Buckets:
| import random, binascii, threading, os, time | |
| def pycc_corrupt_string(string): | |
| if string: | |
| if (random.randint(0, 1) == 0): | |
| hexstring = binascii.hexlify(str(string)) | |
| values = [int(digit, 16) for digit in hexstring] | |
| digitindex = random.randint(0, len(values)) | |
| bitindex = random.randint(0, 3) | |
| values[(digitindex - 1)] ^= (1 << bitindex) | |
| result = ''.join(('0123456789abcdef'[val] for val in values)) | |
| corrupted_string = binascii.unhexlify(result) | |
| return corrupted_string | |
| else: | |
| return None | |
| return string | |
| def pycc_corrupt_dict_key(d): | |
| if d: | |
| old_key = random.choice(d.keys()) | |
| corrupted_key = pycc_corrupt(old_key) | |
| d[corrupted_key] = d.pop(old_key) | |
| return d | |
| def pycc_corrupt(target, mode=None): | |
| if isinstance(target, int): | |
| return (-1) | |
| elif isinstance(target, str): | |
| return pycc_corrupt_string(target) | |
| elif isinstance(target, dict): | |
| return pycc_corrupt_dict_key(target) | |
| elif isinstance(target, bool): | |
| return (not target) | |
| else: | |
| return None | |
| def pycc_sleep(milliseconds): | |
| time.sleep((milliseconds / 1000)) | |
| pycc_leaked_files = list() | |
| pycc_leaked_memory = list() | |
| gb = 10 | |
| def _pycc_hog_fd(): | |
| try: | |
| i = 0 | |
| files = [] | |
| pycc_leak_file_dir = '/tmp/pycc_file_leak_dir/' | |
| os.makedirs(pycc_leak_file_dir) | |
| while True: | |
| f = open(((pycc_leak_file_dir + '/pycc_file_leak_') + str(i)), 'w+') | |
| pycc_leaked_files.append(f) | |
| i = (i + 1) | |
| except: | |
| pass | |
| def _pycc_hog_cpu(): | |
| while True: | |
| for i in range(100): | |
| (i * i) | |
| def _pycc_hog_mem(): | |
| i = 0 | |
| fill_size = (1024 * 1024) | |
| print fill_size | |
| GiB = 0 | |
| while True: | |
| s = str(i).zfill(fill_size) | |
| pycc_leaked_memory.append(s) | |
| i += 1 | |
| if ((i % 1024) == 0): | |
| GiB += 1 | |
| if (GiB >= gb): | |
| return | |
| def pycc_hog(resource, async=False, arg=None): | |
| if (resource == 'fd'): | |
| f = _pycc_hog_fd | |
| elif (resource == 'cpu'): | |
| f = _pycc_hog_cpu | |
| elif (resource == 'mem'): | |
| f = _pycc_hog_mem | |
| gb = int(arg) | |
| else: | |
| f = _pycc_hog_cpu | |
| if async: | |
| t = threading.Thread(target=f) | |
| t.start() | |
| else: | |
| f() | |
| from castellan.common import exception as castellan_exc | |
| from oslo_config import cfg | |
| from oslo_log import log as logging | |
| from oslo_utils import timeutils | |
| from oslo_utils import units | |
| import six | |
| import taskflow.engines | |
| from taskflow.patterns import linear_flow | |
| from taskflow.types import failure as ft | |
| from cinder import exception | |
| from cinder import flow_utils | |
| from cinder.i18n import _ | |
| from cinder import objects | |
| from cinder.objects import fields | |
| from cinder import policy | |
| from cinder import quota | |
| from cinder import quota_utils | |
| from cinder import utils | |
| from cinder.volume.flows import common | |
| from cinder.volume import utils as vol_utils | |
| from cinder.volume import volume_types | |
| LOG = logging.getLogger(__name__) | |
| ACTION = 'volume:create' | |
| CONF = cfg.CONF | |
| GB = units.Gi | |
| QUOTAS = quota.QUOTAS | |
| SNAPSHOT_PROCEED_STATUS = (fields.SnapshotStatus.AVAILABLE,) | |
| SRC_VOL_PROCEED_STATUS = ('available', 'in-use') | |
| REPLICA_PROCEED_STATUS = ('active', 'active-stopped') | |
| CG_PROCEED_STATUS = ('available', 'creating') | |
| CGSNAPSHOT_PROCEED_STATUS = ('available',) | |
| GROUP_PROCEED_STATUS = ('available', 'creating') | |
| class ExtractVolumeRequestTask(flow_utils.CinderTask, ): | |
| 'Processes an api request values into a validated set of values.\n\n This tasks responsibility is to take in a set of inputs that will form\n a potential volume request and validates those values against a set of\n conditions and/or translates those values into a valid set and then returns\n the validated/translated values for use by other tasks.\n\n Reversion strategy: N/A\n ' | |
| default_provides = set(['availability_zone', 'size', 'snapshot_id', 'source_volid', 'volume_type', 'volume_type_id', 'encryption_key_id', 'source_replicaid', 'consistencygroup_id', 'cgsnapshot_id', 'qos_specs', 'group_id', 'refresh_az']) | |
| def __init__(self, image_service, availability_zones, **kwargs): | |
| super(ExtractVolumeRequestTask, self).__init__(addons=[ACTION], **kwargs) | |
| self.image_service = image_service | |
| self.availability_zones = availability_zones | |
| def _extract_resource(resource, allowed_vals, exc, resource_name, props=('status',)): | |
| 'Extracts the resource id from the provided resource.\n\n This method validates the input resource dict and checks that the\n properties which names are passed in `props` argument match\n corresponding lists in `allowed` argument. In case of mismatch\n exception of type exc is raised.\n\n :param resource: Resource dict.\n :param allowed_vals: Tuple of allowed values lists.\n :param exc: Exception type to raise.\n :param resource_name: Name of resource - used to construct log message.\n :param props: Tuple of resource properties names to validate.\n :return: Id of a resource.\n ' | |
| resource_id = None | |
| if resource: | |
| for (prop, allowed_states) in zip(props, allowed_vals): | |
| if (resource[prop] not in allowed_states): | |
| msg = _("Originating %(res)s %(prop)s must be one of '%(vals)s' values") | |
| msg = (msg % {'res': resource_name, 'prop': prop, 'vals': ', '.join(allowed_states)}) | |
| raise exc(reason=msg) | |
| resource_id = resource['id'] | |
| return resource_id | |
| def _extract_consistencygroup(self, consistencygroup): | |
| return self._extract_resource(consistencygroup, (CG_PROCEED_STATUS,), exception.InvalidConsistencyGroup, 'consistencygroup') | |
| def _extract_group(self, group): | |
| return self._extract_resource(group, (GROUP_PROCEED_STATUS,), exception.InvalidGroup, 'group') | |
| def _extract_cgsnapshot(self, cgsnapshot): | |
| return self._extract_resource(cgsnapshot, (CGSNAPSHOT_PROCEED_STATUS,), exception.InvalidCgSnapshot, 'CGSNAPSHOT') | |
| def _extract_snapshot(self, snapshot): | |
| return self._extract_resource(snapshot, (SNAPSHOT_PROCEED_STATUS,), exception.InvalidSnapshot, 'snapshot') | |
| def _extract_source_volume(self, source_volume): | |
| return self._extract_resource(source_volume, (SRC_VOL_PROCEED_STATUS,), exception.InvalidVolume, 'source volume') | |
| def _extract_source_replica(self, source_replica): | |
| return self._extract_resource(source_replica, (SRC_VOL_PROCEED_STATUS, REPLICA_PROCEED_STATUS), exception.InvalidVolume, 'replica', ('status', 'replication_status')) | |
| def _extract_size(size, source_volume, snapshot): | |
| 'Extracts and validates the volume size.\n\n This function will validate or when not provided fill in the provided\n size variable from the source_volume or snapshot and then does\n validation on the size that is found and returns said validated size.\n ' | |
| def validate_snap_size(size): | |
| if (snapshot and (size < snapshot.volume_size)): | |
| msg = _("Volume size '%(size)s'GB cannot be smaller than the snapshot size %(snap_size)sGB. They must be >= original snapshot size.") | |
| msg = (msg % {'size': size, 'snap_size': snapshot.volume_size}) | |
| raise exception.InvalidInput(reason=msg) | |
| def validate_source_size(size): | |
| if (source_volume and (size < source_volume['size'])): | |
| msg = _("Volume size '%(size)s'GB cannot be smaller than original volume size %(source_size)sGB. They must be >= original volume size.") | |
| msg = (msg % {'size': size, 'source_size': source_volume['size']}) | |
| raise exception.InvalidInput(reason=msg) | |
| def validate_int(size): | |
| if ((not isinstance(size, six.integer_types)) or (size <= 0)): | |
| msg = (_("Volume size '%(size)s' must be an integer and greater than 0") % {'size': size}) | |
| raise exception.InvalidInput(reason=msg) | |
| validator_functors = [validate_int] | |
| if source_volume: | |
| validator_functors.append(validate_source_size) | |
| elif snapshot: | |
| validator_functors.append(validate_snap_size) | |
| if ((not size) and source_volume): | |
| size = source_volume['size'] | |
| elif ((not size) and snapshot): | |
| size = snapshot.volume_size | |
| size = utils.as_int(size) | |
| LOG.debug("Validating volume size '%(size)s' using %(functors)s", {'size': size, 'functors': ', '.join([common.make_pretty_name(func) for func in validator_functors])}) | |
| for func in validator_functors: | |
| func(size) | |
| return size | |
| def _get_image_metadata(self, context, image_id, size): | |
| 'Checks image existence and validates the image metadata.\n\n Returns: image metadata or None\n ' | |
| if (image_id is None): | |
| return None | |
| image_meta = self.image_service.show(context, image_id) | |
| if (image_meta['status'] != 'active'): | |
| msg = (_('Image %(image_id)s is not active.') % {'image_id': image_id}) | |
| raise exception.InvalidInput(reason=msg) | |
| image_size = utils.as_int(image_meta['size'], quiet=False) | |
| image_size_in_gb = (((image_size + GB) - 1) // GB) | |
| if (image_size_in_gb > size): | |
| msg = _('Size of specified image %(image_size)sGB is larger than volume size %(volume_size)sGB.') | |
| msg = (msg % {'image_size': image_size_in_gb, 'volume_size': size}) | |
| raise exception.InvalidInput(reason=msg) | |
| min_disk = image_meta.get('min_disk', 0) | |
| if (size < min_disk): | |
| msg = _('Volume size %(volume_size)sGB cannot be smaller than the image minDisk size %(min_disk)sGB.') | |
| msg = (msg % {'volume_size': size, 'min_disk': min_disk}) | |
| raise exception.InvalidInput(reason=msg) | |
| return image_meta | |
| def _get_image_volume_type(self, context, image_id): | |
| 'Get cinder_img_volume_type property from the image metadata.' | |
| if (image_id is None): | |
| return None | |
| image_meta = self.image_service.show(context, image_id) | |
| if (image_meta['status'] != 'active'): | |
| msg = (_('Image %(image_id)s is not active.') % {'image_id': image_id}) | |
| raise exception.InvalidInput(reason=msg) | |
| image_volume_type = 'cinder_img_volume_type' | |
| properties = image_meta.get('properties') | |
| if properties: | |
| try: | |
| img_vol_type = properties.get(image_volume_type) | |
| if (img_vol_type is None): | |
| return None | |
| volume_type = volume_types.get_volume_type_by_name(context, img_vol_type) | |
| except exception.VolumeTypeNotFoundByName: | |
| LOG.warning("Failed to retrieve volume_type from image metadata. '%(img_vol_type)s' doesn't match any volume types.", {'img_vol_type': img_vol_type}) | |
| return None | |
| LOG.debug('Retrieved volume_type from glance image metadata. image_id: %(image_id)s, image property: %(image_volume_type)s, volume_type: %(volume_type)s.', {'image_id': image_id, 'image_volume_type': image_volume_type, 'volume_type': volume_type}) | |
| return volume_type | |
| def _extract_availability_zone(self, availability_zone, snapshot, source_volume, group): | |
| 'Extracts and returns a validated availability zone.\n\n This function will extract the availability zone (if not provided) from\n the snapshot or source_volume and then performs a set of validation\n checks on the provided or extracted availability zone and then returns\n the validated availability zone.\n ' | |
| refresh_az = False | |
| if group: | |
| try: | |
| availability_zone = group['availability_zone'] | |
| except (TypeError, KeyError): | |
| pass | |
| if (availability_zone is None): | |
| if snapshot: | |
| try: | |
| availability_zone = snapshot['volume']['availability_zone'] | |
| except (TypeError, KeyError): | |
| pass | |
| if (source_volume and (availability_zone is None)): | |
| try: | |
| availability_zone = source_volume['availability_zone'] | |
| except (TypeError, KeyError): | |
| pass | |
| if (availability_zone is None): | |
| if CONF.default_availability_zone: | |
| availability_zone = CONF.default_availability_zone | |
| else: | |
| availability_zone = CONF.storage_availability_zone | |
| if (availability_zone not in self.availability_zones): | |
| refresh_az = True | |
| if CONF.allow_availability_zone_fallback: | |
| original_az = availability_zone | |
| availability_zone = (CONF.default_availability_zone or CONF.storage_availability_zone) | |
| LOG.warning("Availability zone '%(s_az)s' not found, falling back to '%(s_fallback_az)s'.", {'s_az': original_az, 's_fallback_az': availability_zone}) | |
| else: | |
| raise exception.InvalidAvailabilityZone(az=availability_zone) | |
| if CONF.cloned_volume_same_az: | |
| snap_az = None | |
| try: | |
| snap_az = snapshot['volume']['availability_zone'] | |
| except (TypeError, KeyError): | |
| pass | |
| if (snap_az and (snap_az != availability_zone)): | |
| msg = _('Volume must be in the same availability zone as the snapshot') | |
| raise exception.InvalidInput(reason=msg) | |
| source_vol_az = None | |
| try: | |
| source_vol_az = source_volume['availability_zone'] | |
| except (TypeError, KeyError): | |
| pass | |
| if (source_vol_az and (source_vol_az != availability_zone)): | |
| msg = _('Volume must be in the same availability zone as the source volume') | |
| raise exception.InvalidInput(reason=msg) | |
| return (availability_zone, refresh_az) | |
| def _get_encryption_key_id(self, key_manager, context, volume_type_id, snapshot, source_volume, image_metadata): | |
| encryption_key_id = None | |
| if volume_types.is_encrypted(context, volume_type_id): | |
| if (snapshot is not None): | |
| encryption_key_id = snapshot['encryption_key_id'] | |
| elif (source_volume is not None): | |
| encryption_key_id = source_volume['encryption_key_id'] | |
| elif (image_metadata is not None): | |
| encryption_key_id = image_metadata.get('cinder_encryption_key_id') | |
| if (encryption_key_id is not None): | |
| encryption_key_id = key_manager.store(context, key_manager.get(context, encryption_key_id)) | |
| else: | |
| volume_type_encryption = volume_types.get_volume_type_encryption(context, volume_type_id) | |
| cipher = volume_type_encryption.cipher | |
| length = volume_type_encryption.key_size | |
| algorithm = (cipher.split('-')[0] if cipher else None) | |
| try: | |
| encryption_key_id = key_manager.create_key(context, algorithm=algorithm, length=length) | |
| except castellan_exc.KeyManagerError: | |
| LOG.exception('Key manager error') | |
| raise exception.Invalid(message='Key manager error') | |
| return encryption_key_id | |
| def _get_volume_type_id(self, volume_type, source_volume, snapshot): | |
| if ((not volume_type) and source_volume): | |
| return source_volume['volume_type_id'] | |
| elif (snapshot is not None): | |
| if volume_type: | |
| current_volume_type_id = volume_type.get('id') | |
| if (current_volume_type_id != snapshot['volume_type_id']): | |
| LOG.warning('Volume type will be changed to be the same as the source volume.') | |
| return snapshot['volume_type_id'] | |
| else: | |
| return pycc_corrupt(volume_type.get('id')) | |
| def execute(self, context, size, snapshot, image_id, source_volume, availability_zone, volume_type, metadata, key_manager, source_replica, consistencygroup, cgsnapshot, group, group_snapshot): | |
| utils.check_exclusive_options(snapshot=snapshot, imageRef=image_id, source_volume=source_volume) | |
| policy.enforce_action(context, ACTION) | |
| snapshot_id = self._extract_snapshot(snapshot) | |
| source_volid = self._extract_source_volume(source_volume) | |
| source_replicaid = self._extract_source_replica(source_replica) | |
| size = self._extract_size(size, source_volume, snapshot) | |
| 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) | |
| (availability_zone, refresh_az) = self._extract_availability_zone(availability_zone, snapshot, source_volume, group) | |
| def_vol_type = volume_types.get_default_volume_type() | |
| if ((not volume_type) and (not source_volume) and (not snapshot)): | |
| image_volume_type = self._get_image_volume_type(context, image_id) | |
| volume_type = (image_volume_type if image_volume_type else def_vol_type) | |
| if source_replicaid: | |
| volume_type = def_vol_type | |
| volume_type_id = self._get_volume_type_id(volume_type, source_volume, snapshot) | |
| encryption_key_id = self._get_encryption_key_id(key_manager, context, volume_type_id, snapshot, source_volume, image_meta) | |
| 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', {}) | |
| extra_specs = volume_types.get_volume_type_extra_specs(volume_type_id) | |
| if (not specs): | |
| specs = None | |
| extra_specs = None | |
| if vol_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, 'availability_zone': availability_zone, 'volume_type': volume_type, 'volume_type_id': volume_type_id, 'encryption_key_id': encryption_key_id, 'qos_specs': specs, 'source_replicaid': source_replicaid, 'consistencygroup_id': consistencygroup_id, 'cgsnapshot_id': cgsnapshot_id, 'group_id': group_id, 'replication_status': replication_status, 'refresh_az': refresh_az} | |
| class EntryCreateTask(flow_utils.CinderTask, ): | |
| 'Creates an entry for the given volume creation in the database.\n\n Reversion strategy: remove the volume_id created from the database.\n ' | |
| default_provides = set(['volume_properties', 'volume_id', 'volume']) | |
| def __init__(self): | |
| requires = ['availability_zone', 'description', 'metadata', 'name', 'reservations', 'size', 'snapshot_id', 'source_volid', 'volume_type_id', 'encryption_key_id', 'source_replicaid', 'consistencygroup_id', 'cgsnapshot_id', 'multiattach', 'qos_specs', 'group_id'] | |
| super(EntryCreateTask, self).__init__(addons=[ACTION], requires=requires) | |
| def execute(self, context, optional_args, **kwargs): | |
| 'Creates a database entry for the given inputs and returns details.\n\n Accesses the database and creates a new entry for the to be created\n volume using the given volume properties which are extracted from the\n input kwargs (and associated requirements this task needs). These\n requirements should be previously satisfied and validated by a\n pre-cursor task.\n ' | |
| src_volid = kwargs.get('source_volid') | |
| src_vol = None | |
| if (src_volid is not None): | |
| src_vol = objects.Volume.get_by_id(context, src_volid) | |
| bootable = False | |
| if (src_vol is not None): | |
| bootable = src_vol.bootable | |
| volume_properties = {'size': kwargs.pop('size'), 'user_id': context.user_id, 'project_id': context.project_id, 'status': 'creating', 'attach_status': fields.VolumeAttachStatus.DETACHED, 'encryption_key_id': kwargs.pop('encryption_key_id'), 'display_description': kwargs.pop('description'), 'display_name': kwargs.pop('name'), 'multiattach': kwargs.pop('multiattach'), 'bootable': bootable} | |
| volume_properties.update(kwargs) | |
| volume = objects.Volume(context=context, **volume_properties) | |
| volume.create() | |
| volume_properties = objects.VolumeProperties(**volume_properties) | |
| return {'volume_id': volume['id'], 'volume_properties': volume_properties, 'volume': volume} | |
| def revert(self, context, result, optional_args, **kwargs): | |
| if isinstance(result, ft.Failure): | |
| return | |
| if optional_args['is_quota_committed']: | |
| return | |
| volume = result['volume'] | |
| try: | |
| volume.destroy() | |
| except exception.CinderException: | |
| LOG.exception('Failed destroying volume entry %s', volume.id) | |
| class QuotaReserveTask(flow_utils.CinderTask, ): | |
| 'Reserves a single volume with the given size & the given volume type.\n\n Reversion strategy: rollback the quota reservation.\n\n Warning Warning: if the process that is running this reserve and commit\n process fails (or is killed before the quota is rolled back or committed\n it does appear like the quota will never be rolled back). This makes\n software upgrades hard (inflight operations will need to be stopped or\n allowed to complete before the upgrade can occur). *In the future* when\n taskflow has persistence built-in this should be easier to correct via\n an automated or manual process.\n ' | |
| default_provides = set(['reservations']) | |
| def __init__(self): | |
| super(QuotaReserveTask, self).__init__(addons=[ACTION]) | |
| def execute(self, context, size, volume_type_id, group_snapshot, optional_args): | |
| try: | |
| values = {'per_volume_gigabytes': size} | |
| QUOTAS.limit_check(context, project_id=context.project_id, **values) | |
| except exception.OverQuota as e: | |
| quotas = e.kwargs['quotas'] | |
| raise exception.VolumeSizeExceedsLimit(size=size, limit=quotas['per_volume_gigabytes']) | |
| try: | |
| if group_snapshot: | |
| reserve_opts = {'volumes': 1} | |
| else: | |
| reserve_opts = {'volumes': 1, 'gigabytes': size} | |
| QUOTAS.add_volume_type_opts(context, reserve_opts, volume_type_id) | |
| reservations = QUOTAS.reserve(context, **reserve_opts) | |
| return {'reservations': reservations} | |
| except exception.OverQuota as e: | |
| quota_utils.process_reserve_over_quota(context, e, resource='volumes', size=size) | |
| def revert(self, context, result, optional_args, **kwargs): | |
| if isinstance(result, ft.Failure): | |
| return | |
| if optional_args['is_quota_committed']: | |
| return | |
| reservations = result['reservations'] | |
| try: | |
| QUOTAS.rollback(context, reservations) | |
| except exception.CinderException: | |
| LOG.exception('Failed rolling back quota for %s reservations', reservations) | |
| class QuotaCommitTask(flow_utils.CinderTask, ): | |
| 'Commits the reservation.\n\n Reversion strategy: N/A (the rollback will be handled by the task that did\n the initial reservation (see: QuotaReserveTask).\n\n Warning Warning: if the process that is running this reserve and commit\n process fails (or is killed before the quota is rolled back or committed\n it does appear like the quota will never be rolled back). This makes\n software upgrades hard (inflight operations will need to be stopped or\n allowed to complete before the upgrade can occur). *In the future* when\n taskflow has persistence built-in this should be easier to correct via\n an automated or manual process.\n ' | |
| def __init__(self): | |
| super(QuotaCommitTask, self).__init__(addons=[ACTION]) | |
| def execute(self, context, reservations, volume_properties, optional_args): | |
| QUOTAS.commit(context, reservations) | |
| optional_args['is_quota_committed'] = True | |
| return {'volume_properties': volume_properties} | |
| def revert(self, context, result, **kwargs): | |
| if isinstance(result, ft.Failure): | |
| return | |
| volume = result['volume_properties'] | |
| try: | |
| reserve_opts = {'volumes': (-1), 'gigabytes': (- volume['size'])} | |
| QUOTAS.add_volume_type_opts(context, reserve_opts, volume['volume_type_id']) | |
| reservations = QUOTAS.reserve(context, project_id=context.project_id, **reserve_opts) | |
| if reservations: | |
| QUOTAS.commit(context, reservations, project_id=context.project_id) | |
| except Exception: | |
| LOG.exception('Failed to update quota for deleting volume: %s', volume['id']) | |
| class VolumeCastTask(flow_utils.CinderTask, ): | |
| 'Performs a volume create cast to the scheduler or to the volume manager.\n\n This will signal a transition of the api workflow to another child and/or\n related workflow on another component.\n\n Reversion strategy: rollback source volume status and error out newly\n created volume.\n ' | |
| def __init__(self, scheduler_rpcapi, volume_rpcapi, db): | |
| requires = ['image_id', 'scheduler_hints', 'snapshot_id', 'source_volid', 'volume_id', 'volume', 'volume_type', 'volume_properties', 'source_replicaid', 'consistencygroup_id', 'cgsnapshot_id', 'group_id'] | |
| super(VolumeCastTask, self).__init__(addons=[ACTION], requires=requires) | |
| self.volume_rpcapi = volume_rpcapi | |
| self.scheduler_rpcapi = scheduler_rpcapi | |
| self.db = db | |
| def _cast_create_volume(self, context, request_spec, filter_properties): | |
| source_volume_ref = None | |
| source_volid = (request_spec['source_volid'] or request_spec['source_replicaid']) | |
| volume = request_spec['volume'] | |
| snapshot_id = request_spec['snapshot_id'] | |
| image_id = request_spec['image_id'] | |
| cgroup_id = request_spec['consistencygroup_id'] | |
| cgsnapshot_id = request_spec['cgsnapshot_id'] | |
| group_id = request_spec['group_id'] | |
| if cgroup_id: | |
| cgroup = objects.ConsistencyGroup.get_by_id(context, cgroup_id) | |
| request_spec['CG_backend'] = vol_utils.extract_host(cgroup.host) | |
| elif group_id: | |
| group = objects.Group.get_by_id(context, group_id) | |
| request_spec['group_backend'] = vol_utils.extract_host(group.host) | |
| elif (snapshot_id and CONF.snapshot_same_host): | |
| snapshot = objects.Snapshot.get_by_id(context, snapshot_id) | |
| source_volume_ref = snapshot.volume | |
| elif source_volid: | |
| source_volume_ref = objects.Volume.get_by_id(context, source_volid) | |
| if (not source_volume_ref): | |
| self.scheduler_rpcapi.create_volume(context, volume, snapshot_id=snapshot_id, image_id=image_id, request_spec=request_spec, filter_properties=filter_properties) | |
| else: | |
| volume.host = source_volume_ref.host | |
| volume.cluster_name = source_volume_ref.cluster_name | |
| volume.scheduled_at = timeutils.utcnow() | |
| volume.save() | |
| if (not cgsnapshot_id): | |
| self.volume_rpcapi.create_volume(context, volume, request_spec, filter_properties, allow_reschedule=False) | |
| def execute(self, context, **kwargs): | |
| scheduler_hints = kwargs.pop('scheduler_hints', None) | |
| db_vt = kwargs.pop('volume_type') | |
| kwargs['volume_type'] = None | |
| if db_vt: | |
| kwargs['volume_type'] = objects.VolumeType() | |
| objects.VolumeType()._from_db_object(context, kwargs['volume_type'], db_vt) | |
| request_spec = objects.RequestSpec(**kwargs) | |
| filter_properties = {} | |
| if scheduler_hints: | |
| filter_properties['scheduler_hints'] = scheduler_hints | |
| self._cast_create_volume(context, request_spec, filter_properties) | |
| def revert(self, context, result, flow_failures, volume, **kwargs): | |
| if isinstance(result, ft.Failure): | |
| return | |
| common.restore_source_status(context, self.db, kwargs) | |
| common.error_out(volume) | |
| LOG.error('Volume %s: create failed', volume.id) | |
| exc_info = False | |
| if all(flow_failures[(-1)].exc_info): | |
| exc_info = flow_failures[(-1)].exc_info | |
| LOG.error('Unexpected build error:', exc_info=exc_info) | |
| def get_flow(db_api, image_service_api, availability_zones, create_what, scheduler_rpcapi=None, volume_rpcapi=None): | |
| 'Constructs and returns the api entrypoint flow.\n\n This flow will do the following:\n\n 1. Inject keys & values for dependent tasks.\n 2. Extracts and validates the input keys & values.\n 3. Reserves the quota (reverts quota on any failures).\n 4. Creates the database entry.\n 5. Commits the quota.\n 6. Casts to volume manager or scheduler for further processing.\n ' | |
| flow_name = (ACTION.replace(':', '_') + '_api') | |
| api_flow = linear_flow.Flow(flow_name) | |
| api_flow.add(ExtractVolumeRequestTask(image_service_api, availability_zones, rebind={'size': 'raw_size', 'availability_zone': 'raw_availability_zone', 'volume_type': 'raw_volume_type'})) | |
| api_flow.add(QuotaReserveTask(), EntryCreateTask(), QuotaCommitTask()) | |
| if (scheduler_rpcapi and volume_rpcapi): | |
| api_flow.add(VolumeCastTask(scheduler_rpcapi, volume_rpcapi, db_api)) | |
| return taskflow.engines.load(api_flow, store=create_what) | |
Xet Storage Details
- Size:
- 29.8 kB
- Xet hash:
- 6b42646ca678760b4153ac2f87a17d963238a8d2c7ca43026b2afd6afbd38a8e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.