예제 #1
0
def get_qos_specs_by_name(context, name):
    """Retrieves single qos specs by name."""
    if name is None:
        msg = _("name cannot be None")
        raise exception.InvalidQoSSpecs(reason=msg)

    return db.qos_specs_get_by_name(context, name)
예제 #2
0
def _verify_prepare_qos_specs(specs, create=True):
    """Check if 'consumer' value in qos specs is valid.

    Verify 'consumer' value in qos_specs is valid, raise
    exception if not. Assign default value to 'consumer', which
    is 'back-end' if input is empty.

    :params create a flag indicate if specs being verified is
    for create. If it's false, that means specs is for update,
    so that there's no need to add 'consumer' if that wasn't in
    specs.
    """

    # Check control location, if it's missing in input, assign default
    # control location: 'front-end'
    if not specs:
        specs = {}
    # remove 'name' since we will handle that elsewhere.
    if specs.get('name', None):
        del specs['name']
    try:
        if specs['consumer'] not in CONTROL_LOCATION:
            msg = _("Valid consumer of QoS specs are: %s") % CONTROL_LOCATION
            raise exception.InvalidQoSSpecs(reason=msg)
    except KeyError:
        # Default consumer is back-end, i.e Cinder volume service
        if create:
            specs['consumer'] = 'back-end'

    return specs
예제 #3
0
def update(context, qos_specs_id, specs):
    """Update qos specs.

    :param specs: dictionary that contains key/value pairs for updating
                  existing specs.
          e.g. {'consumer': 'front-end',
                'total_iops_sec': 500,
                'total_bytes_sec': 512000,}
    """
    LOG.debug('qos_specs.update(): specs %s', specs)

    try:
        utils.validate_dictionary_string_length(specs)
        qos_spec = objects.QualityOfServiceSpecs.get_by_id(
            context, qos_specs_id)

        if 'consumer' in specs:
            qos_spec.consumer = specs['consumer']
            # If we need to modify specs, copy so we don't cause unintended
            # consequences for the caller
            specs = specs.copy()
            del specs['consumer']

        # Update any values in specs dict
        qos_spec.specs.update(specs)

        qos_spec.save()
    except exception.InvalidInput as e:
        raise exception.InvalidQoSSpecs(reason=e)
    except db_exc.DBError:
        LOG.exception('DB error:')
        raise exception.QoSSpecsUpdateFailed(specs_id=qos_specs_id,
                                             qos_specs=specs)

    return qos_spec
예제 #4
0
def return_qos_specs_update(context, id, specs):
    if id == "777":
        raise exception.QoSSpecsNotFound(specs_id=id)
    elif id == "888":
        raise exception.InvalidQoSSpecs(reason=str(id))
    elif id == "999":
        raise exception.QoSSpecsUpdateFailed(specs_id=id, qos_specs=specs)
    pass
예제 #5
0
def return_qos_specs_update(context, id, specs):
    if id == fake.WILL_NOT_BE_FOUND_ID:
        raise exception.QoSSpecsNotFound(specs_id=id)
    elif id == fake.INVALID_ID:
        raise exception.InvalidQoSSpecs(reason=id)
    elif id == fake.UPDATE_FAILED_ID:
        raise exception.QoSSpecsUpdateFailed(specs_id=id, qos_specs=specs)
    pass
예제 #6
0
def return_qos_specs_create(context, name, specs):
    if name == "666":
        raise exception.QoSSpecsExists(specs_id=name)
    elif name == "555":
        raise exception.QoSSpecsCreateFailed(name=id, qos_specs=specs)
    elif name == "444":
        raise exception.InvalidQoSSpecs(reason=name)
    pass
예제 #7
0
def return_qos_specs_create(context, name, specs):
    if name == 'qos_spec_%s' % fake.ALREADY_EXISTS_ID:
        raise exception.QoSSpecsExists(specs_id=name)
    elif name == 'qos_spec_%s' % fake.ACTION_FAILED_ID:
        raise exception.QoSSpecsCreateFailed(name=id, qos_specs=specs)
    elif name == 'qos_spec_%s' % fake.INVALID_ID:
        raise exception.InvalidQoSSpecs(reason=name)
    pass
예제 #8
0
def get_qos_specs(ctxt, id):
    """Retrieves single qos specs by id."""
    if id is None:
        msg = _("id cannot be None")
        raise exception.InvalidQoSSpecs(reason=msg)

    if ctxt is None:
        ctxt = context.get_admin_context()

    return db.qos_specs_get(ctxt, id)
