예제 #1
0
    def _check_storage_parameters(self,
                                  context,
                                  vsa_name,
                                  storage,
                                  shared,
                                  first_index=0):
        """
        Translates storage array of disks to the list of volumes
        :param storage: List of dictionaries with following keys:
                        disk_name, num_disks, size
        :param shared: Specifies if storage is dedicated or shared.
                       For shared storage disks split into partitions
        """
        volume_params = []
        for node in storage:

            name = node.get('drive_name', None)
            num_disks = node.get('num_drives', 1)

            if name is None:
                msg = _("drive_name not defined")
                raise exception.InvalidVolumeType(reason=msg)

            try:
                vol_type = volume_types.get_volume_type_by_name(context, name)
            except exception.NotFound:
                msg = _("invalid drive type name %s")
                raise exception.InvalidVolumeType(reason=msg % name)

            self._check_volume_type_correctness(vol_type)

            # if size field present - override disk size specified in DB
            size = int(
                node.get('size', vol_type['extra_specs'].get('drive_size')))

            if shared:
                part_size = FLAGS.vsa_part_size_gb
                total_capacity = num_disks * size
                num_volumes = total_capacity / part_size
                size = part_size
            else:
                num_volumes = num_disks
                size = 0  # special handling for full drives

            for i in range(num_volumes):
                volume_name = "drive-%03d" % first_index
                first_index += 1
                volume_desc = 'BE volume for VSA %s type %s' % (vsa_name, name)
                volume = {
                    'size': size,
                    'name': volume_name,
                    'description': volume_desc,
                    'volume_type_id': vol_type['id'],
                }
                volume_params.append(volume)

        return volume_params
예제 #2
0
def destroy(context, name):
    """Marks volume types as deleted."""
    if name is None:
        msg = _("name cannot be None")
        raise exception.InvalidVolumeType(reason=msg)
    else:
        db.volume_type_destroy(context, name)
예제 #3
0
def get_volume_type_by_name(context, name):
    """Retrieves single volume type by name."""
    if name is None:
        msg = _("name cannot be None")
        raise exception.InvalidVolumeType(reason=msg)

    return db.volume_type_get_by_name(context, name)
예제 #4
0
    def _check_volume_type_correctness(self, vol_type):
        if (vol_type.get('extra_specs') is None
                or vol_type['extra_specs'].get('type') != 'vsa_drive'
                or vol_type['extra_specs'].get('drive_type') is None
                or vol_type['extra_specs'].get('drive_size') is None):

            msg = _("invalid drive data")
            raise exception.InvalidVolumeType(reason=msg)
예제 #5
0
def get_volume_type_by_name(context, name):
    """Retrieves single volume type by name."""
    if name is None:
        raise exception.InvalidVolumeType(volume_type=name)

    try:
        return db.volume_type_get_by_name(context, name)
    except exception.DBError:
        raise exception.ApiError(_("Unknown volume type: %s") % name)
예제 #6
0
def get_volume_type(ctxt, id):
    """Retrieves single volume type by id."""
    if id is None:
        msg = _("id cannot be None")
        raise exception.InvalidVolumeType(reason=msg)

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

    return db.volume_type_get(ctxt, id)
예제 #7
0
def purge(context, name):
    """Removes volume types from database."""
    if name is None:
        raise exception.InvalidVolumeType(volume_type=name)
    else:
        try:
            db.volume_type_purge(context, name)
        except exception.NotFound:
            LOG.exception(_('Volume type %s not found for purge') % name)
            raise exception.ApiError(_("Unknown volume type: %s") % name)
예제 #8
0
def destroy(context, name):
    """Marks volume types as deleted."""
    if name is None:
        raise exception.InvalidVolumeType(volume_type=name)
    else:
        try:
            db.volume_type_destroy(context, name)
        except exception.NotFound:
            LOG.exception(_('Volume type %s not found for deletion') % name)
            raise exception.ApiError(_("Unknown volume type: %s") % name)
예제 #9
0
def get_volume_type(ctxt, id):
    """Retrieves single volume type by id."""
    if id is None:
        raise exception.InvalidVolumeType(volume_type=id)

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

    try:
        return db.volume_type_get(ctxt, id)
    except exception.DBError:
        raise exception.ApiError(_("Unknown volume type: %s") % id)