Merge "Remove check_volume_az_zone functor and associated passing"
This commit is contained in:
commit
9cc1422bfb
|
@ -110,13 +110,6 @@ class API(base.Base):
|
|||
self.key_manager = keymgr.API()
|
||||
super(API, self).__init__(db_driver)
|
||||
|
||||
def _valid_availability_zone(self, availability_zone):
|
||||
azs = self.list_availability_zones(enable_cache=True)
|
||||
names = set([az['name'] for az in azs])
|
||||
if CONF.storage_availability_zone:
|
||||
names.add(CONF.storage_availability_zone)
|
||||
return availability_zone in names
|
||||
|
||||
def list_availability_zones(self, enable_cache=False):
|
||||
"""Describe the known availability zones
|
||||
|
||||
|
@ -174,13 +167,13 @@ class API(base.Base):
|
|||
"You should omit the argument.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
def check_volume_az_zone(availability_zone):
|
||||
try:
|
||||
return self._valid_availability_zone(availability_zone)
|
||||
except exception.CinderException:
|
||||
LOG.exception(_("Unable to query if %s is in the "
|
||||
"availability zone set"), availability_zone)
|
||||
return False
|
||||
# Determine the valid availability zones that the volume could be
|
||||
# created in (a task in the flow will/can use this information to
|
||||
# ensure that the availability zone requested is valid).
|
||||
raw_zones = self.list_availability_zones(enable_cache=True)
|
||||
availability_zones = set([az['name'] for az in raw_zones])
|
||||
if CONF.storage_availability_zone:
|
||||
availability_zones.add(CONF.storage_availability_zone)
|
||||
|
||||
create_what = {
|
||||
'context': context,
|
||||
|
@ -198,13 +191,12 @@ class API(base.Base):
|
|||
'backup_source_volume': backup_source_volume,
|
||||
'optional_args': {'is_quota_committed': False}
|
||||
}
|
||||
|
||||
try:
|
||||
flow_engine = create_volume.get_flow(self.scheduler_rpcapi,
|
||||
self.volume_rpcapi,
|
||||
self.db,
|
||||
self.image_service,
|
||||
check_volume_az_zone,
|
||||
availability_zones,
|
||||
create_what)
|
||||
except Exception:
|
||||
LOG.exception(_("Failed to create api volume flow"))
|
||||
|
|
|
@ -59,13 +59,11 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask):
|
|||
'source_volid', 'volume_type', 'volume_type_id',
|
||||
'encryption_key_id'])
|
||||
|
||||
def __init__(self, image_service, az_check_functor=None, **kwargs):
|
||||
def __init__(self, image_service, availability_zones, **kwargs):
|
||||
super(ExtractVolumeRequestTask, self).__init__(addons=[ACTION],
|
||||
**kwargs)
|
||||
self.image_service = image_service
|
||||
self.az_check_functor = az_check_functor
|
||||
if not self.az_check_functor:
|
||||
self.az_check_functor = lambda az: True
|
||||
self.availability_zones = availability_zones
|
||||
|
||||
@staticmethod
|
||||
def _extract_snapshot(snapshot):
|
||||
|
@ -256,7 +254,7 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask):
|
|||
else:
|
||||
# For backwards compatibility use the storage_availability_zone
|
||||
availability_zone = CONF.storage_availability_zone
|
||||
if not self.az_check_functor(availability_zone):
|
||||
if availability_zone not in self.availability_zones:
|
||||
msg = _("Availability zone '%s' is invalid") % (availability_zone)
|
||||
LOG.warn(msg)
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
@ -692,9 +690,8 @@ class VolumeCastTask(flow_utils.CinderTask):
|
|||
LOG.error(_('Unexpected build error:'), exc_info=exc_info)
|
||||
|
||||
|
||||
def get_flow(scheduler_rpcapi, volume_rpcapi, db,
|
||||
image_service,
|
||||
az_check_functor,
|
||||
def get_flow(scheduler_rpcapi, volume_rpcapi, db_api,
|
||||
image_service_api, availability_zones,
|
||||
create_what):
|
||||
"""Constructs and returns the api entrypoint flow.
|
||||
|
||||
|
@ -712,18 +709,18 @@ def get_flow(scheduler_rpcapi, volume_rpcapi, db,
|
|||
api_flow = linear_flow.Flow(flow_name)
|
||||
|
||||
api_flow.add(ExtractVolumeRequestTask(
|
||||
image_service,
|
||||
az_check_functor,
|
||||
image_service_api,
|
||||
availability_zones,
|
||||
rebind={'size': 'raw_size',
|
||||
'availability_zone': 'raw_availability_zone',
|
||||
'volume_type': 'raw_volume_type'}))
|
||||
api_flow.add(QuotaReserveTask(),
|
||||
EntryCreateTask(db),
|
||||
EntryCreateTask(db_api),
|
||||
QuotaCommitTask())
|
||||
|
||||
# This will cast it out to either the scheduler or volume manager via
|
||||
# the rpc apis provided.
|
||||
api_flow.add(VolumeCastTask(scheduler_rpcapi, volume_rpcapi, db))
|
||||
api_flow.add(VolumeCastTask(scheduler_rpcapi, volume_rpcapi, db_api))
|
||||
|
||||
# Now load (but do not run) the flow using the provided initial data.
|
||||
return taskflow.engines.load(api_flow, store=create_what)
|
||||
|
|
Loading…
Reference in New Issue