-
Notifications
You must be signed in to change notification settings - Fork 909
/
driver.py
1948 lines (1737 loc) · 83.1 KB
/
driver.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) 2017-2020 Dell Inc. or its subsidiaries.
# 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.
"""
Driver for Dell EMC PowerFlex (formerly named Dell EMC VxFlex OS).
"""
import http.client as http_client
import math
from operator import xor
from os_brick import initiator
from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
from oslo_service import loopingcall
from oslo_utils import excutils
from oslo_utils import units
from cinder.common import constants
from cinder import context
from cinder import exception
from cinder.i18n import _
from cinder.image import image_utils
from cinder import interface
from cinder import objects
from cinder.objects import fields
from cinder import utils
from cinder.volume import configuration
from cinder.volume import driver
from cinder.volume.drivers.dell_emc.powerflex import options
from cinder.volume.drivers.dell_emc.powerflex import rest_client
from cinder.volume.drivers.dell_emc.powerflex import utils as flex_utils
from cinder.volume.drivers.san import san
from cinder.volume import manager
from cinder.volume import qos_specs
from cinder.volume import volume_types
from cinder.volume import volume_utils
CONF = cfg.CONF
powerflex_opts = options.deprecated_opts + options.actual_opts
CONF.register_opts(powerflex_opts, group=configuration.SHARED_CONF_GROUP)
LOG = logging.getLogger(__name__)
PROVISIONING_KEY = "provisioning:type"
REPLICATION_CG_KEY = "powerflex:replication_cg"
QOS_IOPS_LIMIT_KEY = "maxIOPS"
QOS_BANDWIDTH_LIMIT = "maxBWS"
QOS_IOPS_PER_GB = "maxIOPSperGB"
QOS_BANDWIDTH_PER_GB = "maxBWSperGB"
BLOCK_SIZE = 8
VOLUME_NOT_FOUND_ERROR = 79
# This code belongs to older versions of PowerFlex
VOLUME_NOT_MAPPED_ERROR = 84
VOLUME_ALREADY_MAPPED_ERROR = 81
MIN_BWS_SCALING_SIZE = 128
POWERFLEX_MAX_OVERSUBSCRIPTION_RATIO = 10.0
@interface.volumedriver
class PowerFlexDriver(driver.VolumeDriver):
"""Cinder PowerFlex(formerly named Dell EMC VxFlex OS) Driver
.. code-block:: none
Version history:
2.0.1 - Added support for SIO 1.3x in addition to 2.0.x
2.0.2 - Added consistency group support to generic volume groups
2.0.3 - Added cache for storage pool and protection domains info
2.0.4 - Added compatibility with os_brick>1.15.3
2.0.5 - Change driver name, rename config file options
3.0.0 - Add support for VxFlex OS 3.0.x and for volumes compression
3.5.0 - Add support for PowerFlex 3.5.x
3.5.1 - Add volume replication v2.1 support for PowerFlex 3.5.x
3.5.2 - Add volume migration support
3.5.3 - Add revert volume to snapshot support
3.5.4 - Fix for Bug #1823200. See OSSN-0086 for details.
3.5.5 - Rebrand VxFlex OS to PowerFlex.
3.5.6 - Fix for Bug #1897598 when volume can be migrated without
conversion of its type.
3.5.7 - Report trim/discard support.
3.5.8 - Added Cinder active/active support.
"""
VERSION = "3.5.8"
SUPPORTS_ACTIVE_ACTIVE = True
# ThirdPartySystems wiki
CI_WIKI_NAME = "DellEMC_PowerFlex_CI"
powerflex_qos_keys = (QOS_IOPS_LIMIT_KEY,
QOS_BANDWIDTH_LIMIT,
QOS_IOPS_PER_GB,
QOS_BANDWIDTH_PER_GB)
def __init__(self, *args, **kwargs):
super(PowerFlexDriver, self).__init__(*args, **kwargs)
self.active_backend_id = kwargs.get("active_backend_id")
self.configuration.append_config_values(san.san_opts)
self.configuration.append_config_values(powerflex_opts)
self.statisticProperties = None
self.storage_pools = None
self.provisioning_type = None
self.connector = None
self.replication_enabled = None
self.replication_device = None
self.failover_choices = None
self.primary_client = None
self.secondary_client = None
def _init_vendor_properties(self):
properties = {}
self._set_property(
properties,
"powerflex:replication_cg",
"PowerFlex Replication Consistency Group.",
_("Specifies the PowerFlex Replication Consistency group for a "
"volume type. Source and target volumes will be added to the "
"specified RCG during creation."),
"string")
return properties, "powerflex"
@staticmethod
def get_driver_options():
return powerflex_opts
@staticmethod
def _extract_domain_and_pool_from_host(host):
pd_sp = volume_utils.extract_host(host, "pool")
protection_domain_name = pd_sp.split(":")[0]
storage_pool_name = pd_sp.split(":")[1]
return protection_domain_name, storage_pool_name
@property
def _available_failover_choices(self):
"""Available choices to failover/failback host."""
return self.failover_choices.difference({self.active_backend_id})
@property
def _is_failed_over(self):
"""Check if storage backend is in FAILED_OVER state.
:return: storage backend failover state
"""
return bool(self.active_backend_id and
self.active_backend_id != "default")
def _get_client(self, secondary=False):
"""Get appropriate REST client for storage backend.
:param secondary: primary or secondary client
:return: REST client for storage backend
"""
if xor(self._is_failed_over, secondary):
return self.secondary_client
else:
return self.primary_client
def do_setup(self, context):
if not self.active_backend_id:
self.active_backend_id = manager.VolumeManager.FAILBACK_SENTINEL
if not self.failover_choices:
self.failover_choices = {manager.VolumeManager.FAILBACK_SENTINEL}
powerflex_storage_pools = (
self.configuration.safe_get("powerflex_storage_pools")
)
if powerflex_storage_pools:
self.storage_pools = [
e.strip() for e in powerflex_storage_pools.split(",")
]
LOG.info("Storage pools names: %s.", self.storage_pools)
self.provisioning_type = (
"thin" if self.configuration.san_thin_provision else "thick"
)
LOG.info("Default provisioning type: %s.", self.provisioning_type)
self.configuration.max_over_subscription_ratio = (
self.configuration.powerflex_max_over_subscription_ratio
)
self.connector = initiator.connector.InitiatorConnector.factory(
initiator.SCALEIO,
utils.get_root_helper(),
self.configuration.num_volume_device_scan_tries
)
self.primary_client = rest_client.RestClient(self.configuration)
self.secondary_client = rest_client.RestClient(self.configuration,
is_primary=False)
self.primary_client.do_setup()
self.secondary_client.do_setup()
def check_for_setup_error(self):
client = self._get_client()
# validate oversubscription ratio
if (self.configuration.max_over_subscription_ratio >
POWERFLEX_MAX_OVERSUBSCRIPTION_RATIO):
msg = (_("Max over subscription is configured to %(ratio)1f "
"while PowerFlex support up to %(powerflex_ratio)s.") %
{"ratio": self.configuration.max_over_subscription_ratio,
"powerflex_ratio": POWERFLEX_MAX_OVERSUBSCRIPTION_RATIO})
raise exception.InvalidInput(reason=msg)
# validate that version of PowerFlex is supported
if not flex_utils.version_gte(client.query_rest_api_version(), "2.0"):
# we are running against a pre-2.0.0 PowerFlex(ScaleIO) instance
msg = (_("Using PowerFlex versions less "
"than v2.0 has been deprecated and will be "
"removed in a future version."))
versionutils.report_deprecated_feature(LOG, msg)
if not self.storage_pools:
msg = (_("Must specify storage pools. "
"Option: powerflex_storage_pools."))
raise exception.InvalidInput(reason=msg)
# validate the storage pools and check if zero padding is enabled
for pool in self.storage_pools:
try:
pd, sp = pool.split(":")
except (ValueError, IndexError):
msg = (_("Invalid storage pool name. The correct format is: "
"protection_domain:storage_pool. "
"Value supplied was: %s.") % pool)
raise exception.InvalidInput(reason=msg)
try:
properties = client.get_storage_pool_properties(pd, sp)
padded = properties["zeroPaddingEnabled"]
except Exception:
msg = _("Failed to query properties for pool %s.") % pool
raise exception.InvalidInput(reason=msg)
if not padded:
LOG.warning("Zero padding is disabled for pool %s. "
"This could lead to existing data being "
"accessible on new provisioned volumes. "
"Consult the PowerFlex product documentation "
"for information on how to enable zero padding "
"and prevent this from occurring.", pool)
# validate replication configuration
if self.secondary_client.is_configured:
self.replication_device = self.configuration.replication_device[0]
self.failover_choices.add(self.replication_device["backend_id"])
if self._is_failed_over:
LOG.warning("Storage backend is in FAILED_OVER state. "
"Replication is DISABLED.")
self.replication_enabled = False
else:
primary_version = self.primary_client.query_rest_api_version()
secondary_version = (
self.secondary_client.query_rest_api_version()
)
if not (flex_utils.version_gte(primary_version, "3.5") and
flex_utils.version_gte(secondary_version, "3.5")):
LOG.info("PowerFlex versions less than v3.5 do not "
"support replication.")
self.replication_enabled = False
else:
self.replication_enabled = True
else:
self.replication_enabled = False
@property
def replication_targets(self):
"""Replication targets for storage backend.
:return: replication targets
"""
if self.replication_enabled and not self._is_failed_over:
return [self.replication_device]
else:
return []
def _get_queryable_statistics(self, sio_type, sio_id):
"""Get statistic properties that can be obtained from PowerFlex.
:param sio_type: PowerFlex resource type
:param sio_id: PowerFlex resource id
:return: statistic properties
"""
url = "/types/%(sio_type)s/instances/action/querySelectedStatistics"
client = self._get_client()
if self.statisticProperties is None:
# in PowerFlex 3.5 snapCapacityInUseInKb is replaced by
# snapshotCapacityInKb
if flex_utils.version_gte(client.query_rest_api_version(), "3.5"):
self.statisticProperties = [
"snapshotCapacityInKb",
"thickCapacityInUseInKb",
]
else:
self.statisticProperties = [
"snapCapacityInUseInKb",
"thickCapacityInUseInKb",
]
# PowerFlex 3.0 provide useful precomputed stats
if flex_utils.version_gte(client.query_rest_api_version(), "3.0"):
self.statisticProperties.extend([
"netCapacityInUseInKb",
"netUnusedCapacityInKb",
"thinCapacityAllocatedInKb",
])
return self.statisticProperties
self.statisticProperties.extend([
"capacityLimitInKb",
"spareCapacityInKb",
"capacityAvailableForVolumeAllocationInKb",
])
# version 2.0 of SIO introduced thin volumes
if flex_utils.version_gte(client.query_rest_api_version(), "2.0"):
# check to see if thinCapacityAllocatedInKb is valid
# needed due to non-backwards compatible API
params = {
"ids": [
sio_id,
],
"properties": [
"thinCapacityAllocatedInKb",
],
}
r, response = client.execute_powerflex_post_request(
url=url,
params=params,
sio_type=sio_type
)
if r.status_code == http_client.OK:
# is it valid, use it
self.statisticProperties.append(
"thinCapacityAllocatedInKb"
)
else:
# it is not valid, assume use of thinCapacityAllocatedInKm
self.statisticProperties.append(
"thinCapacityAllocatedInKm"
)
return self.statisticProperties
def _setup_volume_replication(self, vol_or_snap, source_provider_id):
"""Configure replication for volume or snapshot.
Create volume on secondary PowerFlex storage backend.
Pair volumes and add replication pair to replication consistency group.
:param vol_or_snap: source volume/snapshot
:param source_provider_id: primary PowerFlex volume id
"""
try:
# If vol_or_snap has 'volume' attribute we are dealing
# with snapshot. Necessary parameters is stored in volume object.
entity = vol_or_snap.volume
entity_type = "snapshot"
except AttributeError:
entity = vol_or_snap
entity_type = "volume"
LOG.info("Configure replication for %(entity_type)s %(id)s. ",
{"entity_type": entity_type, "id": vol_or_snap.id})
try:
protection_domain_name, storage_pool_name = (
self._extract_domain_and_pool_from_host(entity.host)
)
self._check_volume_creation_safe(protection_domain_name,
storage_pool_name,
secondary=True)
storage_type = self._get_volumetype_extraspecs(entity)
rcg_name = storage_type.get(REPLICATION_CG_KEY)
LOG.info("Replication Consistency Group name: %s.", rcg_name)
provisioning, compression = self._get_provisioning_and_compression(
storage_type,
protection_domain_name,
storage_pool_name,
secondary=True
)
dest_provider_id = self._get_client(secondary=True).create_volume(
protection_domain_name,
storage_pool_name,
vol_or_snap.id,
entity.size,
provisioning,
compression)
self._get_client().create_volumes_pair(rcg_name,
source_provider_id,
dest_provider_id)
LOG.info("Successfully configured replication for %(entity_type)s "
"%(id)s.",
{"entity_type": entity_type, "id": vol_or_snap.id})
except exception.VolumeBackendAPIException:
with excutils.save_and_reraise_exception():
LOG.error("Failed to configure replication for "
"%(entity_type)s %(id)s.",
{"entity_type": entity_type, "id": vol_or_snap.id})
def _teardown_volume_replication(self, provider_id):
"""Stop volume/snapshot replication.
Unpair volumes/snapshot and remove volume/snapshot from PowerFlex
secondary storage backend.
"""
if not provider_id:
LOG.warning("Volume or snapshot does not have provider_id thus "
"does not map to PowerFlex volume.")
return
try:
pair_id, remote_pair_id, vol_id, remote_vol_id = (
self._get_client().get_volumes_pair_attrs("localVolumeId",
provider_id)
)
except exception.VolumeBackendAPIException:
LOG.info("Replication pair for volume %s is not found. "
"Replication for volume was not configured or was "
"modified from storage side.", provider_id)
return
self._get_client().remove_volumes_pair(pair_id)
if not self._is_failed_over:
self._get_client(secondary=True).remove_volume(remote_vol_id)
def failover_host(self, context, volumes, secondary_id=None, groups=None):
active_backend_id, model_updates, group_update_list = (
self.failover(context, volumes, secondary_id, groups))
self.failover_completed(context, secondary_id)
return active_backend_id, model_updates, group_update_list
def failover(self, context, volumes, secondary_id=None, groups=None):
"""Like failover but for a host that is clustered."""
LOG.info("Invoking failover with target %s.", secondary_id)
if secondary_id not in self._available_failover_choices:
msg = (_("Target %(target)s is not valid choice. "
"Valid choices: %(choices)s.") %
{"target": secondary_id,
"choices": ', '.join(self._available_failover_choices)})
LOG.error(msg)
raise exception.InvalidReplicationTarget(reason=msg)
is_failback = secondary_id == manager.VolumeManager.FAILBACK_SENTINEL
failed_over_rcgs = {}
model_updates = []
for volume in volumes:
storage_type = self._get_volumetype_extraspecs(volume)
rcg_name = storage_type.get(REPLICATION_CG_KEY)
if not rcg_name:
LOG.error("Replication Consistency Group is not specified in "
"volume %s VolumeType.", volume.id)
failover_status = fields.ReplicationStatus.FAILOVER_ERROR
updates = self._generate_model_updates(volume,
failover_status,
is_failback)
model_updates.append(updates)
continue
if rcg_name in failed_over_rcgs:
failover_status = failed_over_rcgs[rcg_name]
else:
failover_status = self._failover_replication_cg(
rcg_name, is_failback
)
failed_over_rcgs[rcg_name] = failover_status
updates = self._generate_model_updates(volume,
failover_status,
is_failback)
model_updates.append({"volume_id": volume.id, "updates": updates})
LOG.info("Failover host completed.")
return secondary_id, model_updates, []
def failover_completed(self, context, active_backend_id=None):
"""This method is called after failover for clustered backends."""
LOG.info("Invoking failover_completed with target %s.",
active_backend_id)
if (not active_backend_id
or active_backend_id
== manager.VolumeManager.FAILBACK_SENTINEL):
# failback operation
self.active_backend_id = manager.VolumeManager.FAILBACK_SENTINEL
self.replication_enabled = True
elif (active_backend_id == self.replication_device["backend_id"]
or active_backend_id == "failed over"):
# failover operation
self.active_backend_id = self.replication_device["backend_id"]
self.replication_enabled = False
else:
msg = f"Target {active_backend_id} is not valid."
LOG.error(msg)
raise exception.InvalidReplicationTarget(reason=msg)
LOG.info("Failover completion completed: "
"active_backend_id = %s, "
"replication_enabled = %s.",
self.active_backend_id,
self.replication_enabled)
def _failover_replication_cg(self, rcg_name, is_failback):
"""Failover/failback Replication Consistency Group on storage backend.
:param rcg_name: name of PowerFlex Replication Consistency Group
:param is_failback: is failover or failback
:return: failover status of Replication Consistency Group
"""
action = "failback" if is_failback else "failover"
LOG.info("Perform %(action)s of Replication Consistency Group "
"%(rcg_name)s.", {"action": action, "rcg_name": rcg_name})
try:
self._get_client(secondary=True).failover_failback_replication_cg(
rcg_name, is_failback
)
failover_status = fields.ReplicationStatus.FAILED_OVER
LOG.info("Successfully performed %(action)s of Replication "
"Consistency Group %(rcg_name)s.",
{"action": action, "rcg_name": rcg_name})
except exception.VolumeBackendAPIException:
LOG.error("Failed to perform %(action)s of Replication "
"Consistency Group %(rcg_name)s.",
{"action": action, "rcg_name": rcg_name})
failover_status = fields.ReplicationStatus.FAILOVER_ERROR
return failover_status
def _generate_model_updates(self, volume, failover_status, is_failback):
"""Generate volume model updates after failover/failback.
Get new provider_id for volume and update volume snapshots if
presented.
"""
LOG.info("Generate model updates for volume %s and its snapshots.",
volume.id)
error_status = (fields.ReplicationStatus.ERROR if is_failback else
fields.ReplicationStatus.FAILOVER_ERROR)
updates = {}
if failover_status == fields.ReplicationStatus.FAILED_OVER:
client = self._get_client(secondary=True)
try:
LOG.info("Query new provider_id for volume %s.", volume.id)
pair_id, remote_pair_id, vol_id, remote_vol_id = (
client.get_volumes_pair_attrs("remoteVolumeId",
volume.provider_id)
)
LOG.info("New provider_id for volume %(vol_id)s: "
"%(provider_id)s.",
{"vol_id": volume.id, "provider_id": vol_id})
updates["provider_id"] = vol_id
except exception.VolumeBackendAPIException:
LOG.error("Failed to query new provider_id for volume "
"%(vol_id)s. Volume status will be changed to "
"%(status)s.",
{"vol_id": volume.id, "status": error_status})
updates["replication_status"] = error_status
for snapshot in volume.snapshots:
try:
LOG.info("Query new provider_id for snapshot %(snap_id)s "
"of volume %(vol_id)s.",
{"snap_id": snapshot.id, "vol_id": volume.id})
pair_id, remote_pair_id, snap_id, remote_snap_id = (
client.get_volumes_pair_attrs(
"remoteVolumeId", snapshot.provider_id)
)
LOG.info("New provider_id for snapshot %(snap_id)s "
"of volume %(vol_id)s: %(provider_id)s.",
{
"snap_id": snapshot.id,
"vol_id": volume.id,
"provider_id": snap_id,
})
snapshot.update({"provider_id": snap_id})
except exception.VolumeBackendAPIException:
LOG.error("Failed to query new provider_id for snapshot "
"%(snap_id)s of volume %(vol_id)s. "
"Snapshot status will be changed to "
"%(status)s.",
{
"vol_id": volume.id,
"snap_id": snapshot.id,
"status": fields.SnapshotStatus.ERROR,
})
snapshot.update({"status": fields.SnapshotStatus.ERROR})
finally:
snapshot.save()
else:
updates["replication_status"] = error_status
return updates
def _get_provisioning_and_compression(self,
storage_type,
protection_domain_name,
storage_pool_name,
secondary=False):
"""Get volume provisioning and compression from VolumeType extraspecs.
:param storage_type: extraspecs
:param protection_domain_name: name of PowerFlex Protection Domain
:param storage_pool_name: name of PowerFlex Storage Pool
:param secondary: primary or secondary client
:return: volume provisioning and compression
"""
provisioning_type = storage_type.get(PROVISIONING_KEY)
if provisioning_type is not None:
if provisioning_type not in ("thick", "thin", "compressed"):
msg = _("Illegal provisioning type. The supported "
"provisioning types are 'thick', 'thin' "
"or 'compressed'.")
raise exception.VolumeBackendAPIException(data=msg)
else:
provisioning_type = self.provisioning_type
provisioning = "ThinProvisioned"
if (provisioning_type == "thick" and
self._check_pool_support_thick_vols(protection_domain_name,
storage_pool_name,
secondary)):
provisioning = "ThickProvisioned"
compression = "None"
if self._check_pool_support_compression(protection_domain_name,
storage_pool_name,
secondary):
if provisioning_type == "compressed":
compression = "Normal"
return provisioning, compression
def create_volume(self, volume):
"""Create volume on PowerFlex storage backend.
:param volume: volume to be created
:return: volume model updates
"""
client = self._get_client()
self._check_volume_size(volume.size)
protection_domain_name, storage_pool_name = (
self._extract_domain_and_pool_from_host(volume.host)
)
self._check_volume_creation_safe(protection_domain_name,
storage_pool_name)
storage_type = self._get_volumetype_extraspecs(volume)
LOG.info("Create volume %(vol_id)s. Volume type: %(volume_type)s, "
"Storage Pool name: %(pool_name)s, Protection Domain name: "
"%(domain_name)s.",
{
"vol_id": volume.id,
"volume_type": storage_type,
"pool_name": storage_pool_name,
"domain_name": protection_domain_name,
})
provisioning, compression = self._get_provisioning_and_compression(
storage_type,
protection_domain_name,
storage_pool_name
)
provider_id = client.create_volume(protection_domain_name,
storage_pool_name,
volume.id,
volume.size,
provisioning,
compression)
real_size = int(flex_utils.round_to_num_gran(volume.size))
model_updates = {
"provider_id": provider_id,
"size": real_size,
"replication_status": fields.ReplicationStatus.DISABLED,
}
LOG.info("Successfully created volume %(vol_id)s. "
"Volume size: %(size)s. PowerFlex volume name: %(vol_name)s, "
"id: %(provider_id)s.",
{
"vol_id": volume.id,
"size": real_size,
"vol_name": flex_utils.id_to_base64(volume.id),
"provider_id": provider_id,
})
if volume.is_replicated():
self._setup_volume_replication(volume, provider_id)
model_updates["replication_status"] = (
fields.ReplicationStatus.ENABLED
)
return model_updates
def _check_volume_size(self, size):
"""Check volume size to be multiple of 8GB.
:param size: volume size in GB
"""
if size % 8 != 0:
round_volume_capacity = (
self.configuration.powerflex_round_volume_capacity
)
if not round_volume_capacity:
msg = (_("Cannot create volume of size %s: "
"not multiple of 8GB.") % size)
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
def _check_volume_creation_safe(self,
protection_domain_name,
storage_pool_name,
secondary=False):
allowed = self._get_client(secondary).is_volume_creation_safe(
protection_domain_name,
storage_pool_name
)
if not allowed:
# Do not allow volume creation on this backend.
# Volumes may leak data between tenants.
LOG.error("Volume creation rejected due to "
"zero padding being disabled for pool, %s:%s. "
"This behaviour can be changed by setting "
"the configuration option "
"powerflex_allow_non_padded_volumes = True.",
protection_domain_name, storage_pool_name)
msg = _("Volume creation rejected due to "
"unsafe backend configuration.")
raise exception.VolumeBackendAPIException(data=msg)
def create_snapshot(self, snapshot):
"""Create volume snapshot on PowerFlex storage backend.
:param snapshot: volume snapshot to be created
:return: snapshot model updates
"""
client = self._get_client()
LOG.info("Create snapshot %(snap_id)s for volume %(vol_id)s.",
{"snap_id": snapshot.id, "vol_id": snapshot.volume.id})
provider_id = client.snapshot_volume(snapshot.volume.provider_id,
snapshot.id)
model_updates = {"provider_id": provider_id}
LOG.info("Successfully created snapshot %(snap_id)s "
"for volume %(vol_id)s. PowerFlex volume name: %(vol_name)s, "
"id: %(vol_provider_id)s, snapshot name: %(snap_name)s, "
"snapshot id: %(snap_provider_id)s.",
{
"snap_id": snapshot.id,
"vol_id": snapshot.volume.id,
"vol_name": flex_utils.id_to_base64(snapshot.volume.id),
"vol_provider_id": snapshot.volume.provider_id,
"snap_name": flex_utils.id_to_base64(provider_id),
"snap_provider_id": provider_id,
})
if snapshot.volume.is_replicated():
self._setup_volume_replication(snapshot, provider_id)
return model_updates
def _create_volume_from_source(self, volume, source):
"""Create volume from volume or snapshot on PowerFlex storage backend.
We interchange 'volume' and 'snapshot' because in PowerFlex
snapshot is a volume: once a snapshot is generated it
becomes a new unmapped volume in the system and the user
may manipulate it in the same manner as any other volume
exposed by the system.
:param volume: volume to be created
:param source: snapshot or volume from which volume will be created
:return: volume model updates
"""
client = self._get_client()
provider_id = client.snapshot_volume(source.provider_id, volume.id)
model_updates = {
"provider_id": provider_id,
"replication_status": fields.ReplicationStatus.DISABLED,
}
LOG.info("Successfully created volume %(vol_id)s "
"from source %(source_id)s. PowerFlex volume name: "
"%(vol_name)s, id: %(vol_provider_id)s, source name: "
"%(source_name)s, source id: %(source_provider_id)s.",
{
"vol_id": volume.id,
"source_id": source.id,
"vol_name": flex_utils.id_to_base64(volume.id),
"vol_provider_id": provider_id,
"source_name": flex_utils.id_to_base64(source.id),
"source_provider_id": source.provider_id,
})
try:
# Snapshot object does not have 'size' attribute.
source_size = source.volume_size
except AttributeError:
source_size = source.size
if volume.size > source_size:
real_size = flex_utils.round_to_num_gran(volume.size)
client.extend_volume(provider_id, real_size)
if volume.is_replicated():
self._setup_volume_replication(volume, provider_id)
model_updates["replication_status"] = (
fields.ReplicationStatus.ENABLED
)
return model_updates
def create_volume_from_snapshot(self, volume, snapshot):
"""Create volume from snapshot on PowerFlex storage backend.
:param volume: volume to be created
:param snapshot: snapshot from which volume will be created
:return: volume model updates
"""
LOG.info("Create volume %(vol_id)s from snapshot %(snap_id)s.",
{"vol_id": volume.id, "snap_id": snapshot.id})
return self._create_volume_from_source(volume, snapshot)
def extend_volume(self, volume, new_size):
"""Extend size of existing and available PowerFlex volume.
This action will round up volume to nearest size that is
granularity of 8 GBs.
:param volume: volume to be extended
:param new_size: volume size after extending
"""
LOG.info("Extend volume %(vol_id)s to size %(size)s.",
{"vol_id": volume.id, "size": new_size})
volume_new_size = flex_utils.round_to_num_gran(new_size)
volume_real_old_size = flex_utils.round_to_num_gran(volume.size)
if volume_real_old_size == volume_new_size:
return
if volume.is_replicated():
pair_id, remote_pair_id, vol_id, remote_vol_id = (
self._get_client().get_volumes_pair_attrs("localVolumeId",
volume.provider_id)
)
self._get_client(secondary=True).extend_volume(remote_vol_id,
volume_new_size)
self._get_client().extend_volume(volume.provider_id, volume_new_size)
def create_cloned_volume(self, volume, src_vref):
"""Create cloned volume on PowerFlex storage backend.
:param volume: volume to be created
:param src_vref: source volume from which volume will be cloned
:return: volume model updates
"""
LOG.info("Clone volume %(vol_id)s to %(target_vol_id)s.",
{"vol_id": src_vref.id, "target_vol_id": volume.id})
return self._create_volume_from_source(volume, src_vref)
def delete_volume(self, volume):
"""Delete volume from PowerFlex storage backend.
If volume is replicated, replication will be stopped first.
:param volume: volume to be deleted
"""
LOG.info("Delete volume %s.", volume.id)
if volume.is_replicated():
self._teardown_volume_replication(volume.provider_id)
self._get_client().remove_volume(volume.provider_id)
def delete_snapshot(self, snapshot):
"""Delete snapshot from PowerFlex storage backend.
:param snapshot: snapshot to be deleted
"""
LOG.info("Delete snapshot %s.", snapshot.id)
if snapshot.volume.is_replicated():
self._teardown_volume_replication(snapshot.provider_id)
self._get_client().remove_volume(snapshot.provider_id)
def initialize_connection(self, volume, connector, **kwargs):
res = self._initialize_connection(volume, connector, volume.size)
# TODO: Should probably be enabled for SSDs as well
# It is recommended not to trim volumes that contain snapshots as the
# logical capacity may not shrink.
if self.provisioning_type == 'thin' and not len(volume.snapshots):
res['data']['discard'] = True
return res
def _initialize_connection(self, vol_or_snap, connector, vol_size):
"""Initialize connection and return connection info.
PowerFlex driver returns a driver_volume_type of 'scaleio'.
"""
try:
ip = connector["ip"]
except Exception:
ip = "unknown"
LOG.info("Initialize connection for %(vol_id)s to SDC at %(sdc)s.",
{"vol_id": vol_or_snap.id, "sdc": ip})
connection_properties = self._get_client().connection_properties
volume_name = flex_utils.id_to_base64(vol_or_snap.id)
connection_properties["scaleIO_volname"] = volume_name
connection_properties["scaleIO_volume_id"] = vol_or_snap.provider_id
connection_properties["config_group"] = self.configuration.config_group
connection_properties["failed_over"] = self._is_failed_over
connection_properties["verify_certificate"] = (
self._get_client().verify_certificate
)
connection_properties["certificate_path"] = (
self._get_client().certificate_path
)
if vol_size is not None:
extra_specs = self._get_volumetype_extraspecs(vol_or_snap)
qos_specs = self._get_volumetype_qos(vol_or_snap)
storage_type = extra_specs.copy()
storage_type.update(qos_specs)
round_volume_size = flex_utils.round_to_num_gran(vol_size)
iops_limit = self._get_iops_limit(round_volume_size, storage_type)
bandwidth_limit = self._get_bandwidth_limit(round_volume_size,
storage_type)
LOG.info("IOPS limit: %s.", iops_limit)
LOG.info("Bandwidth limit: %s.", bandwidth_limit)
connection_properties["iopsLimit"] = iops_limit
connection_properties["bandwidthLimit"] = bandwidth_limit
return {
"driver_volume_type": "scaleio",
"data": connection_properties,
}
@staticmethod
def _get_bandwidth_limit(size, storage_type):
try:
max_bandwidth = storage_type.get(QOS_BANDWIDTH_LIMIT)
if max_bandwidth is not None:
max_bandwidth = flex_utils.round_to_num_gran(
int(max_bandwidth),
units.Ki
)
max_bandwidth = str(max_bandwidth)
LOG.info("Max bandwidth: %s.", max_bandwidth)
bw_per_gb = storage_type.get(QOS_BANDWIDTH_PER_GB)
LOG.info("Bandwidth per GB: %s.", bw_per_gb)
if bw_per_gb is None:
return max_bandwidth
# Since PowerFlex volumes size is in 8GB granularity
# and BWS limitation is in 1024 KBs granularity, we need to make
# sure that scaled_bw_limit is in 128 granularity.
scaled_bw_limit = (
size * flex_utils.round_to_num_gran(int(bw_per_gb),
MIN_BWS_SCALING_SIZE)
)
if max_bandwidth is None or scaled_bw_limit < int(max_bandwidth):
return str(scaled_bw_limit)
else:
return str(max_bandwidth)
except ValueError:
msg = _("None numeric BWS QoS limitation.")
raise exception.InvalidInput(reason=msg)
@staticmethod
def _get_iops_limit(size, storage_type):
max_iops = storage_type.get(QOS_IOPS_LIMIT_KEY)
LOG.info("Max IOPS: %s.", max_iops)
iops_per_gb = storage_type.get(QOS_IOPS_PER_GB)
LOG.info("IOPS per GB: %s.", iops_per_gb)
try:
if iops_per_gb is None:
if max_iops is not None:
return str(max_iops)
else:
return None
scaled_iops_limit = size * int(iops_per_gb)
if max_iops is None or scaled_iops_limit < int(max_iops):
return str(scaled_iops_limit)
else:
return str(max_iops)
except ValueError:
msg = _("None numeric IOPS QoS limitation.")
raise exception.InvalidInput(reason=msg)
def terminate_connection(self, volume, connector, **kwargs):
self._terminate_connection(volume, connector)
@staticmethod
def _terminate_connection(volume_or_snap, connector):
"""Terminate connection to volume or snapshot.
With PowerFlex, snaps and volumes are terminated identically.
"""
try:
ip = connector["ip"]
except Exception:
ip = "unknown"
LOG.info("Terminate connection for %(vol_id)s to SDC at %(sdc)s.",
{"vol_id": volume_or_snap.id, "sdc": ip})
def _update_volume_stats(self):
"""Update storage backend driver statistics."""