예제 #9
0
def delete_keys(context, qos_specs_id, keys):
    """Marks specified key of target qos specs as deleted."""
    if qos_specs_id is None:
        msg = _("id cannot be None")
        raise exception.InvalidQoSSpecs(reason=msg)

    # make sure qos_specs_id is valid
    get_qos_specs(context, qos_specs_id)
    for key in keys:
        db.qos_specs_item_delete(context, qos_specs_id, key)
예제 #10
0
def get_qos_specs(ctxt, spec_id):
    """Retrieves single qos specs by id."""
    if spec_id is None:
        msg = _("id cannot be None")
        raise exception.InvalidQoSSpecs(reason=msg)

    if ctxt is None:
        ctxt = context.get_admin_context()

    return objects.QualityOfServiceSpecs.get_by_id(ctxt, spec_id)
예제 #11
0
 def __setattr__(self, name, value):
     try:
         super(QualityOfServiceSpecs, self).__setattr__(name, value)
     except ValueError:
         if name == 'consumer':
             # Give more descriptive error message for invalid 'consumer'
             msg = (_("Valid consumer of QoS specs are: %s") %
                    c_fields.QoSConsumerField())
             raise exception.InvalidQoSSpecs(reason=msg)
         else:
             raise
예제 #12
0
def return_qos_specs_create(context, name, specs):
    if name == 'qos_spec_%s' % fake.ALREADY_EXISTS_ID:
        raise exception.QoSSpecsExists(specs_id=name)
    elif name == 'qos_spec_%s' % fake.ACTION_FAILED_ID:
        raise exception.QoSSpecsCreateFailed(name=id, qos_specs=specs)
    elif name == 'qos_spec_%s' % fake.INVALID_ID:
        raise exception.InvalidQoSSpecs(reason=name)

    return objects.QualityOfServiceSpecs(name=name,
                                         specs=specs,
                                         consumer='back-end',
                                         id=fake.QOS_SPEC_ID)
예제 #13
0
def delete(context, qos_specs_id, force=False):
    """Marks qos specs as deleted.

    'force' parameter is a flag to determine whether should destroy
    should continue when there were entities associated with the qos specs.
    force=True indicates caller would like to mark qos specs as deleted
    even if there was entities associate with target qos specs.
    Trying to delete a qos specs still associated with entities will
    cause QoSSpecsInUse exception if force=False (default).
    """
    if qos_specs_id is None:
        msg = _("id cannot be None")
        raise exception.InvalidQoSSpecs(reason=msg)

    qos_spec = objects.QualityOfServiceSpecs.get_by_id(context, qos_specs_id)

    qos_spec.destroy(force)
예제 #14
0
def delete_keys(context, qos_specs_id, keys):
    """Marks specified key of target qos specs as deleted."""
    if qos_specs_id is None:
        msg = _("id cannot be None")
        raise exception.InvalidQoSSpecs(reason=msg)

    qos_spec = objects.QualityOfServiceSpecs.get_by_id(context, qos_specs_id)

    # Previous behavior continued to delete keys until it hit first unset one,
    # so for now will mimic that. In the future it would be useful to have all
    # or nothing deletion of keys (or at least delete all set keys),
    # especially since order of keys from CLI to API is not preserved currently
    try:
        for key in keys:
            try:
                del qos_spec.specs[key]
            except KeyError:
                raise exception.QoSSpecsKeyNotFound(specs_key=key,
                                                    specs_id=qos_specs_id)
    finally:
        qos_spec.save()
예제 #15
0
def delete(context, qos_specs_id, force=False):
    """Marks qos specs as deleted.

    'force' parameter is a flag to determine whether should destroy
    should continue when there were entities associated with the qos specs.
    force=True indicates caller would like to mark qos specs as deleted
    even if there was entities associate with target qos specs.
    Trying to delete a qos specs still associated with entities will
    cause QoSSpecsInUse exception if force=False (default).
    """
    if qos_specs_id is None:
        msg = _("id cannot be None")
        raise exception.InvalidQoSSpecs(reason=msg)

    # check if there is any entity associated with this qos specs
    res = db.qos_specs_associations_get(context, qos_specs_id)
    if res and not force:
        raise exception.QoSSpecsInUse(specs_id=qos_specs_id)
    elif res and force:
        # remove all association
        db.qos_specs_disassociate_all(context, qos_specs_id)

    db.qos_specs_delete(context, qos_specs_id)