Ejemplo n.º 1
0
    def _live_migration_src_check(self, context, instance_ref):
        """Live migration check routine (for src host).

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object

        """

        # Checking instance is running.
        if (power_state.RUNNING != instance_ref['state'] or \
           'running' != instance_ref['state_description']):
            ec2_id = instance_ref['hostname']
            raise exception.Invalid(_('Instance(%s) is not running') % ec2_id)

        # Checing volume node is running when any volumes are mounted
        # to the instance.
        if len(instance_ref['volumes']) != 0:
            services = db.service_get_all_by_topic(context, 'volume')
            if len(services) < 1 or not self.service_is_up(services[0]):
                raise exception.Invalid(
                    _("volume node is not alive"
                      "(time synchronize problem?)"))

        # Checking src host exists and compute node
        src = instance_ref['host']
        services = db.service_get_all_compute_by_host(context, src)

        # Checking src host is alive.
        if not self.service_is_up(services[0]):
            raise exception.Invalid(
                _("%s is not alive(time "
                  "synchronize problem?)") % src)
Ejemplo n.º 2
0
    def _live_migration_dest_check(self, context, instance_ref, dest):
        """Live migration check routine (for destination host).

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        # Checking dest exists and compute node.
        dservice_refs = db.service_get_all_compute_by_host(context, dest)
        dservice_ref = dservice_refs[0]

        # Checking dest host is alive.
        if not self.service_is_up(dservice_ref):
            raise exception.Invalid(
                _("%s is not alive(time "
                  "synchronize problem?)") % dest)

        # Checking whether The host where instance is running
        # and dest is not same.
        src = instance_ref['host']
        if dest == src:
            ec2_id = instance_ref['hostname']
            raise exception.Invalid(
                _("%(dest)s is where %(ec2_id)s is "
                  "running now. choose other host.") % locals())

        # Checking dst host still has enough capacities.
        self.assert_compute_node_has_enough_resources(context, instance_ref,
                                                      dest)
Ejemplo n.º 3
0
def parse_cpu_spec(spec):
    """Parse a CPU set specification.

    :param spec: cpu set string eg "1-4,^3,6"

    Each element in the list is either a single
    CPU number, a range of CPU numbers, or a
    caret followed by a CPU number to be excluded
    from a previous range.

    :returns: a set of CPU indexes
    """

    cpuset_ids = set()
    cpuset_reject_ids = set()
    for rule in spec.split(','):
        rule = rule.strip()
        # Handle multi ','
        if len(rule) < 1:
            continue
        # Note the count limit in the .split() call
        range_parts = rule.split('-', 1)
        if len(range_parts) > 1:
            # So, this was a range; start by converting the parts to ints
            try:
                start, end = [int(p.strip()) for p in range_parts]
            except ValueError:
                raise exception.Invalid(
                    _("Invalid range expression %r") % rule)
            # Make sure it's a valid range
            if start > end:
                raise exception.Invalid(
                    _("Invalid range expression %r") % rule)
            # Add available CPU ids to set
            cpuset_ids |= set(range(start, end + 1))
        elif rule[0] == '^':
            # Not a range, the rule is an exclusion rule; convert to int
            try:
                cpuset_reject_ids.add(int(rule[1:].strip()))
            except ValueError:
                raise exception.Invalid(
                    _("Invalid exclusion "
                      "expression %r") % rule)
        else:
            # OK, a single CPU to include; convert to int
            try:
                cpuset_ids.add(int(rule))
            except ValueError:
                raise exception.Invalid(
                    _("Invalid inclusion "
                      "expression %r") % rule)

    # Use sets to handle the exclusion rules for us
    cpuset_ids -= cpuset_reject_ids

    return cpuset_ids
Ejemplo n.º 4
0
def get_cpuset_ids():
    """
    Parsing vcpu_pin_set config.

    Returns a list of pcpu ids can be used by instances.
    """
    if not CONF.vcpu_pin_set:
        return None

    cpuset_ids = set()
    cpuset_reject_ids = set()
    for rule in CONF.vcpu_pin_set.split(','):
        rule = rule.strip()
        # Handle multi ','
        if len(rule) < 1:
            continue
        # Note the count limit in the .split() call
        range_parts = rule.split('-', 1)
        if len(range_parts) > 1:
            # So, this was a range; start by converting the parts to ints
            try:
                start, end = [int(p.strip()) for p in range_parts]
            except ValueError:
                raise exception.Invalid(
                    _("Invalid range expression %r") % rule)
            # Make sure it's a valid range
            if start > end:
                raise exception.Invalid(
                    _("Invalid range expression %r") % rule)
            # Add available pcpu ids to set
            cpuset_ids |= set(range(start, end + 1))
        elif rule[0] == '^':
            # Not a range, the rule is an exclusion rule; convert to int
            try:
                cpuset_reject_ids.add(int(rule[1:].strip()))
            except ValueError:
                raise exception.Invalid(
                    _("Invalid exclusion "
                      "expression %r") % rule)
        else:
            # OK, a single PCPU to include; convert to int
            try:
                cpuset_ids.add(int(rule))
            except ValueError:
                raise exception.Invalid(
                    _("Invalid inclusion "
                      "expression %r") % rule)
    # Use sets to handle the exclusion rules for us
    cpuset_ids -= cpuset_reject_ids
    if not cpuset_ids:
        raise exception.Invalid(
            _("No CPUs available after parsing %r") % CONF.vcpu_pin_set)
    # This will convert the set to a sorted list for us
    return sorted(cpuset_ids)
Ejemplo n.º 5
0
    def _detach_volume_vmdk(self, connection_info, instance):
        """Detach volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        # Detach Volume from VM
        LOG.debug("_detach_volume_vmdk: %s", connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        device = self._get_vmdk_backed_disk_device(vm_ref, data)

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)

        # IDE does not support disk hotplug
        if vmdk.adapter_type == constants.ADAPTER_TYPE_IDE:
            state = vm_util.get_vm_state(self._session, instance)
            if state.lower() != 'poweredoff':
                raise exception.Invalid(_('%s does not support disk '
                                          'hotplug.') % vmdk.adapter_type)

        self._consolidate_vmdk_volume(instance, vm_ref, device, volume_ref,
                                      adapter_type=vmdk.adapter_type,
                                      disk_type=vmdk.disk_type)

        self.detach_disk_from_vm(vm_ref, instance, device)

        # Remove key-value pair <volume_id, vmdk_uuid> from instance's
        # extra config. Setting value to empty string will remove the key.
        self._update_volume_details(vm_ref, data['volume_id'], "")

        LOG.debug("Detached VMDK: %s", connection_info, instance=instance)
