/
client.py
6910 lines (5446 loc) · 260 KB
/
client.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 -*-
# pylint: disable=R1705, R0205
# --------------------------------------------------------------------------
# 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.
# --------------------------------------------------------------------------
"""File for performing client related operations on the Commcell.
Clients and Client are 2 classes defined in this file.
Clients: Class for representing all the clients associated with the commcell
Client: Class for a single client of the commcell
Clients
=======
__init__(commcell_object) -- initialize object of Clients class associated with
the commcell
__str__() -- returns all the clients associated with the commcell
__repr__() -- returns the string to represent the instance of the
Clients class
__len__() -- returns the number of clients associated with the
Commcell
__getitem__() -- returns the name of the client at the given index
or the details for the given client name
_get_clients() -- gets all the clients associated with the commcell
_get_office_365_clients() -- get all office365 clients in the commcell
_get_dynamics_365_clients() -- get all the Dynamics 365 clients in the commcell
_get_salesforce_clients() -- get all salesforce clients in the commcell
_get_hidden_clients() -- gets all the hidden clients associated with the
commcell
_get_virtualization_clients() -- gets all the virtualization clients associated with
the commcell
_get_virtualization_access_nodes() -- gets all the virtualization access nodes associated with
the commcell
_get_client_dict() -- returns the client dict for client to be added to
member server
_member_servers() -- returns member clients to be associated with the
Virtual Client
_get_client_from_hostname() -- returns the client name if associated with specified
hostname if exists
_get_hidden_client_from_hostname() -- returns the client name if associated with specified
hostname if exists
_get_client_from_displayname() -- get the client name for given display name
has_client(client_name) -- checks if a client exists with the given name or not
has_hidden_client(client_name) -- checks if a hidden client exists with the given name
_process_add_response() -- to process the add client request using API call
add_vmware_client() -- adds a new VMWare Virtualization Client to the
Commcell
add_kubernetes_client() -- adds a new Kubernetes Virtualization Client to the
Commcell
add_nas_client() -- adds a new NAS Client
add_share_point_client() -- adds a new sharepoint pseudo client to the Commcell
add_onedrive_v2_client() -- adds a new OneDrive for Business client to Commcell
add_exchange_client() -- adds a new Exchange Virtual Client to the Commcell
add_splunk_client() -- adds a new Splunk Client to the Commcell
add_case_client() -- adds a new Case Manger Client to the Commcell
add_salesforce_client() -- adds a new salesforce client
add_azure_client() -- adds a new azure cloud client
add_amazon_client() -- adds a new amazon cloud client
add_google_client() -- adds a new google cloud client
add_alicloud_client() -- adds a new alibaba cloud client
add_nutanix_files_client() -- adds a new nutanix files client
add_onedrive_client() -- adds a new onedrive client
get(client_name) -- returns the Client class object of the input client
name
delete(client_name) -- deletes the client specified by the client name from
the commcell
filter_clients_return_displaynames() -- filter clients based on criteria
refresh() -- refresh the clients associated with the commcell
Clients Attributes
------------------
**all_clients** -- returns the dictionary consisting of all the clients that are
associated with the commcell and their information such as id and hostname
**hidden_clients** -- returns the dictionary consisting of only the hidden clients
that are associated with the commcell and their information such as id and hostname
**virtualization_clients** -- returns the dictionary consisting of only the virtualization
clients that are associated with the commcell and their information such as id and hostname
**virtualization_access_nodes** -- returns the dictionary consisting of only the virtualization
clients that are associated with the commcell and their information such as id and hostname
**office365_clients** -- Returns the dictionary consisting of all the office 365 clients that are
associated with the commcell
**dynamics365_clients** -- Returns the dictionary consisting of all the Dynamics 365 clients
that are associated with the commcell
**salesforce_clients** -- Returns the dictionary consisting of all the salesforce clients that are
associated with the commcell
**file_server_clients** -- Returns the dictionary consisting of all the File Server clients
that are associated with the commcell
Client
======
__init__() -- initialize object of Class with the specified client name
and id, and associated to the commcell
__repr__() -- return the client name and id, the instance is associated with
_get_client_id() -- method to get the client id, if not specified in __init__
_get_client_properties() -- get the properties of this client
_get_instance_of_client() -- get the instance associated with the client
_get_log_directory() -- get the log directory path on the client
_service_operations() -- perform services related operations on a client
START / STOP / RESTART
_make_request() -- makes the upload request to the server
_process_update_request() -- to process the request using API call
update_properties() -- to update the client properties
enable_backup() -- enables the backup for the client
enable_backup_at_time() -- enables the backup for the client at the input time specified
disable_backup() -- disables the backup for the client
enable_restore() -- enables the restore for the client
enable_restore_at_time() -- enables the restore for the client at the input time specified
disable_restore() -- disables the restore for the client
enable_data_aging() -- enables the data aging for the client
enable_data_aging_at_time() -- enables the data aging for the client at input time specified
disable_data_aging() -- disables the data aging for the client
execute_script() -- executes given script on the client
execute_command() -- executes a command on the client
enable_intelli_snap() -- enables intelli snap for the client
disable_intelli_snap() -- disables intelli snap for the client
upload_file() -- uploads the specified file on controller to the client machine
upload_folder() -- uploads the specified folder on controller to client machine
start_service() -- starts the service with the given name on the client
stop_service() -- stops the service with the given name on the client
restart_service() -- restarts the service with the given name on the client
restart_services() -- executes the command on the client to restart the services
push_network_config() -- performs a push network configuration on the client
add_user_association() -- adds the user associations on this client
add_client_owner() -- adds users to owner list of this client
refresh() -- refresh the properties of the client
add_additional_setting() -- adds registry key to the client property
delete_additional_setting() -- deletes registry key from the client property
get_configured_additional_setting() -- To get configured additional settings from the client property
release_license() -- releases a license from a client
retire() -- perform retire operation on the client
reconfigure_client() -- reapplies license to the client
push_servicepack_and_hotfixes() -- triggers installation of service pack and hotfixes
repair_software() -- triggers Repair software on the client machine
get_dag_member_servers() -- Gets the member servers of an Exchange DAG client.
create_pseudo_client() -- Creates a pseudo client
register_decoupled_client() -- registers decoupled client
set_job_start_time() -- sets the job start time at client level
uninstall_software() -- Uninstalls all the packages of the client
get_network_summary() -- Gets the network summary of the client
change_exchange_job_results_directory()
-- Move the Job Results Directory for an
Exchange Online Environment
get_environment_details() -- Gets environment tile details present in dashboard page
get_needs_attention_details() -- Gets needs attention tile details from dashboard page
enable_content_indexing() -- Enables the v1 content indexing on the client
disable_content_indexing() -- Disables the v1 content indexing on the client
check_eligibility_for_migration() -- Checks whether client is Eligible for Migration or not
change_company_for_client() -- Migrates client to specified company
disable_owner_privacy() -- Disables the privacy option for client
enable_owner_privacy() -- Enables the privacy option for client
Client Attributes
-----------------
**available_security_roles** -- returns the security roles available for the selected
client
**properties** -- returns the properties of the client
**display_name** -- returns the display name of the client
**description** -- returns the description of the client
**client_id** -- returns the id of the client
**client_name** -- returns the name of the client
**client_hostname** -- returns the host name of the client
**timezone** -- returns the timezone of the client
**os_info** -- returns string consisting of OS information of the client
**is_data_recovery_enabled** -- boolean specifying whether data recovery is enabled for the
client or not
**is_data_management_enabled** -- boolean specifying whether data management is enabled for
the client or not
**is_ci_enabled** -- boolean specifying whether content indexing is enabled for
the client or not
**is_backup_enabled** -- boolean specifying whether backup activity is enabled for
the client or not
**is_restore_enabled** -- boolean specifying whether restore activity is enabled for
the client or not
**is_data_aging_enabled** -- boolean specifying whether data aging is enabled for the
client or not
**is_intelli_snap_enabled** -- boolean specifying whether intelli snap is enabled for the
client or not
**install_directory** -- returns the path where the client is installed at
**version** -- returns the version of the product installed on the client
**service_pack** -- returns the service pack installed on the client
**job_results_directory** -- returns the path of the job results directory on the client
**instance** -- returns the Instance of the client
**log_directory** -- returns the path of the log directory on the client
**agents** -- returns the instance of the Agents class representing
the list of agents installed on the Client
**schedules** -- returns the instance of the Schedules class representing
the list of schedules configured for the Client
**users** -- returns the instance of the Users class representing the
list of users with access to the Client
**network** -- returns object of the Network class corresponding to the
selected client
**is_ready** -- returns boolean value specifying whether services on the
client are running or not, and whether the CommServ is able to communicate with the client
**set_encryption_prop** -- Set encryption properties on a client
**set_dedup_prop** -- Set DDB properties
**consumed_licenses** -- returns dictionary of all the license details
which is consumed by the client
**cvd_port** -- returns cvd port of the client
**vm_guid** -- returns guid of the vm client
**company_name** -- returns company name for the client
**is_privacy_enabled** -- returns if client privacy is enabled
**latitude** -- Returns the latitude from geo location of the client
**longitude** -- Returns the longitude from geo location of the client
**is_vm** -- Returns True if its a VM client
**hyperv_id_of_vm** -- Returns the Id of hyperV that the given VM is associated with
**associated_client_group** -- Returns the list of clientgroups that the client is associated to
**company_id** -- Returns the company Id of the client
"""
from __future__ import absolute_import
from __future__ import unicode_literals
import os
import re
import time
import copy
from base64 import b64encode
import requests
from .job import Job
from .agent import Agents
from .schedules import Schedules
from .exception import SDKException
from .deployment.install import Install
from .deployment.uninstall import Uninstall
from .network import Network
from .network_throttle import NetworkThrottle
from .security.user import Users
from .name_change import NameChange
from .organization import Organizations
from .constants import AppIDAType
class Clients(object):
"""Class for representing all the clients associated with the commcell."""
def __init__(self, commcell_object):
"""Initialize object of the Clients class.
Args:
commcell_object (object) -- instance of the Commcell class
Returns:
object - instance of the Clients class
"""
self._commcell_object = commcell_object
self._cvpysdk_object = commcell_object._cvpysdk_object
self._services = commcell_object._services
self._update_response_ = commcell_object._update_response_
# TODO: check with API team for additional property to remove multiple API calls
# and use a single API call to get all types of clients, and to be able to distinguish
# them
self._CLIENTS = self._ADD_CLIENT = self._services['GET_ALL_CLIENTS']
self._OFFICE_365_CLIENTS = self._services['GET_OFFICE_365_ENTITIES']
self._DYNAMICS365_CLIENTS = self._services['GET_DYNAMICS_365_CLIENTS']
self._SALESFORCE_CLIENTS = self._services['GET_SALESFORCE_CLIENTS']
self._ALL_CLIENTS = self._services['GET_ALL_CLIENTS_PLUS_HIDDEN']
self._VIRTUALIZATION_CLIENTS = self._services['GET_VIRTUAL_CLIENTS']
self._GET_VIRTUALIZATION_ACCESS_NODES = self._services['GET_VIRTUALIZATION_ACCESS_NODES']
self._FS_CLIENTS = self._services['GET_FILE_SERVER_CLIENTS']
self._ADD_EXCHANGE_CLIENT = self._ADD_SHAREPOINT_CLIENT = self._ADD_SALESFORCE_CLIENT = \
self._services['CREATE_PSEUDO_CLIENT']
self._ADD_SPLUNK_CLIENT = self._services['CREATE_PSEUDO_CLIENT']
self._ADD_NUTANIX_CLIENT = self._services['CREATE_NUTANIX_CLIENT']
self._ADD_NAS_CLIENT = self._services['CREATE_NAS_CLIENT']
self._ADD_ONEDRIVE_CLIENT = self._services['CREATE_PSEUDO_CLIENT']
self._clients = None
self._hidden_clients = None
self._virtualization_clients = None
self._virtualization_access_nodes = None
self._office_365_clients = None
self._dynamics365_clients = None
self._salesforce_clients = None
self._file_server_clients = None
self.refresh()
def __str__(self):
"""Representation string consisting of all clients of the commcell.
Returns:
str - string of all the clients associated with the commcell
"""
representation_string = '{:^5}\t{:^20}\n\n'.format('S. No.', 'Client')
for index, client in enumerate(self.all_clients):
sub_str = '{:^5}\t{:20}\n'.format(index + 1, client)
representation_string += sub_str
return representation_string.strip()
def __repr__(self):
"""Representation string for the instance of the Clients class."""
return "Clients class instance for Commcell: '{0}'".format(
self._commcell_object.commserv_name
)
def __len__(self):
"""Returns the number of the clients associated to the Commcell."""
return len(self.all_clients)
def __getitem__(self, value):
"""Returns the name of the client for the given client ID or
the details of the client for given client Name.
Args:
value (str / int) -- Name or ID of the client
Returns:
str - name of the client, if the client id was given
dict - dict of details of the client, if client name was given
Raises:
IndexError:
no client exists with the given Name / Id
"""
value = str(value).lower()
if value in self.all_clients:
return self.all_clients[value]
else:
try:
return list(filter(lambda x: x[1]['id'] == value, self.all_clients.items()))[0][0]
except IndexError:
raise IndexError('No client exists with the given Name / Id')
def _get_clients(self):
"""Gets all the clients associated with the commcell
Returns:
dict - consists of all clients in the commcell
{
"client1_name": {
"id": client1_id,
"hostname": client1_hostname,
"displayName": client1_displayname
},
"client2_name": {
"id": client2_id,
"hostname": client2_hostname.
"displayName": client2_displayname
}
}
Raises:
SDKException:
if response is empty
if response is not success
"""
attempts = 0
while attempts < 5:
flag, response = self._cvpysdk_object.make_request('GET', self._CLIENTS)
attempts += 1
if flag:
if response.json() and 'clientProperties' in response.json():
clients_dict = {}
for dictionary in response.json()['clientProperties']:
temp_name = dictionary['client']['clientEntity']['clientName'].lower()
temp_id = str(dictionary['client']['clientEntity']['clientId']).lower()
temp_hostname = dictionary['client']['clientEntity']['hostName'].lower()
temp_display_name = dictionary['client']['clientEntity']['displayName'].lower()
clients_dict[temp_name] = {
'id': temp_id,
'hostname': temp_hostname,
'displayName': temp_display_name
}
return clients_dict
else:
return {} # logged in user might not have privileges on any client
else:
if attempts > 4:
raise SDKException('Response', '101', self._update_response_(response.text))
time.sleep(5)
def _get_office_365_clients(self):
"""REST API call to get all office365 clients in the commcell
Returns:
dict - consists of all office 365 clients in the commcell
{
"client1_name": {
"id": client1_id
},
"client2_name": {
"id": client2_id
}
}
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._cvpysdk_object.make_request('GET', self._OFFICE_365_CLIENTS)
if flag:
if response.json() and "o365Client" in response.json():
clients_dict = {}
for dictionary in response.json()['o365Client']:
temp_name = dictionary['clientName'].lower()
temp_id = str(dictionary['clientId']).lower()
clients_dict[temp_name] = {
'id': temp_id
}
return clients_dict
else:
raise SDKException('Response', '102')
else:
raise SDKException('Response', '101', self._update_response_(response.text))
@property
def office_365_clients(self):
"""Returns the dict of all office 365 clients in the commcell"""
if self._office_365_clients is None:
self._office_365_clients = self._get_office_365_clients()
return self._office_365_clients
def _get_dynamics_365_clients(self):
"""
REST API call to get all Dynamics 365 clients in the commcell
Returns:
dict - For the Dynamics 365 clients in the Commcell
Format:
{
"client1_name": {
"id": client1_id
},
"client2_name": {
"id": client2_id
}
}
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._cvpysdk_object.make_request('GET', self._DYNAMICS365_CLIENTS)
if flag:
if response.json() and "o365Client" in response.json():
clients_dict = {}
for dictionary in response.json()['o365Client']:
client_name = dictionary['clientName'].lower()
client_id = str(dictionary['clientId']).lower()
clients_dict[client_name] = {
'id': client_id
}
return clients_dict
else:
raise SDKException('Response', '102')
else:
raise SDKException('Response', '101', self._update_response_(response.text))
@property
def dynamics365_clients(self):
"""Returns the dict of all Dynamics 365 clients in the commcell"""
if self._dynamics365_clients is None:
self._dynamics365_clients = self._get_dynamics_365_clients()
return self._dynamics365_clients
def _get_salesforce_clients(self):
"""
REST API call to get all Salesforce clients in the commcell
Returns:
dict[str, dict]: Containing Salesforce clients and ids in the Commcell like
{
"client1_displayName": {
"id": client1_id,
"clientName": "client1_name"
},
"client2_displayName": {
"id": client2_id,
"clientName": "client2_name"
}
}
"""
flag, response = self._cvpysdk_object.make_request('GET', self._SALESFORCE_CLIENTS)
if flag:
if response.json() and 'orgs' in response.json():
return {
self.all_clients[sf_subclient['clientName'].lower()]['displayName']: {
'id': sf_subclient['clientId'],
'clientName': sf_subclient['clientName']
}
for sf_subclient in map(lambda org: org['sfSubclient'], response.json()['orgs'])
}
return {}
else:
raise SDKException('Response', '101', self._update_response_(response.text))
@property
def salesforce_clients(self):
"""Returns the dict of all salesforce clients in the commcell"""
if self._salesforce_clients is None:
self._salesforce_clients = self._get_salesforce_clients()
return self._salesforce_clients
def _get_hidden_clients(self):
"""Gets all the clients associated with the commcell, including all VM's and hidden clients
Returns:
dict - consists of all clients (including hidden clients) in the commcell
{
"client1_name": {
"id": client1_id,
"hostname": client1_hostname,
"displayName": client1_displayname
},
"client2_name": {
"id": client2_id,
"hostname": client2_hostname,
"displayName": client1_displayname
}
}
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._cvpysdk_object.make_request('GET', self._ALL_CLIENTS)
if flag:
if response.json() and 'clientProperties' in response.json():
all_clients_dict = {}
hidden_clients_dict = {}
for dictionary in response.json()['clientProperties']:
temp_name = dictionary['client']['clientEntity']['clientName'].lower()
temp_id = str(dictionary['client']['clientEntity']['clientId']).lower()
temp_hostname = dictionary['client']['clientEntity']['hostName'].lower()
temp_display_name = dictionary['client']['clientEntity']['displayName'].lower()
all_clients_dict[temp_name] = {
'id': temp_id,
'hostname': temp_hostname,
'displayName': temp_display_name
}
# hidden clients = all clients - true clients
hidden_clients_dict = {
client: all_clients_dict.get(
client, client in all_clients_dict or self.all_clients[client]
)
for client in set(all_clients_dict) - set(self.all_clients)
}
return hidden_clients_dict
else:
return {} # logged in user might not have privileges on any client
else:
raise SDKException('Response', '101', self._update_response_(response.text))
def _get_virtualization_clients(self):
"""REST API call to get all virtualization clients in the commcell
Returns:
dict - consists of all virtualization clients in the commcell
{
"client1_name": {
"id": client1_id,
"hostname": client1_hostname
},
"client2_name": {
"id": client2_id,
"hostname": client2_hostname
}
}
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._cvpysdk_object.make_request('GET', self._VIRTUALIZATION_CLIENTS)
if flag:
if response.json() and 'VSPseudoClientsList' in response.json():
pseudo_clients = response.json()['VSPseudoClientsList']
virtualization_clients = {}
for pseudo_client in pseudo_clients:
virtualization_clients[pseudo_client['client']['displayName'].lower()] = {
'clientId': pseudo_client['client']['clientId'],
'clientName': pseudo_client['client']['clientName'],
'hostName': pseudo_client['client']['hostName']
}
return virtualization_clients
return {}
else:
raise SDKException('Response', '101', self._update_response_(response.text))
def _get_virtualization_access_nodes(self):
"""REST API call to get all virtualization access nodes in the commcell
Returns:
dict - consists of all access nodes in the commcell
{
"display_name1": {
"id": client1_id,
"name": client1_name,
"hostname": client1_hostname
},
"display_name2": {
"id": client2_id,
"name": client2_name,
"hostname": client2_hostname
},
}
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._cvpysdk_object.make_request('GET', self._GET_VIRTUALIZATION_ACCESS_NODES)
virtualization_access_nodes = {}
if flag and response:
if response.json() and 'clients' in response.json():
for virtualization_access_node in response.json()['clients']:
client_id = virtualization_access_node.get('clientId')
client_name = virtualization_access_node.get('clientName').lower()
display_name = virtualization_access_node.get('displayName').lower()
host_name = virtualization_access_node.get('hostName').lower()
if client_name:
virtualization_access_nodes[display_name] = {
'id': client_id,
'name': client_name,
'hostName': host_name
}
return virtualization_access_nodes
else:
raise SDKException('Response', '101', self._update_response_(response.text))
def _get_fileserver_clients(self):
"""REST API call to get all file server clients in the commcell
Returns:
dict - consists of all file server clients in the commcell
{
"client1_name": {
"id": client1_id,
"displayName": client1_displayname
},
"client2_name": {
"id": client2_id,
"displayName": client2_displayname
}
}
Raises:
SDKException:
if response is empty
if response is not success
"""
flag, response = self._cvpysdk_object.make_request('GET', self._FS_CLIENTS)
fs_clients = {}
if flag and response:
if response.json() and 'fileServers' in response.json():
for file_server in response.json()['fileServers']:
fs_clients[file_server['name']] = {
'id': file_server['id'],
'displayName': file_server['displayName']
}
return fs_clients
else:
raise SDKException('Response', '101', self._update_response_(response.text))
@staticmethod
def _get_client_dict(client_object):
"""Returns the client dict for the client object to be appended to member server.
Args:
client_object (object) -- instance of the Client class
Returns:
dict - dictionary for a single client to be associated with the Virtual Client
"""
client_dict = {
"client": {
"clientName": client_object.client_name,
"clientId": int(client_object.client_id),
"_type_": 3
}
}
return client_dict
def _member_servers(self, clients_list):
"""Returns the member clients to be associated with the Virtual Client.
Args:
clients_list (list) -- list of the clients to associated to the virtual client
Returns:
list - list consisting of all member servers to be associated to the Virtual Client
Raises:
SDKException:
if type of clients list argument is not list
"""
if not isinstance(clients_list, list):
raise SDKException('Client', '101')
member_servers = []
for client in clients_list:
if isinstance(client, str):
client = client.strip().lower()
if self.has_client(client):
temp_client = self.get(client)
if temp_client.agents.has_agent('virtual server'):
client_dict = self._get_client_dict(temp_client)
member_servers.append(client_dict)
del temp_client
elif isinstance(client, Client):
if client.agents.has_agent('virtual server'):
client_dict = self._get_client_dict(client)
member_servers.append(client_dict)
return member_servers
def _get_client_from_hostname(self, hostname):
"""Checks if a client is associated with the given hostname.
Args:
hostname (str) -- host name of the client on this commcell
Returns:
str - name of the client associated with this hostname
None - if no client has the same hostname as the given input
"""
# verify there is no client in the Commcell with the same name as the given hostname
# for multi-instance clients
if self.all_clients and hostname not in self.all_clients:
for client in self.all_clients:
if hostname.lower() == self.all_clients[client]['hostname']:
return client
def _get_hidden_client_from_hostname(self, hostname):
"""Checks if hidden client associated given hostname exists and returns the hidden client
name
Args:
hostname (str) -- host name of the client on this commcell
Returns:
str - name of the client associated with this hostname
None - if no client has the same hostname as the given input
"""
# verify there is no client in the Commcell with the same name as the given hostname
# for multi-instance clients
if self.hidden_clients and hostname not in self.hidden_clients:
for hidden_client in self.hidden_clients:
if hostname.lower() == self.hidden_clients[hidden_client]['hostname']:
return hidden_client
def _get_client_from_displayname(self, display_name):
"""get the client name for given display name
Args: