-
Notifications
You must be signed in to change notification settings - Fork 1
/
emc_smis_common.py
1713 lines (1448 loc) · 69.8 KB
/
emc_smis_common.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
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2013 EMC Corporation
# All Rights Reserved
#
# Licensed under EMC Freeware Software License Agreement
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://github.com/emc-openstack/freeware-eula/
# blob/master/Freeware_EULA_20131217_modified.md
#
"""
Common class for SMI-S based EMC volume drivers.
This common class is for EMC volume drivers based on SMI-S.
It supports VNX and VMAX arrays.
"""
import time
from oslo.config import cfg
from xml.dom.minidom import parseString
from cinder import context
from cinder import exception
from cinder.openstack.common import log as logging
from cinder import units
from cinder.volume import volume_types
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
try:
import pywbem
except ImportError:
LOG.info(_('Module PyWBEM not installed. '
'Install PyWBEM using the python-pywbem package.'))
CINDER_EMC_CONFIG_FILE = '/etc/cinder/cinder_emc_config.xml'
EMC_ROOT = 'root/emc'
PROVISIONING = 'storagetype:provisioning'
POOL = 'storagetype:pool'
class EMCSMISCommon():
"""Common code that can be used by ISCSI and FC drivers."""
stats = {'driver_version': '1.0',
'free_capacity_gb': 0,
'reserved_percentage': 0,
'storage_protocol': None,
'total_capacity_gb': 0,
'vendor_name': 'EMC',
'volume_backend_name': None}
def __init__(self, prtcl, configuration=None):
opt = cfg.StrOpt('cinder_emc_config_file',
default=CINDER_EMC_CONFIG_FILE,
help='use this file for cinder emc plugin '
'config data')
CONF.register_opt(opt)
self.protocol = prtcl
self.configuration = configuration
self.configuration.append_config_values([opt])
ip, port = self._get_ecom_server()
self.user, self.passwd = self._get_ecom_cred()
self.url = 'http://' + ip + ':' + port
self.conn = self._get_ecom_connection()
def create_volume(self, volume):
"""Creates a EMC(VMAX/VNX) volume."""
LOG.debug(_('Entering create_volume.'))
volumesize = int(volume['size']) * units.GiB
volumename = volume['name']
LOG.info(_('Create Volume: %(volume)s Size: %(size)lu')
% {'volume': volumename,
'size': volumesize})
self.conn = self._get_ecom_connection()
storage_type = self._get_storage_type(volume)
LOG.debug(_('Create Volume: %(volume)s '
'Storage type: %(storage_type)s')
% {'volume': volumename,
'storage_type': storage_type})
pool, storage_system = self._find_pool(storage_type[POOL])
LOG.debug(_('Create Volume: %(volume)s Pool: %(pool)s '
'Storage System: %(storage_system)s')
% {'volume': volumename,
'pool': str(pool),
'storage_system': storage_system})
configservice = self._find_storage_configuration_service(
storage_system)
if configservice is None:
exception_message = (_("Error Create Volume: %(volumename)s. "
"Storage Configuration Service not found for "
"pool %(storage_type)s.")
% {'volumename': volumename,
'storage_type': storage_type})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(data=exception_message)
provisioning = self._get_provisioning(storage_type)
LOG.debug(_('Create Volume: %(name)s Method: '
'CreateOrModifyElementFromStoragePool ConfigServicie: '
'%(service)s ElementName: %(name)s InPool: %(pool)s '
'ElementType: %(provisioning)s Size: %(size)lu')
% {'service': str(configservice),
'name': volumename,
'pool': str(pool),
'provisioning': provisioning,
'size': volumesize})
rc, job = self.conn.InvokeMethod(
'CreateOrModifyElementFromStoragePool',
configservice, ElementName=volumename, InPool=pool,
ElementType=self._getnum(provisioning, '16'),
Size=self._getnum(volumesize, '64'))
LOG.debug(_('Create Volume: %(volumename)s Return code: %(rc)lu')
% {'volumename': volumename,
'rc': rc})
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
LOG.error(_('Error Create Volume: %(volumename)s. '
'Return code: %(rc)lu. Error: %(error)s')
% {'volumename': volumename,
'rc': rc,
'error': errordesc})
raise exception.VolumeBackendAPIException(data=errordesc)
# Find the newly created volume
associators = self.conn.Associators(
job['Job'],
resultClass='EMC_StorageVolume')
volpath = associators[0].path
name = {}
name['classname'] = volpath.classname
keys = {}
keys['CreationClassName'] = volpath['CreationClassName']
keys['SystemName'] = volpath['SystemName']
keys['DeviceID'] = volpath['DeviceID']
keys['SystemCreationClassName'] = volpath['SystemCreationClassName']
name['keybindings'] = keys
LOG.debug(_('Leaving create_volume: %(volumename)s '
'Return code: %(rc)lu '
'volume instance: %(name)s')
% {'volumename': volumename,
'rc': rc,
'name': name})
return name
def create_volume_from_snapshot(self, volume, snapshot):
"""Creates a volume from a snapshot."""
LOG.debug(_('Entering create_volume_from_snapshot.'))
snapshotname = snapshot['name']
volumename = volume['name']
LOG.info(_('Create Volume from Snapshot: Volume: %(volumename)s '
'Snapshot: %(snapshotname)s')
% {'volumename': volumename,
'snapshotname': snapshotname})
self.conn = self._get_ecom_connection()
snapshot_instance = self._find_lun(snapshot)
storage_system = snapshot_instance['SystemName']
LOG.debug(_('Create Volume from Snapshot: Volume: %(volumename)s '
'Snapshot: %(snapshotname)s Snapshot Instance: '
'%(snapshotinstance)s Storage System: %(storage_system)s.')
% {'volumename': volumename,
'snapshotname': snapshotname,
'snapshotinstance': str(snapshot_instance.path),
'storage_system': storage_system})
isVMAX = storage_system.find('SYMMETRIX')
if isVMAX > -1:
exception_message = (_('Error Create Volume from Snapshot: '
'Volume: %(volumename)s Snapshot: '
'%(snapshotname)s. Create Volume '
'from Snapshot is NOT supported on VMAX.')
% {'volumename': volumename,
'snapshotname': snapshotname})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(data=exception_message)
repservice = self._find_replication_service(storage_system)
if repservice is None:
exception_message = (_('Error Create Volume from Snapshot: '
'Volume: %(volumename)s Snapshot: '
'%(snapshotname)s. Cannot find Replication '
'Service to create volume from snapshot.')
% {'volumename': volumename,
'snapshotname': snapshotname})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(data=exception_message)
LOG.debug(_('Create Volume from Snapshot: Volume: %(volumename)s '
'Snapshot: %(snapshotname)s Method: CreateElementReplica '
'ReplicationService: %(service)s ElementName: '
'%(elementname)s SyncType: 8 SourceElement: '
'%(sourceelement)s')
% {'volumename': volumename,
'snapshotname': snapshotname,
'service': str(repservice),
'elementname': volumename,
'sourceelement': str(snapshot_instance.path)})
# Create a Clone from snapshot
rc, job = self.conn.InvokeMethod(
'CreateElementReplica', repservice,
ElementName=volumename,
SyncType=self._getnum(8, '16'),
SourceElement=snapshot_instance.path)
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
exception_message = (_('Error Create Volume from Snapshot: '
'Volume: %(volumename)s Snapshot:'
'%(snapshotname)s. Return code: %(rc)lu.'
'Error: %(error)s')
% {'volumename': volumename,
'snapshotname': snapshotname,
'rc': rc,
'error': errordesc})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
data=exception_message)
# Find the newly created volume
associators = self.conn.Associators(
job['Job'],
resultClass='EMC_StorageVolume')
volpath = associators[0].path
name = {}
name['classname'] = volpath.classname
keys = {}
keys['CreationClassName'] = volpath['CreationClassName']
keys['SystemName'] = volpath['SystemName']
keys['DeviceID'] = volpath['DeviceID']
keys['SystemCreationClassName'] = volpath['SystemCreationClassName']
name['keybindings'] = keys
LOG.debug(_('Create Volume from Snapshot: Volume: %(volumename)s '
'Snapshot: %(snapshotname)s. Successfully clone volume '
'from snapshot. Finding the clone relationship.')
% {'volumename': volumename,
'snapshotname': snapshotname})
volume['provider_location'] = str(name)
sync_name, storage_system = self._find_storage_sync_sv_sv(
volume, snapshot)
# Remove the Clone relationshop so it can be used as a regular lun
# 8 - Detach operation
LOG.debug(_('Create Volume from Snapshot: Volume: %(volumename)s '
'Snapshot: %(snapshotname)s. Remove the clone '
'relationship. Method: ModifyReplicaSynchronization '
'ReplicationService: %(service)s Operation: 8 '
'Synchronization: %(sync_name)s')
% {'volumename': volumename,
'snapshotname': snapshotname,
'service': str(repservice),
'sync_name': str(sync_name)})
rc, job = self.conn.InvokeMethod(
'ModifyReplicaSynchronization',
repservice,
Operation=self._getnum(8, '16'),
Synchronization=sync_name)
LOG.debug(_('Create Volume from Snapshot: Volume: %(volumename)s '
'Snapshot: %(snapshotname)s Return code: %(rc)lu')
% {'volumename': volumename,
'snapshotname': snapshotname,
'rc': rc})
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
exception_message = (_('Error Create Volume from Snapshot: '
'Volume: %(volumename)s '
'Snapshot: %(snapshotname)s. '
'Return code: %(rc)lu. Error: %(error)s')
% {'volumename': volumename,
'snapshotname': snapshotname,
'rc': rc,
'error': errordesc})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
data=exception_message)
LOG.debug(_('Leaving create_volume_from_snapshot: Volume: '
'%(volumename)s Snapshot: %(snapshotname)s '
'Return code: %(rc)lu.')
% {'volumename': volumename,
'snapshotname': snapshotname,
'rc': rc})
return name
def create_cloned_volume(self, volume, src_vref):
"""Creates a clone of the specified volume."""
LOG.debug(_('Entering create_cloned_volume.'))
srcname = src_vref['name']
volumename = volume['name']
LOG.info(_('Create a Clone from Volume: Volume: %(volumename)s '
'Source Volume: %(srcname)s')
% {'volumename': volumename,
'srcname': srcname})
self.conn = self._get_ecom_connection()
src_instance = self._find_lun(src_vref)
storage_system = src_instance['SystemName']
LOG.debug(_('Create Cloned Volume: Volume: %(volumename)s '
'Source Volume: %(srcname)s Source Instance: '
'%(src_instance)s Storage System: %(storage_system)s.')
% {'volumename': volumename,
'srcname': srcname,
'src_instance': str(src_instance.path),
'storage_system': storage_system})
repservice = self._find_replication_service(storage_system)
if repservice is None:
exception_message = (_('Error Create Cloned Volume: '
'Volume: %(volumename)s Source Volume: '
'%(srcname)s. Cannot find Replication '
'Service to create cloned volume.')
% {'volumename': volumename,
'srcname': srcname})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(data=exception_message)
LOG.debug(_('Create Cloned Volume: Volume: %(volumename)s '
'Source Volume: %(srcname)s Method: CreateElementReplica '
'ReplicationService: %(service)s ElementName: '
'%(elementname)s SyncType: 8 SourceElement: '
'%(sourceelement)s')
% {'volumename': volumename,
'srcname': srcname,
'service': str(repservice),
'elementname': volumename,
'sourceelement': str(src_instance.path)})
# Create a Clone from source volume
rc, job = self.conn.InvokeMethod(
'CreateElementReplica', repservice,
ElementName=volumename,
SyncType=self._getnum(8, '16'),
SourceElement=src_instance.path)
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
exception_message = (_('Error Create Cloned Volume: '
'Volume: %(volumename)s Source Volume:'
'%(srcname)s. Return code: %(rc)lu.'
'Error: %(error)s')
% {'volumename': volumename,
'srcname': srcname,
'rc': rc,
'error': errordesc})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
data=exception_message)
# Find the newly created volume
associators = self.conn.Associators(
job['Job'],
resultClass='EMC_StorageVolume')
volpath = associators[0].path
name = {}
name['classname'] = volpath.classname
keys = {}
keys['CreationClassName'] = volpath['CreationClassName']
keys['SystemName'] = volpath['SystemName']
keys['DeviceID'] = volpath['DeviceID']
keys['SystemCreationClassName'] = volpath['SystemCreationClassName']
name['keybindings'] = keys
LOG.debug(_('Create Cloned Volume: Volume: %(volumename)s '
'Source Volume: %(srcname)s. Successfully cloned volume '
'from source volume. Finding the clone relationship.')
% {'volumename': volumename,
'srcname': srcname})
volume['provider_location'] = str(name)
sync_name, storage_system = self._find_storage_sync_sv_sv(
volume, src_vref)
# Remove the Clone relationshop so it can be used as a regular lun
# 8 - Detach operation
LOG.debug(_('Create Cloned Volume: Volume: %(volumename)s '
'Source Volume: %(srcname)s. Remove the clone '
'relationship. Method: ModifyReplicaSynchronization '
'ReplicationService: %(service)s Operation: 8 '
'Synchronization: %(sync_name)s')
% {'volumename': volumename,
'srcname': srcname,
'service': str(repservice),
'sync_name': str(sync_name)})
rc, job = self.conn.InvokeMethod(
'ModifyReplicaSynchronization',
repservice,
Operation=self._getnum(8, '16'),
Synchronization=sync_name)
LOG.debug(_('Create Cloned Volume: Volume: %(volumename)s '
'Source Volume: %(srcname)s Return code: %(rc)lu')
% {'volumename': volumename,
'srcname': srcname,
'rc': rc})
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
exception_message = (_('Error Create Cloned Volume: '
'Volume: %(volumename)s '
'Source Volume: %(srcname)s. '
'Return code: %(rc)lu. Error: %(error)s')
% {'volumename': volumename,
'srcname': srcname,
'rc': rc,
'error': errordesc})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
data=exception_message)
LOG.debug(_('Leaving create_cloned_volume: Volume: '
'%(volumename)s Source Volume: %(srcname)s '
'Return code: %(rc)lu.')
% {'volumename': volumename,
'srcname': srcname,
'rc': rc})
return name
def delete_volume(self, volume):
"""Deletes an EMC volume."""
LOG.debug(_('Entering delete_volume.'))
volumename = volume['name']
LOG.info(_('Delete Volume: %(volume)s')
% {'volume': volumename})
self.conn = self._get_ecom_connection()
vol_instance = self._find_lun(volume)
if vol_instance is None:
LOG.error(_('Volume %(name)s not found on the array. '
'No volume to delete.')
% {'name': volumename})
return
storage_system = vol_instance['SystemName']
configservice =\
self._find_storage_configuration_service(storage_system)
if configservice is None:
exception_message = (_("Error Delete Volume: %(volumename)s. "
"Storage Configuration Service not found.")
% {'volumename': volumename})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(data=exception_message)
device_id = vol_instance['DeviceID']
LOG.debug(_('Delete Volume: %(name)s DeviceID: %(deviceid)s')
% {'name': volumename,
'deviceid': device_id})
LOG.debug(_('Delete Volume: %(name)s Method: EMCReturnToStoragePool '
'ConfigServic: %(service)s TheElement: %(vol_instance)s')
% {'service': str(configservice),
'name': volumename,
'vol_instance': str(vol_instance.path)})
rc, job =\
self.conn.InvokeMethod('EMCReturnToStoragePool',
configservice,
TheElements=[vol_instance.path])
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
exception_message = (_('Error Delete Volume: %(volumename)s. '
'Return code: %(rc)lu. Error: %(error)s')
% {'volumename': volumename,
'rc': rc,
'error': errordesc})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
data=exception_message)
LOG.debug(_('Leaving delete_volume: %(volumename)s Return code: '
'%(rc)lu')
% {'volumename': volumename,
'rc': rc})
def create_snapshot(self, snapshot, volume):
"""Creates a snapshot."""
LOG.debug(_('Entering create_snapshot.'))
snapshotname = snapshot['name']
volumename = snapshot['volume_name']
LOG.info(_('Create snapshot: %(snapshot)s: volume: %(volume)s')
% {'snapshot': snapshotname,
'volume': volumename})
self.conn = self._get_ecom_connection()
vol_instance = self._find_lun(volume)
device_id = vol_instance['DeviceID']
storage_system = vol_instance['SystemName']
LOG.debug(_('Device ID: %(deviceid)s: Storage System: '
'%(storagesystem)s')
% {'deviceid': device_id,
'storagesystem': storage_system})
repservice = self._find_replication_service(storage_system)
if repservice is None:
LOG.error(_("Cannot find Replication Service to create snapshot "
"for volume %s.") % volumename)
exception_message = (_("Cannot find Replication Service to "
"create snapshot for volume %s.")
% volumename)
raise exception.VolumeBackendAPIException(data=exception_message)
LOG.debug(_("Create Snapshot: Method: CreateElementReplica: "
"Target: %(snapshot)s Source: %(volume)s Replication "
"Service: %(service)s ElementName: %(elementname)s Sync "
"Type: 7 SourceElement: %(sourceelement)s.")
% {'snapshot': snapshotname,
'volume': volumename,
'service': str(repservice),
'elementname': snapshotname,
'sourceelement': str(vol_instance.path)})
rc, job =\
self.conn.InvokeMethod('CreateElementReplica', repservice,
ElementName=snapshotname,
SyncType=self._getnum(7, '16'),
SourceElement=vol_instance.path)
LOG.debug(_('Create Snapshot: Volume: %(volumename)s '
'Snapshot: %(snapshotname)s Return code: %(rc)lu')
% {'volumename': volumename,
'snapshotname': snapshotname,
'rc': rc})
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
exception_message = (_('Error Create Snapshot: %(snapshot)s '
'Volume: %(volume)s Error: %(errordesc)s')
% {'snapshot': snapshotname, 'volume':
volumename, 'errordesc': errordesc})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
data=exception_message)
# Find the newly created volume
associators = self.conn.Associators(
job['Job'],
resultClass='EMC_StorageVolume')
volpath = associators[0].path
name = {}
name['classname'] = volpath.classname
keys = {}
keys['CreationClassName'] = volpath['CreationClassName']
keys['SystemName'] = volpath['SystemName']
keys['DeviceID'] = volpath['DeviceID']
keys['SystemCreationClassName'] = volpath['SystemCreationClassName']
name['keybindings'] = keys
LOG.debug(_('Leaving create_snapshot: Snapshot: %(snapshot)s '
'Volume: %(volume)s Return code: %(rc)lu.') %
{'snapshot': snapshotname, 'volume': volumename, 'rc': rc})
return name
def delete_snapshot(self, snapshot, volume):
"""Deletes a snapshot."""
LOG.debug(_('Entering delete_snapshot.'))
snapshotname = snapshot['name']
volumename = snapshot['volume_name']
LOG.info(_('Delete Snapshot: %(snapshot)s: volume: %(volume)s')
% {'snapshot': snapshotname,
'volume': volumename})
self.conn = self._get_ecom_connection()
LOG.debug(_('Delete Snapshot: %(snapshot)s: volume: %(volume)s. '
'Finding StorageSychronization_SV_SV.')
% {'snapshot': snapshotname,
'volume': volumename})
sync_name, storage_system =\
self._find_storage_sync_sv_sv(snapshot, volume, False)
if sync_name is None:
LOG.error(_('Snapshot: %(snapshot)s: volume: %(volume)s '
'not found on the array. No snapshot to delete.')
% {'snapshot': snapshotname,
'volume': volumename})
return
repservice = self._find_replication_service(storage_system)
if repservice is None:
exception_message = (_("Cannot find Replication Service to "
"create snapshot for volume %s.")
% volumename)
raise exception.VolumeBackendAPIException(data=exception_message)
# Delete snapshot - deletes both the target element
# and the snap session
LOG.debug(_("Delete Snapshot: Target: %(snapshot)s "
"Source: %(volume)s. Method: "
"ModifyReplicaSynchronization: "
"Replication Service: %(service)s Operation: 19 "
"Synchronization: %(sync_name)s.")
% {'snapshot': snapshotname,
'volume': volumename,
'service': str(repservice),
'sync_name': str(sync_name)})
rc, job =\
self.conn.InvokeMethod('ModifyReplicaSynchronization',
repservice,
Operation=self._getnum(19, '16'),
Synchronization=sync_name)
LOG.debug(_('Delete Snapshot: Volume: %(volumename)s Snapshot: '
'%(snapshotname)s Return code: %(rc)lu')
% {'volumename': volumename,
'snapshotname': snapshotname,
'rc': rc})
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
exception_message = (_('Error Delete Snapshot: Volume: '
'%(volumename)s Snapshot: '
'%(snapshotname)s. Return code: %(rc)lu.'
' Error: %(error)s')
% {'volumename': volumename,
'snapshotname': snapshotname,
'rc': rc,
'error': errordesc})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
data=exception_message)
LOG.debug(_('Leaving delete_snapshot: Volume: %(volumename)s '
'Snapshot: %(snapshotname)s Return code: %(rc)lu.')
% {'volumename': volumename,
'snapshotname': snapshotname,
'rc': rc})
# Mapping method for VNX
def _expose_paths(self, configservice, vol_instance,
connector):
"""This method maps a volume to a host.
It adds a volume and initiator to a Storage Group
and therefore maps the volume to the host.
"""
volumename = vol_instance['ElementName']
lun_name = vol_instance['DeviceID']
initiators = self._find_initiator_names(connector)
storage_system = vol_instance['SystemName']
lunmask_ctrl = self._find_lunmasking_scsi_protocol_controller(
storage_system, connector)
LOG.debug(_('ExposePaths: %(vol)s ConfigServicie: %(service)s '
'LUNames: %(lun_name)s InitiatorPortIDs: %(initiator)s '
'DeviceAccesses: 2')
% {'vol': str(vol_instance.path),
'service': str(configservice),
'lun_name': lun_name,
'initiator': initiators})
if lunmask_ctrl is None:
rc, controller =\
self.conn.InvokeMethod('ExposePaths',
configservice, LUNames=[lun_name],
InitiatorPortIDs=initiators,
DeviceAccesses=[self._getnum(2, '16')])
else:
LOG.debug(_('ExposePaths parameter '
'LunMaskingSCSIProtocolController: '
'%(lunmasking)s')
% {'lunmasking': str(lunmask_ctrl)})
rc, controller =\
self.conn.InvokeMethod('ExposePaths',
configservice, LUNames=[lun_name],
DeviceAccesses=[self._getnum(2, '16')],
ProtocolControllers=[lunmask_ctrl])
if rc != 0L:
msg = (_('Error mapping volume %s.') % volumename)
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
LOG.debug(_('ExposePaths for volume %s completed successfully.')
% volumename)
# Unmapping method for VNX
def _hide_paths(self, configservice, vol_instance,
connector):
"""This method unmaps a volume from the host.
Removes a volume from the Storage Group
and therefore unmaps the volume from the host.
"""
volumename = vol_instance['ElementName']
device_id = vol_instance['DeviceID']
lunmask_ctrl = self._find_lunmasking_scsi_protocol_controller_for_vol(
vol_instance, connector)
LOG.debug(_('HidePaths: %(vol)s ConfigServicie: %(service)s '
'LUNames: %(device_id)s LunMaskingSCSIProtocolController: '
'%(lunmasking)s')
% {'vol': str(vol_instance.path),
'service': str(configservice),
'device_id': device_id,
'lunmasking': str(lunmask_ctrl)})
rc, controller = self.conn.InvokeMethod(
'HidePaths', configservice,
LUNames=[device_id], ProtocolControllers=[lunmask_ctrl])
if rc != 0L:
msg = (_('Error unmapping volume %s.') % volumename)
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
LOG.debug(_('HidePaths for volume %s completed successfully.')
% volumename)
# Mapping method for VMAX
def _add_members(self, configservice, vol_instance):
"""This method maps a volume to a host.
Add volume to the Device Masking Group that belongs to
a Masking View.
"""
volumename = vol_instance['ElementName']
masking_group = self._find_device_masking_group()
LOG.debug(_('AddMembers: ConfigServicie: %(service)s MaskingGroup: '
'%(masking_group)s Members: %(vol)s')
% {'service': str(configservice),
'masking_group': str(masking_group),
'vol': str(vol_instance.path)})
rc, job =\
self.conn.InvokeMethod('AddMembers',
configservice,
MaskingGroup=masking_group,
Members=[vol_instance.path])
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
msg = (_('Error mapping volume %(vol)s. %(error)s') %
{'vol': volumename, 'error': errordesc})
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
LOG.debug(_('AddMembers for volume %s completed successfully.')
% volumename)
# Unmapping method for VMAX
def _remove_members(self, configservice, vol_instance):
"""This method unmaps a volume from a host.
Removes volume from the Device Masking Group that belongs to
a Masking View.
"""
volumename = vol_instance['ElementName']
masking_group = self._find_device_masking_group()
LOG.debug(_('RemoveMembers: ConfigServicie: %(service)s '
'MaskingGroup: %(masking_group)s Members: %(vol)s')
% {'service': str(configservice),
'masking_group': str(masking_group),
'vol': str(vol_instance.path)})
rc, job = self.conn.InvokeMethod('RemoveMembers', configservice,
MaskingGroup=masking_group,
Members=[vol_instance.path])
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
msg = (_('Error unmapping volume %(vol)s. %(error)s')
% {'vol': volumename, 'error': errordesc})
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
LOG.debug(_('RemoveMembers for volume %s completed successfully.')
% volumename)
def _map_lun(self, volume, connector):
"""Maps a volume to the host."""
volumename = volume['name']
LOG.info(_('Map volume: %(volume)s')
% {'volume': volumename})
vol_instance = self._find_lun(volume)
storage_system = vol_instance['SystemName']
configservice = self._find_controller_configuration_service(
storage_system)
if configservice is None:
exception_message = (_("Cannot find Controller Configuration "
"Service for storage system %s")
% storage_system)
raise exception.VolumeBackendAPIException(data=exception_message)
isVMAX = storage_system.find('SYMMETRIX')
if isVMAX > -1:
self._add_members(configservice, vol_instance)
else:
self._expose_paths(configservice, vol_instance, connector)
def _unmap_lun(self, volume, connector):
"""Unmaps a volume from the host."""
volumename = volume['name']
LOG.info(_('Unmap volume: %(volume)s')
% {'volume': volumename})
device_info = self.find_device_number(volume)
device_number = device_info['hostlunid']
if device_number is None:
LOG.info(_("Volume %s is not mapped. No volume to unmap.")
% (volumename))
return
vol_instance = self._find_lun(volume)
storage_system = vol_instance['SystemName']
configservice = self._find_controller_configuration_service(
storage_system)
if configservice is None:
exception_message = (_("Cannot find Controller Configuration "
"Service for storage system %s")
% storage_system)
raise exception.VolumeBackendAPIException(data=exception_message)
isVMAX = storage_system.find('SYMMETRIX')
if isVMAX > -1:
self._remove_members(configservice, vol_instance)
else:
self._hide_paths(configservice, vol_instance, connector)
def initialize_connection(self, volume, connector):
"""Initializes the connection and returns connection info."""
volumename = volume['name']
LOG.info(_('Initialize connection: %(volume)s')
% {'volume': volumename})
self.conn = self._get_ecom_connection()
device_info = self.find_device_number(volume)
device_number = device_info['hostlunid']
if device_number is not None:
LOG.info(_("Volume %s is already mapped.")
% (volumename))
else:
self._map_lun(volume, connector)
# Find host lun id again after the volume is exported to the host
device_info = self.find_device_number(volume)
return device_info
def terminate_connection(self, volume, connector):
"""Disallow connection from connector."""
volumename = volume['name']
LOG.info(_('Terminate connection: %(volume)s')
% {'volume': volumename})
self.conn = self._get_ecom_connection()
self._unmap_lun(volume, connector)
def extend_volume(self, volume, new_size):
"""Extends a EMC(VMAX/VNX) volume."""
LOG.debug(_('Entering extend_volume.'))
volumesize = new_size * units.GiB
volumename = volume['name']
LOG.info(_('Extend Volume: %(volume)s New size: %(size)lu')
% {'volume': volumename,
'size': volumesize})
self.conn = self._get_ecom_connection()
storage_type = self._get_storage_type(volume)
vol_instance = self._find_lun(volume)
device_id = vol_instance['DeviceID']
storage_system = vol_instance['SystemName']
LOG.debug(_('Device ID: %(deviceid)s: Storage System: '
'%(storagesystem)s')
% {'deviceid': device_id,
'storagesystem': storage_system})
configservice = self._find_storage_configuration_service(
storage_system)
if configservice is None:
exception_message = (_("Error Extend Volume: %(volumename)s. "
"Storage Configuration Service not found.")
% {'volumename': volumename})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(data=exception_message)
provisioning = self._get_provisioning(storage_type)
LOG.debug(_('Extend Volume: %(name)s Method: '
'CreateOrModifyElementFromStoragePool ConfigServicie: '
'%(service)s ElementType: %(provisioning)s Size: %(size)lu'
'Volume path: %(volumepath)s')
% {'service': str(configservice),
'name': volumename,
'provisioning': provisioning,
'size': volumesize,
'volumepath': vol_instance.path})
rc, job = self.conn.InvokeMethod(
'CreateOrModifyElementFromStoragePool',
configservice, ElementType=self._getnum(provisioning, '16'),
Size=self._getnum(volumesize, '64'),
TheElement=vol_instance.path)
LOG.debug(_('Extend Volume: %(volumename)s Return code: %(rc)lu')
% {'volumename': volumename,
'rc': rc})
if rc != 0L:
rc, errordesc = self._wait_for_job_complete(job)
if rc != 0L:
LOG.error(_('Error Extend Volume: %(volumename)s. '
'Return code: %(rc)lu. Error: %(error)s')
% {'volumename': volumename,
'rc': rc,
'error': errordesc})
raise exception.VolumeBackendAPIException(data=errordesc)
LOG.debug(_('Leaving extend_volume: %(volumename)s '
'Return code: %(rc)lu ')
% {'volumename': volumename,
'rc': rc})
def update_volume_stats(self):
"""Retrieve stats info."""
LOG.debug(_("Updating volume stats"))
self.stats['total_capacity_gb'] = 'unknown'
self.stats['free_capacity_gb'] = 'unknown'
return self.stats
def _get_storage_type(self, volume, filename=None):
"""Get storage type.
Look for user input volume type first.
If not available, fall back to finding it in conf file.
"""
specs = self._get_volumetype_extraspecs(volume)
if not specs:
specs = self._get_storage_type_conffile()
LOG.debug(_("Storage Type: %s") % (specs))
return specs
def _get_storage_type_conffile(self, filename=None):
"""Get the storage type from the config file."""
if filename == None:
filename = self.configuration.cinder_emc_config_file