Ejemplo n.º 6
0
def get_action_fn():
    fn = CONF.category.action_fn
    fn_args = []
    for arg in CONF.category.action_args:
        if isinstance(arg, six.binary_type):
            arg = arg.decode('utf-8')
        fn_args.append(arg)

    fn_kwargs = {}
    for k in CONF.category.action_kwargs:
        v = getattr(CONF.category, 'action_kwarg_' + k)
        if v is None:
            continue
        if isinstance(v, six.binary_type):
            v = v.decode('utf-8')
        fn_kwargs[k] = v

    # call the action with the remaining arguments
    # check arguments
    missing = utils.validate_args(fn, *fn_args, **fn_kwargs)
    if missing:
        # NOTE(mikal): this isn't the most helpful error message ever. It is
        # long, and tells you a lot of things you probably don't want to know
        # if you just got a single arg wrong.
        print(fn.__doc__)
        CONF.print_help()
        raise exception.Invalid(
            _("Missing arguments: %s") % ", ".join(missing))

    return fn, fn_args, fn_kwargs
Ejemplo n.º 7
0
    def _attach_volume_vmdk(self, connection_info, instance):
        """Attach vmdk volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        LOG.debug("_attach_volume_vmdk: %s",
                  connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        hw_devices = self._session._call_method(vim_util,
                                                'get_dynamic_property',
                                                volume_ref, 'VirtualMachine',
                                                'config.hardware.device')
        (volume_vmdk_path, adapter_type,
         disk_type) = vm_util.get_vmdk_path_and_adapter_type(hw_devices)

        # IDE does not support disk hotplug
        if (instance.vm_state == vm_states.ACTIVE
                and adapter_type == constants.ADAPTER_TYPE_IDE):
            msg = _('%s does not support disk hotplug.') % adapter_type
            raise exception.Invalid(msg)

        # Attach the disk to virtual machine instance
        self.attach_disk_to_vm(vm_ref,
                               instance,
                               adapter_type,
                               disk_type,
                               vmdk_path=volume_vmdk_path)

        # Store the uuid of the volume_device
        self._update_volume_details(vm_ref, instance, data['volume_id'])

        LOG.debug("Attached VMDK: %s", connection_info, instance=instance)
Ejemplo n.º 8
0
    def __init__(self, hosts):
        """Create a new hash ring across the specified hosts.

        :param hosts: an iterable of hosts which will be mapped.
        """
        replicas = DISTRIBUTION_REPLICAS

        try:
            self.hosts = set(hosts)
            self.replicas = replicas if replicas <= len(hosts) else len(hosts)
        except TypeError:
            raise exception.Invalid(
                _("Invalid hosts supplied when building HashRing."))

        self._host_hashes = {}
        for host in hosts:
            key = str(host).encode('utf8')
            key_hash = hashlib.md5(key)
            for p in range(2**PARTITION_EXPONENT):
                key_hash.update(key)
                hashed_key = self._hash2int(key_hash)
                self._host_hashes[hashed_key] = host
        # Gather the (possibly colliding) resulting hashes into a bisectable
        # list.
        self._partitions = sorted(self._host_hashes.keys())
Ejemplo n.º 9
0
Archivo: lvm.py Proyecto: zlzlnet/nova
def clear_volume(path):
    """Obfuscate the logical volume.

    :param path: logical volume path
    """
    volume_clear = CONF.libvirt.volume_clear

    if volume_clear == 'none':
        return

    volume_clear_size = int(CONF.libvirt.volume_clear_size) * units.Mi

    try:
        volume_size = get_volume_size(path)
    except exception.VolumeBDMPathNotFound:
        LOG.warn(_LW('ignoring missing logical volume %(path)s'),
                 {'path': path})
        return

    if volume_clear_size != 0 and volume_clear_size < volume_size:
        volume_size = volume_clear_size

    if volume_clear == 'zero':
        # NOTE(p-draigbrady): we could use shred to do the zeroing
        # with -n0 -z, however only versions >= 8.22 perform as well as dd
        _zero_volume(path, volume_size)
    elif volume_clear == 'shred':
        utils.execute('shred', '-n3', '-s%d' % volume_size, path,
                      run_as_root=True)
    else:
        raise exception.Invalid(_("volume_clear='%s' is not handled")
                                % volume_clear)
Ejemplo n.º 10
0
    def parse_disk_qos_specs(self, qos_specs):
        total_bytes_sec = int(qos_specs.get('total_bytes_sec', 0))
        min_bytes_sec = int(qos_specs.get('min_bytes_sec', 0))

        total_iops = int(
            qos_specs.get('total_iops_sec',
                          self._bytes_per_sec_to_iops(total_bytes_sec)))
        min_iops = int(
            qos_specs.get('min_iops_sec',
                          self._bytes_per_sec_to_iops(min_bytes_sec)))

        if total_iops and total_iops < min_iops:
            err_msg = (_("Invalid QoS specs: minimum IOPS cannot be greater "
                         "than maximum IOPS. "
                         "Requested minimum IOPS: %(min_iops)s "
                         "Requested maximum IOPS: %(total_iops)s.") % {
                             'min_iops': min_iops,
                             'total_iops': total_iops
                         })
            raise exception.Invalid(err_msg)

        unsupported_specs = [
            spec for spec in qos_specs if spec not in self._SUPPORTED_QOS_SPECS
        ]
        if unsupported_specs:
            LOG.warning(
                _LW('Ignoring unsupported qos specs: '
                    '%(unsupported_specs)s. '
                    'Supported qos specs: %(supported_qos_speces)s'), {
                        'unsupported_specs': unsupported_specs,
                        'supported_qos_speces': self._SUPPORTED_QOS_SPECS
                    })

        return min_iops, total_iops
Ejemplo n.º 11
0
def add_rules(context, id, name, vals):
    """Add security group rule(s) to security group.

    Note: the Nova security group API doesn't support adding multiple
    security group rules at once but the EC2 one does. Therefore,
    this function is written to support both. Multiple rules are
    installed to a security group in neutron using bulk support.
    """

    neutron = neutronapi.get_client(context)
    body = _make_neutron_security_group_rules_list(vals)
    try:
        rules = neutron.create_security_group_rule(body).get(
            'security_group_rules')
    except n_exc.NeutronClientException as e:
        exc_info = sys.exc_info()
        if e.status_code == 404:
            LOG.exception("Neutron Error getting security group %s", name)
            raise exception.SecurityGroupNotFound(six.text_type(e))
        elif e.status_code == 409:
            LOG.exception("Neutron Error adding rules to security "
                          "group %s", name)
            raise exception.SecurityGroupLimitExceeded(six.text_type(e))
        elif e.status_code == 400:
            LOG.exception("Neutron Error: %s", e)
            raise exception.Invalid(six.text_type(e))
        else:
            six.reraise(*exc_info)
    converted_rules = []
    for rule in rules:
        converted_rules.append(
            _convert_to_nova_security_group_rule_format(rule))
    return converted_rules
Ejemplo n.º 12
0
    def _get_kernel_ramdisk_from_image(self, req, image_id):
        """Retrevies kernel and ramdisk IDs from Glance

        Only 'machine' (ami) type use kernel and ramdisk outside of the
        image.
        """
        # FIXME(sirp): Since we're retrieving the kernel_id from an
        # image_property, this means only Glance is supported.
        # The BaseImageService needs to expose a consistent way of accessing
        # kernel_id and ramdisk_id
        image = self._image_service.show(req.environ['nova.context'], image_id)

        if image['status'] != 'active':
            raise exception.Invalid(
                _("Cannot build from image %(image_id)s, status not active") %
                locals())

        if image['disk_format'] != 'ami':
            return None, None

        try:
            kernel_id = image['properties']['kernel_id']
        except KeyError:
            raise exception.NotFound(
                _("Kernel not found for image %(image_id)s") % locals())

        try:
            ramdisk_id = image['properties']['ramdisk_id']
        except KeyError:
            raise exception.NotFound(
                _("Ramdisk not found for image %(image_id)s") % locals())

        return kernel_id, ramdisk_id
Ejemplo n.º 13
0
def clear_logical_volume(path):
    """Obfuscate the logical volume.

    :param path: logical volume path
    """
    volume_clear = CONF.libvirt.volume_clear

    if volume_clear not in ('none', 'shred', 'zero'):
        LOG.error(_("ignoring unrecognized volume_clear='%s' value"),
                  volume_clear)
        volume_clear = 'zero'

    if volume_clear == 'none':
        return

    volume_clear_size = int(CONF.libvirt.volume_clear_size) * units.Mi
    volume_size = logical_volume_size(path)

    if volume_clear_size != 0 and volume_clear_size < volume_size:
        volume_size = volume_clear_size

    if volume_clear == 'zero':
        # NOTE(p-draigbrady): we could use shred to do the zeroing
        # with -n0 -z, however only versions >= 8.22 perform as well as dd
        _zero_logical_volume(path, volume_size)
    elif volume_clear == 'shred':
        utils.execute('shred',
                      '-n3',
                      '-s%d' % volume_size,
                      path,
                      run_as_root=True)
    else:
        raise exception.Invalid(
            _("volume_clear='%s' is not handled") % volume_clear)
Ejemplo n.º 14
0
    def _attach_volume_vmdk(self,
                            connection_info,
                            instance,
                            adapter_type=None):
        """Attach vmdk volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        LOG.debug("_attach_volume_vmdk: %s",
                  connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)
        adapter_type = adapter_type or vmdk.adapter_type

        # IDE does not support disk hotplug
        if (instance.vm_state == vm_states.ACTIVE
                and adapter_type == constants.ADAPTER_TYPE_IDE):
            msg = _('%s does not support disk hotplug.') % adapter_type
            raise exception.Invalid(msg)

        # Attach the disk to virtual machine instance
        self.attach_disk_to_vm(vm_ref,
                               instance,
                               adapter_type,
                               vmdk.disk_type,
                               vmdk_path=vmdk.path)

        # Store the uuid of the volume_device
        self._update_volume_details(vm_ref, data['volume_id'],
                                    vmdk.device.backing.uuid)

        LOG.debug("Attached VMDK: %s", connection_info, instance=instance)
