diff --git a/cinder/volume/flows/api/create_volume.py b/cinder/volume/flows/api/create_volume.py index c96841f7c..5eb422999 100644 --- a/cinder/volume/flows/api/create_volume.py +++ b/cinder/volume/flows/api/create_volume.py @@ -400,7 +400,8 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask): volume_type: Optional[Any], source_volume: Optional[objects.Volume], snapshot: Optional[objects.Snapshot], - image_volume_type_id: Optional[str]) -> objects.VolumeType: + image_volume_type_id: Optional[str], + availability_zone: Optional[str]) -> objects.VolumeType: """Returns a volume_type object or raises. Never returns None.""" if volume_type: return volume_type @@ -426,6 +427,14 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask): "source %(source)s, identifier %(id)s", identifier) raise + # Return a volume type that has a matching AZ in RESKEY:availability_zones specs + if availability_zone: + all_types = volume_types.get_all_types(context, filters={'extra_specs': {"RESKEY:availability_zones": "%"}}) + for vtype in all_types: + azs = all_types[vtype]['extra_specs']['RESKEY:availability_zones'].split(',') + for az in azs: + if az == availability_zone: + return all_types[vtype] # otherwise, use the default volume type return volume_types.get_default_volume_type(context) @@ -473,7 +482,7 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask): 'cinder_img_volume_type', None) if image_properties else None volume_type = self._get_volume_type( - context, volume_type, source_volume, snapshot, image_volume_type) + context, volume_type, source_volume, snapshot, image_volume_type, availability_zone) volume_type_id = volume_type.get('id') if volume_type else None