-
Notifications
You must be signed in to change notification settings - Fork 31
/
storagegroup.py
1926 lines (1790 loc) · 79.5 KB
/
storagegroup.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
#!/usr/bin/python
# Copyright: (c) 2019, Dell Technologies
# Apache License version 2.0 (see MODULE-LICENSE or http://www.apache.org/licenses/LICENSE-2.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = r'''
---
module: storagegroup
version_added: '1.0.0'
short_description: Manage storage groups on PowerMax or VMAX Storage System
description:
- Managing storage groups on a PowerMax storage system includes the following.
- Listing the volumes of a storage group.
- Creating a new storage group.
- Deleting an existing storage group.
- Adding existing volumes to an existing storage group.
- Removing existing volumes from an existing storage group.
- Creating new volumes in an existing storage group.
- Modifying existing storage group attributes.
- Adding child storage groups inside an existing storage group (parent).
- Moving volumes between storage groups.
- Removing a child storage group from an existing parent storage group.
extends_documentation_fragment:
- dellemc.powermax.powermax
- dellemc.powermax.powermax.powermax_serial_no
author:
- Vasudevu Lakhinana (@unknown) <ansible.team@dell.com>
- Prashant Rakheja (@prashant-dell) <ansible.team@dell.com>
- Ambuj Dubey (@AmbujDube) <ansible.team@dell.com>
- Pavan Mudunuri (@Pavan-Mudunuri) <ansible.team@dell.com>
- Trisha Datta (@Trisha-Datta) <ansible.team@dell.com>
options:
sg_name:
description:
- The name of the storage group.
required: true
type: str
service_level:
description:
- The name of SLO.
type: str
srp:
description:
- The name of the storage resource pool.
- This parameter is ignored if service_level is not specified.
- Default is to use whichever is the default SRP on the array.
type: str
compression:
description:
- Compression on storage group.
- Compression parameter is ignored if service_level is not specified.
- Default is true.
type: bool
volumes:
description:
- This is a list of volumes.
- Each volume has four attributes; vol_name, size, cap_unit, vol_id.
- Volume ID must be provided for existing volumes.
- The size must be provided to add new volumes to SG.
- The cap_unit is optional.
- Default value of cap_unit is GB, choices are MB, GB, TB.
type: list
elements: dict
vol_state:
description:
- Describes the state of volumes inside the SG.
choices: [present-in-group, absent-in-group]
type: str
child_storage_groups:
description:
- This is a list of child storage groups.
type: list
elements: str
child_sg_state:
description:
- Describes the state of CSG inside parent SG.
choices: [present-in-group, absent-in-group]
type: str
new_sg_name:
description:
- The new name of the storage group.
type: str
target_sg_name:
description:
- The destination SG name to move the volumes to.
type: str
force:
description:
- This flag is to be set to True while moving volumes to target
SG if volume is in a masking view.
type: bool
snapshot_policies:
description:
- List of snapshot policies.
type: list
elements: str
snapshot_policy_state:
description:
- Describes the state of snapshot policy for an SG.
type: str
choices: [present-in-group, absent-in-group]
host_io_limit:
description:
- Host I/O limit of the storage group.
type: dict
suboptions:
host_io_limit_iops:
description:
- The I/Os per second host I/O limit for the storage group.
type: int
dynamic_distribution:
description:
- The dynamic distribution of host I/O limit for the storage group.
type: str
default: Never
choices: [Always, Never, OnFailure]
host_io_limit_mbps:
description:
- The MBs per second host I/O limit for the storage group.
type: int
state:
description:
- Define whether the storage group should exist or not.
choices: [absent, present]
type: str
required: true
notes:
- To set host_io_limit_mbps to NOLIMIT, value can be provided as 0.
- Idempotency is not supported when creating a new volume in the storage group
without providing volume name.
- The check_mode is not supported.
'''
EXAMPLES = r'''
- name: Get storage group details including volumes
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "ansible_sg"
state: "present"
- name: Create empty storage group
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "foo"
service_level: "Diamond"
srp: "SRP_1"
compression: True
state: "present"
- name: Delete the storage group
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "foo"
state: "absent"
- name: Adding existing volumes to existing SG
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "foo"
state: "present"
volumes:
- vol_id: "00028"
- vol_id: "00018"
- vol_id: "00025"
vol_state: "present-in-group"
- name: Create new volumes for existing SG
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "foo"
state: "present"
volumes:
- vol_name: "foo"
size: 1
cap_unit: "GB"
- vol_name: "bar"
size: 1
cap_unit: "GB"
vol_state: "present-in-group"
- name: Remove volumes from existing SG
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "foo"
state: "present"
volumes:
- vol_id: "00028"
- vol_id: "00018"
- vol_name: "ansible-vol"
vol_state: "absent-in-group"
- name: Move volumes to target SG
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "foo"
target_sg_name: "foo_sg"
force: True
state: "present"
volumes:
- vol_id: "00028"
- vol_id: "00018"
- vol_name: "ansible-vol"
vol_state: "absent-in-group"
- name: Adding child SG to parent SG
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "parent_sg"
state: "present"
child_storage_groups:
- "pie"
- "bar"
child_sg_state: "present-in-group"
- name: Removing child SG from parent SG
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "parent_sg"
state: "present"
child_storage_groups:
- "pie"
- "bar"
child_sg_state: "absent-in-group"
- name: Rename storage group
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "ansible_sg"
new_sg_name: "ansible_sg_renamed"
state: "present"
- name: Create a storage group with snapshot policies
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "ansible_test_sg"
service_level: "Diamond"
srp: "SRP_1"
compression: True
snapshot_policies:
- "10min_policy"
- "30min_policy"
snapshot_policy_state: "present-in-group"
state: "present"
- name: Add snapshot policy to a storage group
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "ansible_test_sg"
snapshot_policies:
- "15min_policy"
snapshot_policy_state: "present-in-group"
state: "present"
- name: Remove snapshot policy from a storage group
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "ansible_test_sg"
snapshot_policies:
- "15min_policy"
snapshot_policy_state: "absent-in-group"
state: "present"
- name: Set host I/O limits on an existing storage group
dellemc.powermax.storagegroup:
unispherehost: "{{unispherehost}}"
universion: "{{universion}}"
verifycert: "{{verifycert}}"
user: "{{user}}"
password: "{{password}}"
serial_no: "{{serial_no}}"
sg_name: "Test"
host_io_limit:
dynamic_distribution: "Always"
host_io_limit_iops: 100
host_io_limit_mbps: 100
state: "present"
'''
RETURN = r'''
changed:
description: Whether or not the resource has changed.
returned: always
type: bool
sample: "false"
add_child_sg:
description: Sets to True when a child SG is added.
returned: When value exists.
type: bool
sample: "true"
add_new_vols_to_sg:
description: Sets to True when new volumes are added to the SG.
returned: When value exists.
type: bool
sample: "true"
add_vols_to_sg:
description: Sets to True when existing volumes are added to the SG.
returned: When value exists.
type: bool
sample: "false"
added_vols_details:
description: Volume IDs of the volumes added.
returned: When value exists.
type: list
sample: ["0081A"]
create_sg:
description: Sets to True when a new SG is created.
returned: When value exists.
type: bool
sample: "true"
delete_sg:
description: Sets to True when an SG is deleted.
returned: When value exists.
type: bool
sample: "true"
modify_sg:
description: Sets to True when an SG is modified.
returned: When value exists.
type: bool
sample: "true"
remove_child_sg:
description: Sets to True when a child SG is removed.
returned: When value exists.
type: bool
sample: "true"
remove_vols_from_sg:
description: Sets to True when volumes are removed.
returned: When value exists.
type: bool
sample: "true"
removed_vols_details:
description: Volume IDs of the volumes removed.
returned: When value exists.
type: list
sample: ["0081A"]
rename_sg:
description: Sets to True when an SG is renamed.
returned: When value exists.
type: bool
sample: "true"
add_snapshot_policy_to_sg:
description: Sets to True when snapshot policy is added to SG.
returned: When value exists.
type: bool
sample: "true"
remove_snapshot_policy_to_sg:
description: Sets to false when snapshot policy is removed from SG.
returned: When value exists.
type: bool
sample: "true"
storage_group_details:
description: Details of the storage group.
returned: When a storage group exists.
type: complex
contains:
base_slo_name:
description: Base Service Level Objective (SLO) of a storage
group.
type: str
cap_gb:
description: Storage group capacity in GB.
type: int
compression:
description: Compression flag.
type: bool
device_emulation:
description: Device emulation type.
type: str
num_of_child_sgs:
description: Number of child storage groups.
type: int
num_of_masking_views:
description: Number of masking views associated with the storage
group.
type: int
num_of_parent_sgs:
description: Number of parent storage groups.
type: int
num_of_snapshots:
description: Number of snapshots for the storage group.
type: int
num_of_vols:
description: Number of volumes in the storage group.
type: int
service_level:
description: Type of service level.
type: str
slo:
description: Service Level Objective type.
type: str
slo_compliance:
description: Type of SLO compliance.
type: str
srp:
description: Storage Resource Pool.
type: str
storageGroupId:
description: ID for the storage group.
type: str
type:
description: Type of storage group.
type: str
unprotected:
description: Flag for storage group protection.
type: bool
vp_saved_percent:
description: Percentage saved for virtual pools.
type: int
hostIOLimit:
description: Host I/O limit of the storage group.
type: complex
contains:
iops:
description: The I/Os per second host I/O limit for the storage group.
type: int
dynamic_distribution:
description: The dynamic distribution of host I/O limit for the storage group.
type: str
mbps:
description: The MBs per second host I/O limit for the storage group.
type: int
sample: {
"cap_gb": 6.01,
"compression": false,
"compression_ratio_to_one": 0.0,
"device_emulation": "FBA",
"num_of_child_sgs": 0,
"num_of_masking_views": 0,
"num_of_parent_sgs": 0,
"num_of_snapshots": 0,
"num_of_vols": 6,
"slo": "NONE",
"slo_compliance": "NONE",
"srp": "SRP_1",
"storageGroupId": "sample_sg_name",
"type": "Standalone",
"unprotected": true,
"unreducible_data_gb": 0.0,
"vp_saved_percent": 100.0
}
storage_group_volumes:
description: Volume IDs of storage group volumes.
returned: When value exists.
type: list
sample: ["00773","0081A"]
storage_group_volumes_details:
description: Details of the storage group volumes.
returned: When storage group volumes exist.
type: complex
contains:
effective_wwn:
description: Effective WWN of the volume.
type: str
type:
description: Type of the volume.
type: str
volumeId:
description: Unique ID of the volume.
type: str
volume_identifier:
description: Name associated with the volume.
type: str
wwn:
description: WWN of the volume.
type: str
sample: [
{
"effective_wwn": "60000970000197902573533030373733",
"type": "TDEV",
"volumeId": "00773",
"volume_identifier": "sample_sg_name",
"wwn": "60000970000197902573533030373733"
}]
snapshot_policy_compliance_details:
description: The compliance status of this storage group.
returned: When a snapshot policy is associated.
type: complex
contains:
compliance:
description: Compliance status.
type: str
sl_compliance:
description: Compliance details.
type: complex
contains:
sl_name:
description: Name of the snapshot policy.
type: str
compliance:
description: Compliance status.
type: str
sl_count:
description: Number of snapshot policies associated with storage group.
type: int
storage_group_name:
description: Name of the storage group.
type: str
sample: {
"compliance": "NONE",
"sl_compliance": [
{
"calculation_time": "2022-10-25T12:05",
"compliance": "NONE",
"sl_name": "ansible_SP4"
}
],
"sl_count": 1,
"storage_group_name": "sample_sg_name"
}
'''
import logging
from ansible_collections.dellemc.powermax.plugins.module_utils.storage.dell \
import utils
from ansible.module_utils.basic import AnsibleModule
LOG = utils.get_logger('storagegroup')
HAS_PYU4V = utils.has_pyu4v_sdk()
PYU4V_VERSION_CHECK = utils.pyu4v_version_check()
# Application Type
APPLICATION_TYPE = 'ansible_v2.1.1'
class StorageGroup(object):
"""Class with Storage Group operations"""
protected_sg_msg = "Modifying volume or child storagegroup" \
" for an SRDF protected storage group will " \
"render it unprotected and unmanageable." \
" Hence this operation is not allowed through" \
" Ansible Module."
u4v_conn = None
def __init__(self):
"""Define all the parameters required by this module"""
self.module_params = utils.get_powermax_management_host_parameters()
self.module_params.update(get_storage_group_parameters())
# initialize the Ansible module
required_together = [['snapshot_policies', 'snapshot_policy_state'],
['volumes', 'vol_state']]
self.module = AnsibleModule(
argument_spec=self.module_params,
supports_check_mode=True,
required_together=required_together
)
if HAS_PYU4V is False:
self.show_error_exit(msg="Ansible modules for PowerMax require "
"the PyU4V python library to be "
"installed. Install the library "
"before using these modules.")
if PYU4V_VERSION_CHECK is not None:
self.show_error_exit(msg=PYU4V_VERSION_CHECK)
if self.module.params['universion'] is not None:
universion_details = utils.universion_check(
self.module.params['universion'])
LOG.info("universion_details: %s", universion_details)
if not universion_details['is_valid_universion']:
self.show_error_exit(msg=universion_details['user_message'])
try:
self.u4v_conn = utils.get_U4V_connection(
self.module.params, application_type=APPLICATION_TYPE)
except Exception as e:
self.show_error_exit(msg=str(e))
self.provisioning = self.u4v_conn.provisioning
self.replication = self.u4v_conn.replication
self.common = self.u4v_conn.common
self.foxtail_version = '5978.444.444'
curr_version = utils.PyU4V.__version__
supp_version = "9.2.1.3"
is_supported_version = utils.pkg_resources.parse_version(
curr_version) >= utils.pkg_resources.parse_version(supp_version)
if is_supported_version:
self.snapshot_policy = self.u4v_conn.snapshot_policy
LOG.info('Check Mode flag is %s', self.module.check_mode)
LOG.info('Got PyU4V instance for provisioning on PowerMax ')
def get_volume(self):
"""Get volume details"""
vol_id = self.module.params['vol_id']
if vol_id is None:
vol_id = self.provisioning.find_volume_device_id(
self.module.params['vol_name'])
try:
LOG.info('Getting volume %s details', vol_id)
return self.provisioning.get_volume(vol_id)
except Exception as e:
errorMsg = ("Getting details of volume %s failed with error "
"%s" % (vol_id, str(e)))
LOG.error(errorMsg)
return None
def get_volumes_storagegroup(self, sg_name):
"""Get the list of volumes from a storage group"""
if not sg_name:
errmsg = 'StorageGroup name is required to get the ' \
'candidate volumes'
LOG.error(errmsg)
self.show_error_exit(msg=errmsg)
try:
LOG.info('Getting the list of volumes '
'from storage group %s', sg_name)
sg_vol_list = self.provisioning \
.get_volumes_from_storage_group(sg_name)
LOG.info('%d volumes present in storage group '
'%s', len(sg_vol_list), sg_name)
return sg_vol_list
except Exception as e:
errmsg = ("Getting list of volumes for storage group "
"%s failed with error %s" % (sg_name, str(e)))
LOG.error(errmsg)
self.show_error_exit(msg=errmsg)
return None
def get_volumes_details_storagegroup(self, sg_name):
"""Get volumes details of a storage group"""
if not sg_name:
errmsg = 'StorageGroup name is required to get the candidate ' \
'volumes details'
self.show_error_exit(msg=errmsg)
try:
LOG.info('Getting volumes details of storage group %s', sg_name)
sg_vol_list = self.provisioning.\
get_volumes_from_storage_group(sg_name)
LOG.info('%s volumes present in storage group %s',
len(sg_vol_list), sg_name)
sg_vol_details = []
for vol in sg_vol_list:
vol_details = self.provisioning.get_volume(device_id=vol)
details = dict(
type='',
volumeId=vol,
volume_identifier='',
wwn='',
effective_wwn='',
)
if 'volume_identifier' in vol_details:
details['volume_identifier'] = \
vol_details['volume_identifier']
details['wwn'] = vol_details['wwn']
details['effective_wwn'] = vol_details['effective_wwn']
details['type'] = vol_details['type']
sg_vol_details.append(details)
return sg_vol_details
except Exception as e:
errmsg = ("Getting volume details of storage group "
"%s failed with error %s" % (sg_name, str(e)))
self.show_error_exit(msg=errmsg)
return None
def get_storage_group(self, sg_name):
"""Get storage group details"""
try:
LOG.info('Getting details of storage group %s', sg_name)
return self.provisioning.get_storage_group(sg_name)
except Exception as e:
errorMsg = ("Getting details of storage group %s failed with error "
"%s" % (sg_name, str(e)))
LOG.error(errorMsg)
return None
def if_srdf_protected(self, sg_details):
"""Check if this storage group is protected with SRDF"""
try:
if not sg_details['unprotected']:
srdf_sgs = self.replication.get_replication_enabled_storage_groups(has_srdf=True)
if sg_details['storageGroupId'] in srdf_sgs:
return True
return False
except Exception as e:
errorMsg = ("Determining SRDF protection for storage group %s "
"failed with error %s" % (sg_details['storageGroupId'], str(e)))
LOG.error(errorMsg)
self.show_error_exit(msg=errorMsg)
def create_storage_group(self, sg_name):
"""Create a storage group"""
slo = self.module.params['service_level']
srp = self.module.params['srp']
compression = self.module.params['compression']
if compression is None:
compression = True
if slo and srp is None:
srp = 'SRP_1'
disable_compression = not compression
resp = {}
try:
if self.module.params['snapshot_policies'] \
and self.module.params['snapshot_policy_state'] \
== 'present-in-group':
self.pre_check_for_PyU4V_version()
snapshot_policies = self.module.params['snapshot_policies']
LOG.info('Creating storage group %s and associating snapshot '
'policies to it %s', sg_name, snapshot_policies)
if not self.module.check_mode:
resp = self.provisioning.create_storage_group(
srp_id=srp, sg_id=sg_name, slo=slo, workload=None,
do_disable_compression=disable_compression,
snapshot_policy_ids=snapshot_policies)
return True, resp
LOG.info('Creating empty storage group %s ', sg_name)
if not self.module.check_mode:
resp = self.provisioning.create_empty_storage_group(
srp_id=srp, storage_group_id=sg_name, service_level=slo,
workload=None, disable_compression=disable_compression)
return True, resp
except Exception as e:
errorMsg = ("Create storage group %s failed with error %s"
% (sg_name, str(e)))
self.show_error_exit(msg=errorMsg)
def get_volumes_to_move(self, sg_name, existing_volumes, volumes):
"""
Get list of volume Id's
:param sg_name: Source storagegroup name
:param existing_volumes: List of existing volumes
:param volumes: List of volumes to move
:return: List of volume IDs
"""
try:
vol_ids = []
for vol in volumes:
if (self.validate_volume(vol)) and ('vol_id' in vol) \
and vol['vol_id'].upper() in existing_volumes:
vol_ids.append(vol['vol_id'])
elif 'vol_name' in vol:
params = {"storageGroupId": sg_name,
"volume_identifier": vol['vol_name']}
volume_list = self.provisioning.get_volume_list(params)
if volume_list:
if len(volume_list) > 1:
err_msg = ("Duplicate volumes found: "
"There are %s volumes with "
"the same name %s in "
"the storage group %s"
% (len(volume_list), vol['vol_name'], sg_name))
self.show_error_exit(msg=err_msg)
elif volume_list[0] in existing_volumes:
vol_ids.append(volume_list[0])
return vol_ids
except Exception as e:
error_msg = ("Retrieving volume details while performing move operation "
"failed with error %s" % str(e))
self.show_error_exit(msg=error_msg)
def move_volume_between_storage_groups(self, sg_name, target_sg_name, force):
"""
Move volumes between storage groups
:param sg_name: Source storagegroup name
:param target_sg_name: Targeted storagegroup name
:param force: Force flag
:return: boolean
"""
volumes = self.module.params['volumes']
vol_state = self.module.params['vol_state']
if vol_state != 'absent-in-group':
self.show_error_exit(msg="Specify vol_state as 'absent-in-group' to move volumes")
if not force and (self.if_srdf_protected(self.get_storage_group(sg_name)) or
self.if_srdf_protected(self.get_storage_group(target_sg_name))):
error_msg = ("Specify a force flag to move volumes to or from SRDF protected storage group")
self.show_error_exit(msg=error_msg)
try:
LOG.info('Move volumes to target SG %s', target_sg_name)
vol_ids = []
existing_volumes = self.get_volumes_storagegroup(sg_name)
vol_ids = self.get_volumes_to_move(sg_name, existing_volumes, volumes)
if vol_ids:
vol_ids = list(set(vol_ids))
if not self.module.check_mode:
self.provisioning.move_volumes_between_storage_groups(
device_ids=vol_ids,
source_storagegroup_name=sg_name,
target_storagegroup_name=target_sg_name,
force=force)
return True
except Exception as e:
error_msg = ("Move volumes to target storage group %s failed with error %s"
% (target_sg_name, str(e)))
self.show_error_exit(msg=error_msg)
def add_volume_storage_group(self, sg_name):
"""Add new volumes to existing storage group"""
volumes = self.module.params['volumes']
LOG.info('Creating new volumes for SG %s', sg_name)
changed = False
storage_group = self.provisioning.get_storage_group(sg_name)
for vol in volumes:
LOG.info('Processing vol %s', vol)
if (self.validate_volume(vol)) and (('cap_unit' in vol) or
('vol_name' in vol) or
('size' in vol)):
if 'cap_unit' in vol:
unit = vol['cap_unit']
else:
unit = 'GB'
name = None
if 'vol_name' in vol:
name = vol['vol_name']
if 'size' in vol:
size = vol['size']
else:
self.show_error_exit(
msg='No valid size was specified for the volume {0}'
.format(vol))
try:
params = {"storageGroupId": sg_name,
"volume_identifier": name}
volume_list = self.provisioning.get_volume_list(params)
if not volume_list or len(volume_list) == 0 or name is None:
LOG.info(
'No volume found with volume identifier %s '
'in storage group %s', name, sg_name)
remote_array = None
remote_array_sg = None
# Check SRDF protected SG
if self.if_srdf_protected(storage_group):
array_id = self.module.params['serial_no']
array_details = self.common.get_array(
array_id=array_id)
if 'ucode' in array_details and \
utils.parse_version(array_details['ucode']) \
< utils.parse_version(
self.foxtail_version):
msg = ("Add new volumes on SRDF protected"
" storage group is supported from"
" v5978.444.444 onwards."
" Upgrade the array for this support.")
self.show_error_exit(msg=msg)
rdfg_list = self.replication. \
get_storage_group_srdf_group_list(
storage_group_id=sg_name)
# Basic configuration
if len(rdfg_list) == 1:
rdfg_details = self.replication.\
get_rdf_group(rdf_number=rdfg_list[0])
remote_array = rdfg_details['remoteSymmetrix']
remote_array_sg = sg_name
msg = ("Creating volume with parameters:"
"storage_group_id= ", sg_name,
", num_vols= ", 1,
", vol_size= ", size,
", cap_unit= ", unit,
", vol_name= ", name,
", create_new_volumes= ", True,
", remote_array_1_id= ", remote_array,
", remote_array_1_sgs= ",
remote_array_sg)
LOG.info(msg)
if not self.module.check_mode:
self.provisioning.add_new_volume_to_storage_group(
storage_group_id=sg_name, num_vols=1,
vol_size=size, cap_unit=unit,
vol_name=name,
create_new_volumes=True,
remote_array_1_id=remote_array,
remote_array_1_sgs=remote_array_sg)
LOG.info('Volume created!')
changed = True
# Multisite configuration
if len(rdfg_list) == 2:
remote_array_1 = None
remote_array_1_sg = None
remote_array_2 = None
remote_array_2_sg = None
LOG.info("Concurrent configuration detected "
"for %s", sg_name)
rdfg_details = self.replication. \
get_rdf_group(rdf_number=rdfg_list[0])
remote_array_1 = rdfg_details['remoteSymmetrix']
remote_array_1_sg = sg_name
rdfg_details = self.replication. \
get_rdf_group(rdf_number=rdfg_list[1])
remote_array_2 = rdfg_details['remoteSymmetrix']
remote_array_2_sg = sg_name
msg = ("Creating volume with parameters:"
"storage_group_id= ", sg_name,
", num_vols= ", 1,
", vol_size= ", size,
", cap_unit= ", unit,
", vol_name= ", name,
", create_new_volumes= ", True,
", remote_array_1_id= ",
remote_array_1,
", remote_array_1_sgs= ",
remote_array_1_sg,
", remote_array_2_id= ",
remote_array_2,
", remote_array_2_sgs= ",
remote_array_2_sg
)
LOG.info(msg)
if not self.module.check_mode:
self.provisioning.add_new_volume_to_storage_group(
storage_group_id=sg_name, num_vols=1,
vol_size=size, cap_unit=unit,
vol_name=name,
create_new_volumes=True,
remote_array_1_id=remote_array_1,
remote_array_1_sgs=remote_array_1_sg,
remote_array_2_id=remote_array_2,
remote_array_2_sgs=remote_array_2_sg)
LOG.info('Volume created!')
changed = True
if len(rdfg_list) > 2:
err_msg = (
"More than 2 RDF groups exist for the given "
"storage group {0}. Create volume is not "
"supported.".formate(sg_name))
self.show_error_exit(msg=err_msg)
# non SRDF protected SG
else:
LOG.info('Creating volume with name %s, '
'size %s %s', name, size, unit)