Ejemplo n.º 15
0
    def _detach_volume_vmdk(self, connection_info, instance):
        """Detach volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        # Detach Volume from VM
        LOG.debug("_detach_volume_vmdk: %s",
                  connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        device = self._get_vmdk_backed_disk_device(vm_ref, data)

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)

        # IDE does not support disk hotplug
        if (instance.vm_state == vm_states.ACTIVE
                and vmdk.adapter_type == constants.ADAPTER_TYPE_IDE):
            msg = _('%s does not support disk hotplug.') % vmdk.adapter_type
            raise exception.Invalid(msg)

        self._consolidate_vmdk_volume(instance,
                                      vm_ref,
                                      device,
                                      volume_ref,
                                      adapter_type=vmdk.adapter_type,
                                      disk_type=vmdk.disk_type)

        self.detach_disk_from_vm(vm_ref, instance, device)
        LOG.debug("Detached VMDK: %s", connection_info, instance=instance)
Ejemplo n.º 16
0
def _translate_plain_exception(exc_type, exc_value):
    if exc_type in (glanceclient.exc.Forbidden, glanceclient.exc.Unauthorized):
        return exception.NotAuthorized(exc_value)
    if exc_type is glanceclient.exc.NotFound:
        return exception.NotFound(exc_value)
    if exc_type is glanceclient.exc.BadRequest:
        return exception.Invalid(exc_value)
    return exc_value
Ejemplo n.º 17
0
 def _canonical_path(self, path):
     canonpath, _err = utils.execute(
         'readlink', '-nm',
         os.path.join(self.imgdir, path.lstrip("/")),
         run_as_root=True)
     if not canonpath.startswith(os.path.realpath(self.imgdir) + '/'):
         raise exception.Invalid(_('File path %s not valid') % path)
     return canonpath
Ejemplo n.º 18
0
def create_security_group_rule(context, security_group, new_rule):
    if _rule_exists(security_group, new_rule):
        msg = (_('This rule already exists in group %s') %
               new_rule['parent_group_id'])
        raise exception.Invalid(msg)

    return add_rules(context, new_rule['parent_group_id'],
                     security_group['name'], [new_rule])[0]
Ejemplo n.º 19
0
def db_sync(version=None, database='main', context=None):
    """Migrate the database to `version` or the most recent version."""

    if database not in ('main', 'api'):
        raise exception.Invalid('%s is not a valid database' % database)

    # if the user requested a specific version, check if it's an integer:
    # if so, we're almost certainly in sqlalchemy-migrate land and won't
    # support that
    if version is not None and version.isdigit():
        raise exception.Invalid(
            'You requested an sqlalchemy-migrate database version; this is '
            'no longer supported'
        )

    engine = _get_engine(database, context=context)

    repository = _find_migrate_repo(database)
    config = _find_alembic_conf(database)
    # discard the URL stored in alembic.ini in favour of the URL configured
    # for the engine, casting from 'sqlalchemy.engine.url.URL' to str in the
    # process
    # NOTE(sean-k-mooney): the engine has already url encoded the connection
    # string using a mix of url encode styles for different parts of the url.
    # since we are updating the alembic config parser instance we need to
    # escape '%' to '%%' to account for ConfigParser's string interpolation.
    url = str(engine.url).replace('%', '%%')
    config.set_main_option('sqlalchemy.url', url)

    # if we're in a deployment where sqlalchemy-migrate is already present,
    # then apply all the updates for that and fake apply the initial alembic
    # migration; if we're not then 'upgrade' will take care of everything
    # this should be a one-time operation
    if (
        _is_database_under_migrate_control(engine, repository) and
        not _is_database_under_alembic_control(engine)
    ):
        _init_alembic_on_legacy_database(engine, database, repository, config)

    # apply anything later
    LOG.info('Applying migration(s)')

    _upgrade_alembic(engine, config, version)

    LOG.info('Migration(s) applied')
Ejemplo n.º 20
0
def _translate_plain_exception(exc_value):
    if isinstance(exc_value,
                  (glanceclient.exc.Forbidden, glanceclient.exc.Unauthorized)):
        return exception.NotAuthorized(unicode(exc_value))
    if isinstance(exc_value, glanceclient.exc.NotFound):
        return exception.NotFound(unicode(exc_value))
    if isinstance(exc_value, glanceclient.exc.BadRequest):
        return exception.Invalid(unicode(exc_value))
    return exc_value
Ejemplo n.º 21
0
def _translate_image_exception(image_id, exc_value):
    if isinstance(exc_value,
                  (glanceclient.exc.Forbidden, glanceclient.exc.Unauthorized)):
        return exception.ImageNotAuthorized(image_id=image_id)
    if isinstance(exc_value, glanceclient.exc.NotFound):
        return exception.ImageNotFound(image_id=image_id)
    if isinstance(exc_value, glanceclient.exc.BadRequest):
        return exception.Invalid(exc_value)
    return exc_value
Ejemplo n.º 22
0
def _translate_plain_exception(exc_type, exc_value):
    if exc_type in (glance_exception.Forbidden,
                    glance_exception.NotAuthenticated,
                    glance_exception.MissingCredentialError):
        return exception.NotAuthorized(exc_value)
    if exc_type is glance_exception.NotFound:
        return exception.NotFound(exc_value)
    if exc_type is glance_exception.Invalid:
        return exception.Invalid(exc_value)
    return exc_value
Ejemplo n.º 23
0
    def _get_vol_urn_from_connection(self, connection_info):
        """

        :param connection_info:
        :return:
        """
        vol_urn = connection_info.get('vol_urn')
        if vol_urn is None:
            msg = (_("invalid connection_info: %s."), connection_info)
            raise exception.Invalid(msg)
        return vol_urn
Ejemplo n.º 24
0
 def _get_partition(self, data):
     try:
         if six.PY3 and data is not None:
             data = data.encode('utf-8')
         key_hash = hashlib.md5(data)
         hashed_key = self._hash2int(key_hash)
         position = bisect.bisect(self._partitions, hashed_key)
         return position if position < len(self._partitions) else 0
     except TypeError:
         raise exception.Invalid(
             _("Invalid data supplied to HashRing.get_hosts."))
Ejemplo n.º 25
0
Archivo: api.py Proyecto: altai/nova
def _join_and_check_path_within_fs(fs, *args):
    '''os.path.join() with safety check for injected file paths.

    Join the supplied path components and make sure that the
    resulting path we are injecting into is within the
    mounted guest fs.  Trying to be clever and specifying a
    path with '..' in it will hit this safeguard.
    '''
    absolute_path = os.path.realpath(os.path.join(fs, *args))
    if not absolute_path.startswith(os.path.realpath(fs) + '/'):
        raise exception.Invalid(_('injected file path not valid'))
    return absolute_path
Ejemplo n.º 26
0
def get_vcpu_pin_set():
    """Parsing vcpu_pin_set config.

    Returns a set of pcpu ids can be used by instances.
    """
    if not CONF.vcpu_pin_set:
        return None

    cpuset_ids = parse_cpu_spec(CONF.vcpu_pin_set)
    if not cpuset_ids:
        raise exception.Invalid(
            _("No CPUs available after parsing %r") % CONF.vcpu_pin_set)
    return cpuset_ids
Ejemplo n.º 27
0
    def _detach_volume_fcd(self, connection_info, instance):
        """Detach fcd volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        data = connection_info['data']
        adapter_type = data['adapter_type']

        if adapter_type == constants.ADAPTER_TYPE_IDE:
            state = vm_util.get_vm_state(self._session, instance)
            if state != power_state.SHUTDOWN:
                raise exception.Invalid(_('%s does not support disk '
                                          'hotplug.') % adapter_type)

        vm_util.detach_fcd(self._session, vm_ref, data['id'])
Ejemplo n.º 28
0
    def _check_volume_ownership(self, context, vsa_id, id):
        obj = self.object
        try:
            volume_ref = self.volume_api.get(context, volume_id=id)
        except exception.NotFound:
            LOG.error(_("%(obj)s with ID %(id)s not found"), locals())
            raise

        own_vsa_id = self.volume_api.get_volume_metadata_value(
            volume_ref, self.direction)
        if own_vsa_id != vsa_id:
            LOG.error(_("%(obj)s with ID %(id)s belongs to VSA %(own_vsa_id)s"\
                        " and not to VSA %(vsa_id)s."), locals())
            raise exception.Invalid()
Ejemplo n.º 29
0
def destroy(context, security_group):
    """This function deletes a security group."""

    neutron = neutronapi.get_client(context)
    try:
        neutron.delete_security_group(security_group['id'])
    except n_exc.NeutronClientException as e:
        if e.status_code == 404:
            raise exception.SecurityGroupNotFound(str(e))
        elif e.status_code == 409:
            raise exception.Invalid(str(e))
        else:
            LOG.error("Neutron Error: %s", e)
            raise e
Ejemplo n.º 30
0
    def _get_available_controller_slot(self, controller_type, slot_map):
        max_slots = (os_win_const.IDE_CONTROLLER_SLOTS_NUMBER
                     if controller_type == constants.CTRL_TYPE_IDE else
                     os_win_const.SCSI_CONTROLLER_SLOTS_NUMBER)
        for idx, ctrl in enumerate(slot_map[controller_type]):
            if slot_map[controller_type][idx] >= 1:
                drive_addr = idx
                ctrl_disk_addr = max_slots - slot_map[controller_type][idx]
                slot_map[controller_type][idx] -= 1
                return (drive_addr, ctrl_disk_addr)

        msg = _(
            "There are no more free slots on controller %s") % controller_type
        raise exception.Invalid(msg)