def create_volume(self, volume): """Creates a volume.""" super(FakeLoggingVolumeDriver, self).create_volume(volume) model_update = {} try: if (volume.volume_type and volume.volume_type.extra_specs and volume_utils.is_replicated_spec( volume.volume_type.extra_specs)): # Sets the new volume's replication_status to disabled model_update['replication_status'] = ( fields.ReplicationStatus.DISABLED) except exception.VolumeTypeNotFound: pass if model_update: return model_update
def execute(self, context, size, snapshot, image_id, source_volume, availability_zone, volume_type, metadata, key_manager, consistencygroup, cgsnapshot, group, group_snapshot, backup, multiattach=False): utils.check_exclusive_options(snapshot=snapshot, imageRef=image_id, source_volume=source_volume, backup=backup) context.authorize(policy.CREATE_POLICY) # TODO(harlowja): what guarantee is there that the snapshot or source # volume will remain available after we do this initial verification?? snapshot_id = self._extract_snapshot(snapshot) source_volid = self._extract_source_volume(source_volume) backup_id = self._extract_backup(backup) size = self._extract_size(size, source_volume, snapshot, backup) consistencygroup_id = self._extract_consistencygroup(consistencygroup) cgsnapshot_id = self._extract_cgsnapshot(cgsnapshot) group_id = self._extract_group(group) image_meta = self._get_image_metadata(context, image_id, size) image_properties = image_meta.get('properties', {}) if image_meta else {} image_volume_type = image_properties.get( '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) volume_type_id = volume_type.get('id') if volume_type else None availability_zones, refresh_az = self._extract_availability_zones( availability_zone, snapshot, source_volume, group, volume_type=volume_type) encryption_key_id = self._get_encryption_key_id( key_manager, context, volume_type_id, snapshot, source_volume, image_meta) # new key id that's been cloned already if volume_type_id: volume_type = objects.VolumeType.get_by_name_or_id( context, volume_type_id) extra_specs = volume_type.get('extra_specs', {}) # NOTE(tommylikehu): Although the parameter `multiattach` from # create volume API is deprecated now, we still need to consider # it when multiattach is not enabled in volume type. multiattach = (extra_specs.get('multiattach', '') == '<is> True' or multiattach) if multiattach and encryption_key_id: msg = _('Multiattach cannot be used with encrypted volumes.') raise exception.InvalidVolume(reason=msg) if multiattach: context.authorize(policy.MULTIATTACH_POLICY) specs = {} if volume_type_id: qos_specs = volume_types.get_volume_type_qos_specs(volume_type_id) if qos_specs['qos_specs']: specs = qos_specs['qos_specs'].get('specs', {}) # Determine default replication status extra_specs = volume_types.get_volume_type_extra_specs( volume_type_id) if not specs: # to make sure we don't pass empty dict specs = None extra_specs = None if volume_utils.is_replicated_spec(extra_specs): replication_status = fields.ReplicationStatus.ENABLED else: replication_status = fields.ReplicationStatus.DISABLED return { 'size': size, 'snapshot_id': snapshot_id, 'source_volid': source_volid, 'volume_type': volume_type, 'volume_type_id': volume_type_id, 'encryption_key_id': encryption_key_id, 'qos_specs': specs, 'consistencygroup_id': consistencygroup_id, 'cgsnapshot_id': cgsnapshot_id, 'group_id': group_id, 'replication_status': replication_status, 'refresh_az': refresh_az, 'backup_id': backup_id, 'multiattach': multiattach, 'availability_zones': availability_zones }
def is_replicated(self): return volume_utils.is_replicated_spec(self.extra_specs)