/
clientgroup.py
2028 lines (1581 loc) · 73.1 KB
/
clientgroup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# --------------------------------------------------------------------------
# Copyright Commvault Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# --------------------------------------------------------------------------
"""Main file for performing client group operations.
ClientGroups and ClientGroup are the classes defined in this file.
ClientGroups: Class for representing all the client groups associated with a commcell
ClientGroup: Class for representing a single Client Group of the commcell
ClientGroups:
__init__(commcell_object) -- initialise instance of the ClientGroups associated with
the specified commcell
__str__() -- returns all the client groups associated with the Commcell
__repr__() -- returns the string for the instance of the ClientGroups class
__len__() -- returns the number of client groups associated with the Commcell
__getitem__() -- returns the name of the client group for the given client group
Id or the details for the given client group name
_get_clientgroups() -- gets all the clientgroups associated with the commcell specified
_valid_clients() -- returns the list of all the valid clients,
from the list of clients provided
all_clientgroups() -- returns the dict of all the clientgroups on the commcell
has_clientgroup() -- checks if a client group exists with the given name or not
create_smart_rule() -- Create rules required for smart client group creation
based on input parameters
merge_smart_rules() -- Merge multiple rules into (SCG) rule to create smart client group
_create_scope_dict() -- Creates Scope Dictionary needed for Smart Client group association
add(clientgroup_name) -- adds a new client group to the commcell
get(clientgroup_name) -- returns the instance of the ClientGroup class,
for the the input client group name
delete(clientgroup_name) -- deletes the client group from the commcell
refresh() -- refresh the client groups associated with the commcell
ClientGroup:
__init__(commcell_object,
clientgroup_name,
clientgroup_id=None) -- initialise object of ClientGroup class with the specified
client group name and id
__repr__() -- return the client group name, the instance is associated with
_get_clientgroup_id() -- method to get the clientgroup id, if not specified
_get_clientgroup_properties() -- get the properties of this clientgroup
_initialize_clientgroup_properties() -- initializes the properties of this ClientGroup
_request_json_() -- returns the appropriate JSON to pass for enabling/disabling
an activity
_process_update_request() -- processes the clientgroup update API call
_update() -- updates the client group properties
_add_or_remove_clients() -- adds/removes clients to/from a ClientGroup
enable_backup_at_time() -- enables backup for the client group at the time specified
enable_backup() -- enables the backup flag
disable_backup() -- disables the backup flag
enable_restore_at_time() -- enables restore for the client group at the time specified
enable_restore() -- enables the restore flag
disable_restore() -- disables the restore flag
enable_data_aging_at_time() -- enables data aging for the client group at the time specified
enable_data_aging() -- enables the data aging flag
disable_data_aging() -- disables the data aging flag
add_clients() -- adds the valid clients to client group
remove_clients() -- removes the valid clients from client group
remove_all_clients() -- removes all the associated clients from client group
network() -- returns Network class object
push_network_config() -- performs a push network configuration on client group
refresh() -- refresh the properties of the client group
push_servicepack_and_hotfixes() -- triggers installation of service pack and hotfixes
repair_software() -- triggers Repair software on the client group
update_properties() -- to update the client group properties
add_additional_setting() -- adds registry key to client group property
is_auto_discover_enabled() -- gets the autodiscover option for the Organization
enable_auto_discover() -- enables autodiscover option at client group level
disable_auto_discover() -- disables autodiscover option at client group level
ClientGroup Attributes
-----------------------
Following attributes are available for an instance of the ClientGroup class:
**name** -- returns the name of client group
**clientgroup_id** -- returns the id of client group
**clientgroup_name** -- returns the name of client group
**description** -- returns the description of client group
**associated_clients** -- returns the associated clients of client group
**is_backup_enabled** -- returns the backup activity status of client group
**is_restore_enabled** -- returns the restore activity status of client group
**is_data_aging_enabled** -- returns the data aging activity status of client group
**is_smart_client_group** -- returns true if client group is a smart client group
**is_auto_discover_enabled** -- returns the auto discover status of client group
"""
from __future__ import absolute_import
from __future__ import unicode_literals
import time
import copy
from .exception import SDKException
from .network import Network
from .network_throttle import NetworkThrottle
from .deployment.install import Install
class ClientGroups(object):
"""Class for representing all the clientgroups associated with a Commcell."""
def __init__(self, commcell_object):
"""Initialize object of the ClientGroups class.
Args:
commcell_object (object) -- instance of the Commcell class
Returns:
object - instance of the ClientGroups class
"""
self._commcell_object = commcell_object
self._CLIENTGROUPS = self._commcell_object._services['CLIENTGROUPS']
self._clientgroups = None
self.refresh()
def __str__(self):
"""Representation string consisting of all clientgroups of the Commcell.
Returns:
str - string of all the clientgroups for a commcell
"""
representation_string = "{:^5}\t{:^50}\n\n".format('S. No.', 'ClientGroup')
for index, clientgroup_name in enumerate(self._clientgroups):
sub_str = '{:^5}\t{:50}\n'.format(index + 1, clientgroup_name)
representation_string += sub_str
return representation_string.strip()
def __repr__(self):
"""Representation string for the instance of the ClientGroups class.
Returns:
str - string of all the client groups associated with the commcell
"""
return "ClientGroups class instance for Commcell: '{0}'".format(
self._commcell_object.commserv_name
)
def __len__(self):
"""Returns the number of the client groups associated to the Commcell."""
return len(self.all_clientgroups)
def __getitem__(self, value):
"""Returns the name of the client group for the given client group ID or
the details of the client group for given client group Name.
Args:
value (str / int) -- Name or ID of the client group
Returns:
str - name of the client group, if the client group id was given
dict - dict of details of the client group, if client group name was given
Raises:
IndexError:
no client group exists with the given Name / Id
"""
value = str(value)
if value in self.all_clientgroups:
return self.all_clientgroups[value]
else:
try:
return list(
filter(lambda x: x[1]['id'] == value, self.all_clientgroups.items())
)[0][0]
except IndexError:
raise IndexError('No client group exists with the given Name / Id')
def _get_clientgroups(self):
"""Gets all the clientgroups associated with the commcell
Returns:
dict - consists of all clientgroups of the commcell
{
"clientgroup1_name": clientgroup1_id,
"clientgroup2_name": clientgroup2_id,
}
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._commcell_object._cvpysdk_object.make_request(
'GET', self._CLIENTGROUPS
)
if flag:
if response.json() and 'groups' in response.json():
client_groups = response.json()['groups']
clientgroups_dict = {}
for client_group in client_groups:
temp_name = client_group['name'].lower()
temp_id = str(client_group['Id']).lower()
clientgroups_dict[temp_name] = temp_id
return clientgroups_dict
else:
raise SDKException('Response', '102')
else:
response_string = self._commcell_object._update_response_(response.text)
raise SDKException('Response', '101', response_string)
def _valid_clients(self, clients_list):
"""Returns only the valid clients specified in the input clients list
Args:
clients_list (list) -- list of the clients to add to the client group
Returns:
list - list consisting of the names of all valid clients in the input clients list
Raises:
SDKException:
if type of clients list argument is not list
"""
if not isinstance(clients_list, list):
raise SDKException('ClientGroup', '101')
clients = []
for client in clients_list:
if isinstance(client, str):
client = client.strip().lower()
if self._commcell_object.clients.has_client(client):
clients.append(client)
return clients
@property
def all_clientgroups(self):
"""Returns dict of all the clientgroups associated with this commcell
dict - consists of all clientgroups of the commcell
{
"clientgroup1_name": clientgroup1_id,
"clientgroup2_name": clientgroup2_id,
}
"""
return self._clientgroups
def has_clientgroup(self, clientgroup_name):
"""Checks if a client group exists in the commcell with the input client group name.
Args:
clientgroup_name (str) -- name of the client group
Returns:
bool - boolean output whether the client group exists in the commcell or not
Raises:
SDKException:
if type of the client group name argument is not string
"""
if not isinstance(clientgroup_name, str):
raise SDKException('ClientGroup', '101')
return self._clientgroups and clientgroup_name.lower() in self._clientgroups
def create_smart_rule(self,
filter_rule='OS Type',
filter_condition='equal to',
filter_value='Windows',
value='1'):
"""Create/Prepare rules required for smart client group creation based on input parameters
Args:
filter_rule (str) -- Rule selection to match specific criterion
filter_condition (str) -- Filter value between selections in rule
filter_value(str) -- Value of rule criterion
value(str) -- value required to create rule
Returns:
dict - consists of single rule based on inputs
{
"rule": {
"filterID": 100,
"secValue": 'Windows',
"propID": 8,
"propType": 4,
"value": '1'
}
}
"""
filter_dict = {
'equal to': 100,
'not equal': 101,
'any in selection': 108,
'not in selection': 109,
'is true': 1,
'is false': 2,
'contains': 10,
'starts with': 14,
'ends with': 15,
}
prop_id_dict = {
'Name': 1,
'Client': 2,
'Agents Installed': 3,
'Associated Client Group': 4,
'Timezone': 5,
'Hostname': 6,
'Client Version': 7,
'OS Type': 8,
'Package Installed': 9,
'Client offline (days)': 10,
'User as client owner': 11,
'Local user group as client owner': 12,
'External group as client owner': 13,
'Associated library name': 14,
'OS Version': 15,
'Product Version': 16,
'Client Version Same as CS Version': 17,
'Days since client created': 18,
'Days since last backup': 19,
'SnapBackup clients': 20,
'Clients with attached storages': 21,
'Case manager hold clients': 22,
'MediaAgents for clients in group': 23,
'Client acts as proxy': 24,
'Backup activity enabled': 25,
'Restore activity enabled': 26,
'Client online (days)': 27,
'Inactive AD user as client owner': 28,
'Client excluded from SLA report': 29,
'Client uses storage policy': 30,
'Client is not ready': 31,
'Associated Storage Policy': 32,
'MediaAgent has Lucene Index Roles': 33,
'Client associated with plan': 34,
'Client by Schedule Interval': 35,
'Client needs Updates': 36,
'Subclient Name': 37,
'CommCell Psuedo Client': 38,
'Client Description': 39,
'Clients discovered using VSA Subclient': 40,
'Clients with no Archive Data': 41,
'User Client Provider Associations': 42,
'User Group Client Provider Associations': 43,
'Company Client Provider Associations': 44,
'Clients Meet SLA': 45,
'Index Servers': 46,
'Clients with OnePass enabled': 49,
'Clients by Role': 50,
'Clients by Permission': 51,
'User description contains': 52,
'User Group description contains': 53,
'Content Analyzer Cloud': 54,
'Company Installed Client Associations': 55,
'Client Online in Last 30 Days': 56,
'Clients With Subclients Having Associated Storage Policy': 60,
'Clients With Improperly Deconfigured Subclients': 61,
'Strikes count': 62,
'Clients With Backup Schedule': 63,
'Clients With Long Running Jobs': 64,
'Clients With Synthetic Full Backup N Days': 67,
'MediaAgents for clients in group list': 70,
'Associated Client Group List': 71,
'Timezone List': 72,
'MediaAgent has Lucene Index Role List': 73,
'Associated Storage Policy List': 74,
'Timezone Region List': 75,
'Clients With Encryption': 80,
'Client CIDR Address Range': 81,
'HAC Cluster': 85,
'Client Display Name': 116,
}
ptype_dict = {
'Name': 2,
'Client': 4,
'Agents Installed': 6,
'Associated Client Group': 4,
'Timezone': 4,
'Hostname': 2,
'Client Version': 4,
'OS Type': 4,
'Package Installed': 6,
'Client offline (days)': 3,
'User as client owner': 2,
'Local user group as client owner': 2,
'External group as client owner': 2,
'Associated library name': 2,
'OS Version': 2,
'Product Version': 2,
'Client Version Same as CS Version': 1,
'Days since client created': 3,
'Days since last backup': 3,
'SnapBackup clients': 1,
'Clients with attached storages': 1,
'Case manager hold clients': 1,
'MediaAgents for clients in group': 2,
'Client acts as proxy': 1,
'Backup activity enabled': 1,
'Restore activity enabled': 1,
'Client online (days)': 3,
'Inactive AD user as client owner': 1,
'Client excluded from SLA report': 1,
'Client uses storage policy': 2,
'Client is not ready': 1,
'Associated Storage Policy': 4,
'MediaAgent has Lucene Index Roles': 4,
'Client associated with plan': 2,
'Client by Schedule Interval': 4,
'Client needs Updates': 1,
'Subclient Name': 2,
'CommCell Psuedo Client': 1,
'Client Description': 2,
'Clients discovered using VSA Subclient': 6,
'Clients with no Archive Data': 1,
'User Client Provider Associations': 2,
'User Group Client Provider Associations': 2,
'Company Client Provider Associations': 4,
'Clients Meet SLA': 4,
'Index Servers': 1,
'Clients with OnePass enabled': 1,
'Clients by Role': 4,
'Clients by Permission': 4,
'User description contains': 2,
'User Group description contains': 2,
'Content Analyzer Cloud': 1,
'Company Installed Client Associations': 4,
'Client Online in Last 30 Days': 1,
'Clients With Subclients Having Associated Storage Policy': 1,
'Clients With Improperly Deconfigured Subclients': 1,
'Strikes count': 3,
'Clients With Backup Schedule': 1,
'Clients With Long Running Jobs': 3,
'Clients With Synthetic Full Backup N Days': 3,
'MediaAgents for clients in group list': 7,
'Associated Client Group List': 7,
'Timezone List': 7,
'MediaAgent has Lucene Index Role List': 7,
'Associated Storage Policy List': 7,
'Timezone Region List': 7,
'Clients With Encryption': 1,
'Client CIDR Address Range': 10,
'HAC Cluster': 1,
'Client Display Name': 2,
}
rule_mk = {
"rule": {
"filterID": filter_dict[filter_condition],
"secValue": filter_value,
"propID": prop_id_dict[filter_rule],
"propType": ptype_dict[filter_rule],
"value": value
}
}
return rule_mk
def merge_smart_rules(self, rule_list, op_value='all', scg_op='all'):
"""Merge multiple rules into (SCG) rule to create smart client group.
Args:
rule_list (list) -- List of smart rules to be added in rule group
op_value (str)-- condition to apply between smart rules
ex: all, any,not any
scg_op (str)-- condition to apply between smart rule groups (@group level)
Returns:
scg_rule (dict) - Rule group to create smart client group
"""
op_dict = {
'all': 0,
'any': 1,
'not any': 2
}
scg_rule = {
"op": op_dict[scg_op],
"rules": [
]
}
rules_dict = {
"rule": {
"op": op_dict[op_value],
"rules": [
]
}
}
for each_rule in rule_list:
rules_dict["rule"]["rules"].append(each_rule)
scg_rule["rules"].append(rules_dict)
return scg_rule
def _create_scope_dict(self, client_scope, value=None):
"""Creates required dictionary for given client scope
Args:
value (string) -- Value to be selected for the client scope dropdown
client_scope (string) -- Value of the client scope
Accepted Values (client_scope) --
Clients in this Commcell
Clients of Companies
Clients of User
Clients of User Groups
Returns:
dictionary - Client Scope data required for the smart client group
NOTE : Value is not required for client scope = "Clients in this Commcell"
For this, value is automatically set to the Commserve Name
"""
scgscope = {
"entity": {}
}
if client_scope.lower() == 'clients in this commcell':
scgscope["entity"] = {
"commCellName": self._commcell_object.commserv_name,
"_type_": 1
}
elif client_scope.lower() == 'clients of companies' and value is not None:
scgscope["entity"] = {
"providerDomainName": value,
"_type_": 61
}
elif client_scope.lower() == 'clients of user' and value is not None:
scgscope["entity"] = {
"userName": value,
"_type_": 13
}
elif client_scope.lower() == 'clients of user group' and value is not None:
scgscope["entity"] = {
"userGroupName": value,
"_type_": 15
}
return scgscope
def add(self, clientgroup_name, clients=[], **kwargs):
"""Adds a new Client Group to the Commcell.
Args:
clientgroup_name (str) -- name of the new client group to add
clients (str/list) -- ',' separated string of client names,
or a list of clients,
to be added under client group
default: []
** kwargs (dict) -- Key value pairs for supported arguments
Supported:
clientgroup_description (str) -- description of the client group
default: ""
enable_backup (bool) -- enable or disable backup
default: True
enable_restore (bool) -- enable or disable restore
default: True
enable_data_aging (bool) -- enable or disable data aging
default: True
scg_rule (dict) -- scg_rule required to create smart
client group
client_scope (str) -- Client scope for the Smart Client Group
client_scope_value (str) -- Client scope value for a particular scope
Returns:
object - instance of the ClientGroup class created by this method
Raises:
SDKException:
if type of client group name and description is not of type string
if clients argument is not of type list / string
if response is empty
if response is not success
if client group already exists with the given name
"""
if not (isinstance(clientgroup_name, str) and
isinstance(kwargs.get('clientgroup_description', ''), str)):
raise SDKException('ClientGroup', '101')
if not self.has_clientgroup(clientgroup_name):
if isinstance(clients, list):
clients = self._valid_clients(clients)
elif isinstance(clients, str):
clients = self._valid_clients(clients.split(','))
else:
raise SDKException('ClientGroup', '101')
clients_list = []
for client in clients:
clients_list.append({'clientName': client})
smart_client_group = bool(kwargs.get('scg_rule'))
if kwargs.get('scg_rule') is None:
kwargs['scg_rule'] = {}
request_json = {
"clientGroupOperationType": 1,
"clientGroupDetail": {
"description": kwargs.get('clientgroup_description', ''),
"isSmartClientGroup": smart_client_group,
"scgRule": kwargs.get('scg_rule'),
"clientGroup": {
"clientGroupName": clientgroup_name
},
"associatedClients": clients_list
}
}
scg_scope = None
if kwargs.get("client_scope") is not None:
# Check if value is there or not
if kwargs.get("client_scope").lower() == "clients in this commcell":
scg_scope = [self._create_scope_dict(kwargs.get("client_scope"))]
else:
if kwargs.get("client_scope_value") is not None:
scg_scope = [self._create_scope_dict(kwargs.get("client_scope"), kwargs.get("client_scope_value"))]
else:
raise SDKException('ClientGroup', '102',
"Client Scope {0} requires a value".format(kwargs.get("client_scope")))
if scg_scope is not None:
request_json["clientGroupDetail"]["scgScope"] = scg_scope
if kwargs.get("enable_backup") or kwargs.get("enable_data_aging") or kwargs.get("enable_restore"):
client_group_activity_control = {
"activityControlOptions": [
{
"activityType": 1,
"enableAfterADelay": False,
"enableActivityType": kwargs.get('enable_backup', True)
}, {
"activityType": 16,
"enableAfterADelay": False,
"enableActivityType": kwargs.get('enable_data_aging', True)
}, {
"activityType": 2,
"enableAfterADelay": False,
"enableActivityType": kwargs.get('enable_restore', True)
}
]
}
request_json["clientGroupDetail"]["clientGroupActivityControl"] = client_group_activity_control
flag, response = self._commcell_object._cvpysdk_object.make_request(
'POST', self._CLIENTGROUPS, request_json
)
if flag:
if response.json():
error_message = None
if 'errorMessage' in response.json():
error_message = response.json()['errorMessage']
o_str = 'Failed to create new ClientGroup\nError:"{0}"'.format(
error_message
)
raise SDKException('ClientGroup', '102', o_str)
elif 'clientGroupDetail' in response.json():
self.refresh()
clientgroup_id = response.json()['clientGroupDetail'][
'clientGroup']['clientGroupId']
return ClientGroup(
self._commcell_object, clientgroup_name, clientgroup_id
)
else:
o_str = 'Failed to create new ClientGroup'
raise SDKException('ClientGroup', '102', o_str)
else:
raise SDKException('Response', '102')
else:
response_string = self._commcell_object._update_response_(response.text)
raise SDKException('Response', '101', response_string)
else:
raise SDKException(
'ClientGroup', '102', 'Client Group "{0}" already exists.'.format(clientgroup_name)
)
def get(self, clientgroup_name):
"""Returns a client group object of the specified client group name.
Args:
clientgroup_name (str) -- name of the client group
Returns:
object - instance of the ClientGroup class for the given clientgroup name
Raises:
SDKException:
if type of the client group name argument is not string
if no client group exists with the given name
"""
if not isinstance(clientgroup_name, str):
raise SDKException('ClientGroup', '101')
else:
clientgroup_name = clientgroup_name.lower()
if self.has_clientgroup(clientgroup_name):
return ClientGroup(
self._commcell_object, clientgroup_name, self._clientgroups[clientgroup_name]
)
raise SDKException(
'ClientGroup',
'102',
'No ClientGroup exists with name: {0}'.format(clientgroup_name)
)
def delete(self, clientgroup_name):
"""Deletes the clientgroup from the commcell.
Args:
clientgroup_name (str) -- name of the clientgroup
Raises:
SDKException:
if type of the clientgroup name argument is not string
if response is empty
if failed to delete the client group
if no clientgroup exists with the given name
"""
if not isinstance(clientgroup_name, str):
raise SDKException('ClientGroup', '101')
else:
clientgroup_name = clientgroup_name.lower()
if self.has_clientgroup(clientgroup_name):
clientgroup_id = self._clientgroups[clientgroup_name]
delete_clientgroup_service = self._commcell_object._services['CLIENTGROUP']
flag, response = self._commcell_object._cvpysdk_object.make_request(
'DELETE', delete_clientgroup_service % clientgroup_id
)
if flag:
if response.json():
if 'errorCode' in response.json():
error_code = str(response.json()['errorCode'])
error_message = response.json()['errorMessage']
if error_code == '0':
# initialize the clientgroups again
# so the clientgroups object has all the client groups
self.refresh()
else:
o_str = 'Failed to delete ClientGroup\nError: "{0}"'.format(
error_message
)
raise SDKException('ClientGroup', '102', o_str)
else:
raise SDKException('Response', '102')
else:
raise SDKException('Response', '102')
else:
response_string = self._commcell_object._update_response_(response.text)
raise SDKException('Response', '101', response_string)
else:
raise SDKException(
'ClientGroup',
'102',
'No ClientGroup exists with name: "{0}"'.format(clientgroup_name)
)
def refresh(self):
"""Refresh the client groups associated with the Commcell."""
self._clientgroups = self._get_clientgroups()
class ClientGroup(object):
"""Class for performing operations for a specific ClientGroup."""
def __init__(self, commcell_object, clientgroup_name, clientgroup_id=None):
"""Initialise the ClientGroup class instance.
Args:
commcell_object (object) -- instance of the Commcell class
clientgroup_name (str) -- name of the clientgroup
clientgroup_id (str) -- id of the clientgroup
default: None
Returns:
object - instance of the ClientGroup class
"""
self._commcell_object = commcell_object
self._clientgroup_name = clientgroup_name.lower()
if clientgroup_id:
# Use the client group id provided in the arguments
self._clientgroup_id = str(clientgroup_id)
else:
# Get the id associated with this client group
self._clientgroup_id = self._get_clientgroup_id()
self._CLIENTGROUP = self._commcell_object._services['CLIENTGROUP'] % (self.clientgroup_id)
self._cvpysdk_object = commcell_object._cvpysdk_object
self._services = commcell_object._services
self._update_response_ = commcell_object._update_response_
self._properties = None
self._description = None
self._is_backup_enabled = None
self._is_restore_enabled = None
self._is_data_aging_enabled = None
self._is_smart_client_group = None
self._company_name = None
self.refresh()
def __repr__(self):
"""String representation of the instance of this class.
Returns:
str - string containing the details of this ClientGroup
"""
representation_string = 'ClientGroup class instance for ClientGroup: "{0}"'
return representation_string.format(self.clientgroup_name)
def _get_clientgroup_id(self):
"""Gets the clientgroup id associated with this clientgroup.
Returns:
str - id associated with this clientgroup
"""
clientgroups = ClientGroups(self._commcell_object)
return clientgroups.get(self.clientgroup_name).clientgroup_id
def _get_clientgroup_properties(self):
"""Gets the clientgroup properties of this clientgroup.
Returns:
dict - dictionary consisting of the properties of this clientgroup
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._commcell_object._cvpysdk_object.make_request(
'GET', self._CLIENTGROUP
)
if flag:
if response.json() and 'clientGroupDetail' in response.json():
return response.json()['clientGroupDetail']
else:
raise SDKException('Response', '102')
else:
response_string = self._commcell_object._update_response_(response.text)
raise SDKException('Response', '101', response_string)
def _initialize_clientgroup_properties(self):
"""Initializes the common properties for the clientgroup."""
clientgroup_props = self._get_clientgroup_properties()
self._properties = clientgroup_props
if 'clientGroupName' in clientgroup_props['clientGroup']:
self._clientgroup_name = clientgroup_props['clientGroup']['clientGroupName'].lower()
else:
raise SDKException(
'ClientGroup', '102', 'Client Group name is not specified in the response'
)
self._description = None
if 'description' in clientgroup_props:
self._description = clientgroup_props['description']
self._associated_clients = []
if 'associatedClients' in clientgroup_props:
for client in clientgroup_props['associatedClients']:
self._associated_clients.append(client['clientName'])
self._is_smart_client_group = self._properties['isSmartClientGroup']
self._is_backup_enabled = False
self._is_restore_enabled = False
self._is_data_aging_enabled = False
if 'clientGroupActivityControl' in clientgroup_props:
cg_activity_control = clientgroup_props['clientGroupActivityControl']
if 'activityControlOptions' in cg_activity_control:
for control_options in cg_activity_control['activityControlOptions']:
if control_options['activityType'] == 1:
self._is_backup_enabled = control_options['enableActivityType']
elif control_options['activityType'] == 2:
self._is_restore_enabled = control_options['enableActivityType']
elif control_options['activityType'] == 16:
self._is_data_aging_enabled = control_options['enableActivityType']
self._company_name = clientgroup_props.get('securityAssociations', {}).get('tagWithCompany', {}).get('providerDomainName')
def _request_json_(self, option, enable=True, enable_time=None, **kwargs):