forked from emc-openstack/vmax-cinder-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemc_vmax_provision.py
1032 lines (887 loc) · 41.8 KB
/
emc_vmax_provision.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
# Copyright (c) 2012 - 2014 EMC Corporation.
# All Rights Reserved.
#
# 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.
import time
import six
from cinder import exception
from cinder.i18n import _, _LE
from cinder.openstack.common import log as logging
from cinder.volume.drivers.emc import emc_vmax_utils
LOG = logging.getLogger(__name__)
STORAGEGROUPTYPE = 4
POSTGROUPTYPE = 3
EMC_ROOT = 'root/emc'
THINPROVISIONINGCOMPOSITE = 32768
THINPROVISIONING = 5
class EMCVMAXProvision(object):
"""Provisioning Class for SMI-S based EMC volume drivers.
This Provisioning class is for EMC volume drivers based on SMI-S.
It supports VMAX arrays.
"""
def __init__(self, prtcl):
self.protocol = prtcl
self.utils = emc_vmax_utils.EMCVMAXUtils(prtcl)
def delete_volume_from_pool(
self, conn, storageConfigservice, volumeInstanceName, volumeName):
"""Given the volume instance remove it from the pool.
:param conn: connection the the ecom server
:param storageConfigservice: volume created from job
:param volumeInstanceName: the volume instance name
:param volumeName: the volume name (String)
:param
:param rc: return code
"""
startTime = time.time()
if isinstance(volumeInstanceName, list):
theElements = volumeInstanceName
volumeName = 'Bulk Delete'
else:
theElements = [volumeInstanceName]
rc, job = conn.InvokeMethod(
'EMCReturnToStoragePool', storageConfigservice,
TheElements=theElements)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Delete Volume: %(volumeName)s. "
"Return code: %(rc)lu. Error: %(error)s")
% {'volumeName': volumeName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod EMCReturnToStoragePool took: "
"%(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc
def create_volume_from_pool(
self, conn, storageConfigService, volumeName,
poolInstanceName, volumeSize):
"""Create the volume in the specified pool.
:param conn: the connection information to the ecom server
:param storageConfigService: the storage configuration service
:param volumeName: the volume name (String)
:param poolInstanceName: the pool instance name to create
the dummy volume in
:param volumeSize: volume size (String)
:returns: volumeDict - the volume dict
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'CreateOrModifyElementFromStoragePool',
storageConfigService, ElementName=volumeName,
InPool=poolInstanceName,
ElementType=self.utils.get_num(THINPROVISIONING, '16'),
Size=self.utils.get_num(volumeSize, '64'),
EMCBindElements=False)
LOG.debug("Create Volume: %(volumename)s Return code: %(rc)lu",
{'volumename': volumeName,
'rc': rc})
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Create Volume: %(volumeName)s. "
"Return code: %(rc)lu. Error: %(error)s")
% {'volumeName': volumeName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod CreateOrModifyElementFromStoragePool "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
# Find the newly created volume
volumeDict = self.get_volume_dict_from_job(conn, job['Job'])
return volumeDict, rc
def create_and_get_storage_group(self, conn, controllerConfigService,
storageGroupName, volumeInstanceName):
"""Create a storage group and return it.
:param conn: the connection information to the ecom server
:param controllerConfigService: the controller configuration service
:param storageGroupName: the storage group name (String
:param volumeInstanceName: the volume instance name
:returns: foundStorageGroupInstanceName - instance name of the
default storage group
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'CreateGroup', controllerConfigService, GroupName=storageGroupName,
Type=self.utils.get_num(STORAGEGROUPTYPE, '16'),
Members=[volumeInstanceName])
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Create Group: %(groupName)s. "
"Return code: %(rc)lu. Error: %(error)s")
% {'groupName': storageGroupName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod CreateGroup "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
foundStorageGroupInstanceName = self._find_new_storage_group(
conn, job, storageGroupName)
return foundStorageGroupInstanceName
def create_storage_group_no_members(
self, conn, controllerConfigService, groupName):
"""Create a new storage group that has no members.
:param conn: connection the ecom server
:param controllerConfigService: the controller configuration service
:param groupName: the proposed group name
:returns: foundStorageGroupInstanceName - the instance Name of
the storage group
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'CreateGroup', controllerConfigService, GroupName=groupName,
Type=self.utils.get_num(STORAGEGROUPTYPE, '16'),
DeleteWhenBecomesUnassociated=False)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Create Group: %(groupName)s. "
"Return code: %(rc)lu. Error: %(error)s")
% {'groupName': groupName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod CreateGroup "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
foundStorageGroupInstanceName = self._find_new_storage_group(
conn, job, groupName)
return foundStorageGroupInstanceName
def _find_new_storage_group(
self, conn, maskingGroupDict, storageGroupName):
"""After creating an new storage group find it and return it.
:param conn: connection the ecom server
:param maskingGroupDict: the maskingGroupDict dict
:param storageGroupName: storage group name (String)
:returns: maskingGroupDict['MaskingGroup']
"""
foundStorageGroupInstanceName = None
if 'MaskingGroup' in maskingGroupDict:
foundStorageGroupInstanceName = maskingGroupDict['MaskingGroup']
return foundStorageGroupInstanceName
def get_volume_dict_from_job(self, conn, jobInstance):
"""Given the jobInstance determine the volume Instance.
:param conn: the ecom connection
:param jobInstance: the instance of a job
:returns: volumeDict - an instance of a volume
"""
associators = conn.Associators(
jobInstance,
ResultClass='EMC_StorageVolume')
volpath = associators[0].path
volumeDict = {}
volumeDict['classname'] = volpath.classname
keys = {}
keys['CreationClassName'] = volpath['CreationClassName']
keys['SystemName'] = volpath['SystemName']
keys['DeviceID'] = volpath['DeviceID']
keys['SystemCreationClassName'] = volpath['SystemCreationClassName']
volumeDict['keybindings'] = keys
return volumeDict
def remove_device_from_storage_group(
self, conn, controllerConfigService, storageGroupInstanceName,
volumeInstanceName, volumeName):
"""Remove a volume from a storage group.
:param conn: the connection to the ecom server
:param controllerConfigService: the controller configuration service
:param storageGroupInstanceName: the instance name of the storage group
:param volumeInstanceName: the instance name of the volume
:param volumeName: the volume name (String)
:returns: rc - the return code of the job
"""
startTime = time.time()
rc, jobDict = conn.InvokeMethod('RemoveMembers',
controllerConfigService,
MaskingGroup=storageGroupInstanceName,
Members=[volumeInstanceName])
if rc != 0L:
rc, errorDesc = self.utils.wait_for_job_complete(conn, jobDict)
if rc != 0L:
exceptionMessage = (_(
"Error removing volume %(vol)s. %(error)s")
% {'vol': volumeName, 'error': errorDesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod RemoveMembers "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc
def add_members_to_masking_group(
self, conn, controllerConfigService, storageGroupInstanceName,
volumeInstanceName, volumeName):
"""Add a member to a masking group group.
:param conn: the connection to the ecom server
:param controllerConfigService: the controller configuration service
:param storageGroupInstanceName: the instance name of the storage group
:param volumeInstanceName: the instance name of the volume
:param volumeName: the volume name (String)
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'AddMembers', controllerConfigService,
MaskingGroup=storageGroupInstanceName,
Members=[volumeInstanceName])
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error mapping volume %(vol)s. %(error)s")
% {'vol': volumeName, 'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod AddMembers "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
def unbind_volume_from_storage_pool(
self, conn, storageConfigService, poolInstanceName,
volumeInstanceName, volumeName):
"""Unbind a volume from a pool and return the unbound volume.
:param conn: the connection information to the ecom server
:param storageConfigService: the storage configuration service
instance name
:param poolInstanceName: the pool instance name
:param volumeInstanceName: the volume instance name
:param volumeName: the volume name
:returns: unboundVolumeInstance - the unbound volume instance
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'EMCUnBindElement',
storageConfigService,
InPool=poolInstanceName,
TheElement=volumeInstanceName)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error unbinding volume %(vol)s from pool. %(error)s")
% {'vol': volumeName, 'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod EMCUnBindElement "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def modify_composite_volume(
self, conn, elementCompositionService, theVolumeInstanceName,
inVolumeInstanceName):
"""Given a composite volume add a storage volume to it.
:param conn: the connection to the ecom
:param elementCompositionService: the element composition service
:param theVolumeInstanceName: the existing composite volume
:param inVolumeInstanceName: the volume you wish to add to the
composite volume
:returns: rc - return code
:returns: job - job
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'CreateOrModifyCompositeElement',
elementCompositionService,
TheElement=theVolumeInstanceName,
InElements=[inVolumeInstanceName])
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error adding volume to composite volume. "
"Error is: %(error)s")
% {'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod CreateOrModifyCompositeElement "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def create_composite_volume(
self, conn, elementCompositionService, volumeSize, volumeName,
poolInstanceName, compositeType, numMembers):
"""Create a new volume using the auto meta feature.
:param conn: the connection the the ecom server
:param elementCompositionService: the element composition service
:param volumeSize: the size of the volume
:param volumeName: user friendly name
:param poolInstanceName: the pool to bind the composite volume to
:param compositeType: the proposed composite type of the volume
e.g striped/concatenated
:param numMembers: the number of meta members to make up the composite.
If it is 1 then a non composite is created
:returns: rc
:returns: errordesc
"""
startTime = time.time()
newMembers = 2
LOG.debug(
"Parameters for CreateOrModifyCompositeElement: "
"elementCompositionService: %(elementCompositionService)s "
"provisioning: %(provisioning)lu "
"volumeSize: %(volumeSize)s "
"newMembers: %(newMembers)lu "
"poolInstanceName: %(poolInstanceName)s "
"compositeType: %(compositeType)lu "
"numMembers: %(numMembers)s ",
{'elementCompositionService': elementCompositionService,
'provisioning': THINPROVISIONINGCOMPOSITE,
'volumeSize': volumeSize,
'newMembers': newMembers,
'poolInstanceName': poolInstanceName,
'compositeType': compositeType,
'numMembers': numMembers})
rc, job = conn.InvokeMethod(
'CreateOrModifyCompositeElement', elementCompositionService,
ElementName=volumeName,
ElementType=self.utils.get_num(THINPROVISIONINGCOMPOSITE, '16'),
Size=self.utils.get_num(volumeSize, '64'),
ElementSource=self.utils.get_num(newMembers, '16'),
EMCInPools=[poolInstanceName],
CompositeType=self.utils.get_num(compositeType, '16'),
EMCNumberOfMembers=self.utils.get_num(numMembers, '32'))
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Create Volume: %(volumename)s. "
"Return code: %(rc)lu. Error: %(error)s")
% {'volumename': volumeName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod CreateOrModifyCompositeElement "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
# Find the newly created volume
volumeDict = self.get_volume_dict_from_job(conn, job['Job'])
return volumeDict, rc
def create_new_composite_volume(
self, conn, elementCompositionService, compositeHeadInstanceName,
compositeMemberInstanceName, compositeType):
"""Creates a new composite volume.
Given a bound composite head and an unbound composite member
create a new composite volume.
:param conn: the connection the the ecom server
:param elementCompositionService: the element composition service
:param compositeHeadInstanceName: the composite head. This can be bound
:param compositeMemberInstanceName: the composite member.
This must be unbound
:param compositeType: the composite type e.g striped or concatenated
:returns: rc - return code
:returns: errordesc - descriptions of the error
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'CreateOrModifyCompositeElement', elementCompositionService,
ElementType=self.utils.get_num('2', '16'),
InElements=(
[compositeHeadInstanceName, compositeMemberInstanceName]),
CompositeType=self.utils.get_num(compositeType, '16'))
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Creating new composite Volume Return code: %(rc)lu."
"Error: %(error)s")
% {'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod CreateOrModifyCompositeElement "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def _migrate_volume(
self, conn, storageRelocationServiceInstanceName,
volumeInstanceName, targetPoolInstanceName):
"""Migrate a volume to another pool.
:param conn: the connection to the ecom server
:param storageRelocationServiceInstanceName: the storage relocation
service
:param volumeInstanceName: the volume to be migrated
:param targetPoolInstanceName: the target pool to migrate the volume to
:returns: rc - return code
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'RelocateStorageVolumesToStoragePool',
storageRelocationServiceInstanceName,
TheElements=[volumeInstanceName],
TargetPool=targetPoolInstanceName)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Migrating volume from one pool to another. "
"Return code: %(rc)lu. Error: %(error)s")
% {'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod RelocateStorageVolumesToStoragePool "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc
def migrate_volume_to_storage_pool(
self, conn, storageRelocationServiceInstanceName,
volumeInstanceName, targetPoolInstanceName):
"""Given the storage system name, get the storage relocation service.
:param conn: the connection to the ecom server
:param storageRelocationServiceInstanceName: the storage relocation
service
:param volumeInstanceName: the volume to be migrated
:param targetPoolInstanceName: the target pool to migrate the
volume to.
:returns: rc
"""
LOG.debug(
"Volume instance name is %(volumeInstanceName)s. "
"Pool instance name is : %(targetPoolInstanceName)s. ",
{'volumeInstanceName': volumeInstanceName,
'targetPoolInstanceName': targetPoolInstanceName})
rc = -1
try:
rc = self._migrate_volume(
conn, storageRelocationServiceInstanceName,
volumeInstanceName, targetPoolInstanceName)
except Exception as ex:
if 'source of a migration session' in six.text_type(ex):
try:
rc = self._terminate_migrate_session(
conn, volumeInstanceName)
except Exception as ex:
LOG.error(_LE('Exception: %s'), ex)
exceptionMessage = (_(
"Failed to terminate migrate session"))
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
try:
rc = self._migrate_volume(
conn, storageRelocationServiceInstanceName,
volumeInstanceName, targetPoolInstanceName)
except Exception as ex:
LOG.error(_LE('Exception: %s'), ex)
exceptionMessage = (_(
"Failed to migrate volume for the second time"))
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
else:
LOG.error(_LE('Exception: %s'), ex)
exceptionMessage = (_(
"Failed to migrate volume for the first time"))
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
return rc
def _terminate_migrate_session(self, conn, volumeInstanceName):
"""Given the volume instance terminate a migrate session.
:param conn: the connection to the ecom server
:param volumeInstanceName: the volume to be migrated
:returns: rc
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'RequestStateChange', volumeInstanceName,
RequestedState=self.utils.get_num(32769, '16'))
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Terminating migrate session. "
"Return code: %(rc)lu. Error: %(error)s")
% {'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod RequestStateChange "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc
def create_element_replica(
self, conn, repServiceInstanceName, cloneName,
sourceName, sourceInstance, targetInstance, copyOnWrite=False):
"""Make SMI-S call to create replica for source element
:param conn - the connection to the ecom server
:param repServiceInstanceName - replication service
:param cloneName - replica name
:param sourceName - source volume name
:param sourceInstance - source volume instance
:returns: rc - return code
:returns: job - job object of the replica creation operation
"""
if copyOnWrite:
startTime = time.time()
repServiceCapabilityInstanceNames = conn.AssociatorNames(
repServiceInstanceName,
ResultClass='CIM_ReplicationServiceCapabilities',
AssocClass='CIM_ElementCapabilities')
repServiceCapabilityInstanceName = \
repServiceCapabilityInstanceNames[0]
# ReplicationType 10 - Synchronous Clone Local
rc, rsd = conn.InvokeMethod(
'GetDefaultReplicationSettingData',
repServiceCapabilityInstanceName,
ReplicationType=self.utils.get_num(10, '16'))
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, rsd)
if rc != 0L:
exceptionMessage = (_(
"Error Create Cloned Volume: "
"Volume: %(cloneName)s Source Volume:"
"%(sourceName)s. Return code: %(rc)lu."
"Error: %(error)s")
% {'cloneName': cloneName,
'sourceName': sourceName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod GetDefaultReplicationSettingData "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
# Set DesiredCopyMethodology to Copy-On-Write (6)
rsdInstance = rsd['DefaultInstance']
rsdInstance['DesiredCopyMethodology'] = self.utils.get_num(6, '16')
startTime = time.time()
# SyncType 8 - Clone
# ReplicationSettingData.DesiredCopyMethodology 6 - Copy-On-Write
rc, job = conn.InvokeMethod(
'CreateElementReplica', repServiceInstanceName,
ElementName=cloneName, SyncType=self.utils.get_num(8, '16'),
ReplicationSettingData=rsdInstance,
SourceElement=sourceInstance.path)
else:
startTime = time.time()
if targetInstance is None:
rc, job = conn.InvokeMethod(
'CreateElementReplica', repServiceInstanceName,
ElementName=cloneName,
SyncType=self.utils.get_num(8, '16'),
SourceElement=sourceInstance.path)
else:
rc, job = conn.InvokeMethod(
'CreateElementReplica', repServiceInstanceName,
ElementName=cloneName,
SyncType=self.utils.get_num(8, '16'),
SourceElement=sourceInstance.path,
TargetElement=targetInstance.path)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error Create Cloned Volume: "
"Volume: %(cloneName)s Source Volume:"
"%(sourceName)s. Return code: %(rc)lu."
"Error: %(error)s")
% {'cloneName': cloneName,
'sourceName': sourceName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod CreateElementReplica "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def delete_clone_relationship(
self, conn, repServiceInstanceName, syncInstanceName, force=False):
"""Deletes the relationship between the clone and source volume.
Makes an SMI-S call to break clone relationship between the clone
volume and the source
:param conn: the connection to the ecom server
:param repServiceInstanceName: instance name of the replication service
:param syncInstanceName: instance name of the
SE_StorageSynchronized_SV_SV object
:returns: rc - return code
:returns: job - job object of the replica creation operation
"""
'''
8/Detach - Delete the synchronization between two storage objects.
Treat the objects as independent after the synchronization is deleted.
'''
startTime = time.time()
rc, job = conn.InvokeMethod(
'ModifyReplicaSynchronization', repServiceInstanceName,
Operation=self.utils.get_num(8, '16'),
Synchronization=syncInstanceName,
Force=force)
LOG.debug("Delete clone relationship: Sync Name: %(syncName)s "
"Return code: %(rc)lu",
{'syncName': syncInstanceName,
'rc': rc})
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Error break clone relationship: "
"Sync Name: %(syncName)s "
"Return code: %(rc)lu. Error: %(error)s")
% {'syncName': syncInstanceName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod ModifyReplicaSynchronization "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def get_target_endpoints(self, conn, storageHardwareService, hardwareId):
"""Given the hardwareId get the
:param conn: the connection to the ecom server
:param storageHardwareService: the storage HardwareId Service
:param hardwareId: the hardware Id
:returns: rc
:returns: targetendpoints
"""
startTime = time.time()
rc, targetEndpoints = conn.InvokeMethod(
'EMCGetTargetEndpoints', storageHardwareService,
HardwareId=hardwareId)
if rc != 0L:
exceptionMessage = (_("Error finding Target WWNs."))
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(data=exceptionMessage)
LOG.debug("InvokeMethod EMCGetTargetEndpoints "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, targetEndpoints
def create_consistency_group(
self, conn, replicationService, consistencyGroupName):
"""Create a new consistency group
:param conn: the connection to the ecom server
:param replicationService: the replication Service
:param consistencyGroupName: the CG group name
:returns: rc
:returns: job
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'CreateGroup',
replicationService,
GroupName=consistencyGroupName)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Failed to create consistency group: "
"%(consistencyGroupName)s "
"Return code: %(rc)lu. Error: %(error)s")
% {'consistencyGroupName': consistencyGroupName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod CreateGroup "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def delete_consistency_group(
self, conn, replicationService, cgInstanceName,
consistencyGroupName):
"""Delete a consistency group
:param conn: the connection to the ecom server
:param replicationService: the replication Service
:param cgInstanceName: the CG instance name
:param consistencyGroupName: the CG group name
:returns: rc
:returns: job
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'DeleteGroup',
replicationService,
ReplicationGroup=cgInstanceName,
RemoveElements=True)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Failed to delete consistency group: "
"%(consistencyGroupName)s "
"Return code: %(rc)lu. Error: %(error)s")
% {'consistencyGroupName': consistencyGroupName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod DeleteGroup "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def add_volume_to_cg(
self, conn, replicationService, cgInstanceName,
volumeInstanceName, cgName, volumeName):
"""Add a volume to a consistency group
:param conn: the connection to the ecom server
:param replicationService: the replication Service
:param volumeInstanceName: the volume instance name
:param cgInstanceName: the CG instance name
:param cgName: the CG group name
:param volumeName: the volume name
:returns: rc
:returns: job
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'AddMembers',
replicationService,
Members=[volumeInstanceName],
ReplicationGroup=cgInstanceName)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Failed to add volume %(volumeName)s: "
"to consistency group %(cgName)s "
"Return code: %(rc)lu. Error: %(error)s")
% {'volumeName': volumeName,
'cgName': cgName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod AddMembers "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def remove_volume_from_cg(
self, conn, replicationService, cgInstanceName,
volumeInstanceName, cgName, volumeName):
"""Remove a volume from a consistency group
:param conn: the connection to the ecom server
:param replicationService: the replication Service
:param volumeInstanceName: the volume instance name
:param cgInstanceName: the CG instance name
:param cgName: the CG group name
:param volumeName: the volume name
:returns: rc
:returns: job
"""
startTime = time.time()
rc, job = conn.InvokeMethod(
'RemoveMembers',
replicationService,
Members=[volumeInstanceName],
ReplicationGroup=cgInstanceName,
RemoveElements=True)
if rc != 0L:
rc, errordesc = self.utils.wait_for_job_complete(conn, job)
if rc != 0L:
exceptionMessage = (_(
"Failed to remove volume %(volumeName)s: "
"to consistency group %(cgName)s "
"Return code: %(rc)lu. Error: %(error)s")
% {'volumeName': volumeName,
'cgName': cgName,
'rc': rc,
'error': errordesc})
LOG.error(exceptionMessage)
raise exception.VolumeBackendAPIException(
data=exceptionMessage)
LOG.debug("InvokeMethod RemoveMembers "
"took: %(delta)s H:MM:SS",
{'delta': self.utils.get_time_delta(startTime,
time.time())})
return rc, job
def create_group_replica(
self, conn, replicationService,
srcGroupInstanceName, tgtGroupInstanceName, relationName):
"""Make SMI-S call to create replica for source group
:param conn - the connection to the ecom server
:param repServiceInstanceName - replication service
:param srcGroupInstanceName - source group instance name
:param tgtGroupInstanceName - target group instance name
:param cgName - target group name
:returns: rc - return code
:returns: job - job object of the replica creation operation
"""