예제 #1
0
    def get_vsa_volume_type(self, context):
        name = FLAGS.vsa_volume_type_name
        try:
            vol_type = volume_types.get_volume_type_by_name(context, name)
        except exception.NotFound:
            volume_types.create(context, name,
                                extra_specs=dict(type='vsa_volume'))
            vol_type = volume_types.get_volume_type_by_name(context, name)

        return vol_type
예제 #2
0
파일: api.py 프로젝트: wendy-king/x7_venv
    def get_vsa_volume_type(self, context):
        name = FLAGS.vsa_volume_type_name
        try:
            vol_type = volume_types.get_volume_type_by_name(context, name)
        except exception.NotFound:
            volume_types.create(context,
                                name,
                                extra_specs=dict(type='vsa_volume'))
            vol_type = volume_types.get_volume_type_by_name(context, name)

        return vol_type
예제 #3
0
    def create(self, req, body):
        """Creates a new volume type."""
        context = req.environ['engine.context']

        if not body or body == "":
            raise exc.HTTPUnprocessableEntity()

        vol_type = body.get('volume_type', None)
        if vol_type is None or vol_type == "":
            raise exc.HTTPUnprocessableEntity()

        name = vol_type.get('name', None)
        specs = vol_type.get('extra_specs', {})

        if name is None or name == "":
            raise exc.HTTPUnprocessableEntity()

        try:
            volume_types.create(context, name, specs)
            vol_type = volume_types.get_volume_type_by_name(context, name)
        except exception.QuotaError as error:
            self._handle_quota_error(error)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        return {'volume_type': vol_type}
예제 #4
0
    def test_volume_type_create_then_purge(self):
        """Ensure volume types can be created and deleted"""
        prev_all_vtypes = volume_types.get_all_types(self.ctxt, inactive=1)

        volume_types.create(self.ctxt,
                            self.vol_type1_name,
                            self.vol_type1_specs)
        new = volume_types.get_volume_type_by_name(self.ctxt,
                                                   self.vol_type1_name)

        for k, v in self.vol_type1_specs.iteritems():
            self.assertEqual(v, new['extra_specs'][k],
                             'one of fields doesnt match')

        new_all_vtypes = volume_types.get_all_types(self.ctxt, inactive=1)
        self.assertEqual(len(prev_all_vtypes) + 1,
                         len(new_all_vtypes),
                         'drive type was not created')

        volume_types.destroy(self.ctxt, self.vol_type1_name)
        new_all_vtypes2 = volume_types.get_all_types(self.ctxt, inactive=1)
        self.assertEqual(len(new_all_vtypes),
                         len(new_all_vtypes2),
                         'drive type was incorrectly deleted')

        volume_types.purge(self.ctxt, self.vol_type1_name)
        new_all_vtypes2 = volume_types.get_all_types(self.ctxt, inactive=1)
        self.assertEqual(len(new_all_vtypes) - 1,
                         len(new_all_vtypes2),
                         'drive type was not purged')
예제 #5
0
    def test_volume_type_create_then_destroy(self):
        """Ensure volume types can be created and deleted"""
        prev_all_vtypes = volume_types.get_all_types(self.ctxt)

        volume_types.create(self.ctxt,
                            self.vol_type1_name,
                            self.vol_type1_specs)
        new = volume_types.get_volume_type_by_name(self.ctxt,
                                                   self.vol_type1_name)

        LOG.info(_("Given data: %s"), self.vol_type1_specs)
        LOG.info(_("Result data: %s"), new)

        for k, v in self.vol_type1_specs.iteritems():
            self.assertEqual(v, new['extra_specs'][k],
                             'one of fields doesnt match')

        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(len(prev_all_vtypes) + 1,
                         len(new_all_vtypes),
                         'drive type was not created')

        volume_types.destroy(self.ctxt, self.vol_type1_name)
        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(prev_all_vtypes,
                         new_all_vtypes,
                         'drive type was not deleted')
예제 #6
0
    def create(self, req, body):
        """Creates a new volume."""
        context = req.environ['engine.context']

        if not body:
            raise exc.HTTPUnprocessableEntity()

        vol = body['volume']
        size = vol['size']
        LOG.audit(_("Create volume of %s GB"), size, context=context)

        vol_type = vol.get('volume_type', None)
        if vol_type:
            try:
                vol_type = volume_types.get_volume_type_by_name(context,
                                                                vol_type)
            except exception.NotFound:
                raise exc.HTTPNotFound()

        metadata = vol.get('metadata', None)

        new_volume = self.volume_api.create(context, size,
                                            vol.get('snapshot_id'),
                                            vol.get('display_name'),
                                            vol.get('display_description'),
                                            volume_type=vol_type,
                                            metadata=metadata)

        # Work around problem that instance is lazy-loaded...
        new_volume = self.volume_api.get(context, new_volume['id'])

        retval = _translate_volume_detail_view(context, new_volume)

        return {'volume': retval}
예제 #7
0
    def create(self, req, body):
        """Creates a new volume."""
        context = req.environ['engine.context']

        if not body:
            raise exc.HTTPUnprocessableEntity()

        vol = body['volume']
        size = vol['size']
        LOG.audit(_("Create volume of %s GB"), size, context=context)

        vol_type = vol.get('volume_type', None)
        if vol_type:
            try:
                vol_type = volume_types.get_volume_type_by_name(
                    context, vol_type)
            except exception.NotFound:
                raise exc.HTTPNotFound()

        metadata = vol.get('metadata', None)

        new_volume = self.volume_api.create(context,
                                            size,
                                            vol.get('snapshot_id'),
                                            vol.get('display_name'),
                                            vol.get('display_description'),
                                            volume_type=vol_type,
                                            metadata=metadata)

        # Work around problem that instance is lazy-loaded...
        new_volume = self.volume_api.get(context, new_volume['id'])

        retval = _translate_volume_detail_view(context, new_volume)

        return {'volume': retval}
예제 #8
0
    def create(self, req, body):
        """Creates a new volume type."""
        context = req.environ['engine.context']

        if not body or body == "":
            raise exc.HTTPUnprocessableEntity()

        vol_type = body.get('volume_type', None)
        if vol_type is None or vol_type == "":
            raise exc.HTTPUnprocessableEntity()

        name = vol_type.get('name', None)
        specs = vol_type.get('extra_specs', {})

        if name is None or name == "":
            raise exc.HTTPUnprocessableEntity()

        try:
            volume_types.create(context, name, specs)
            vol_type = volume_types.get_volume_type_by_name(context, name)
        except exception.QuotaError as error:
            self._handle_quota_error(error)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        return {'volume_type': vol_type}
예제 #9
0
    def _get_vol_creation_request(self, num_vols, drive_ix, size=0):
        volume_params = []
        for i in range(num_vols):

            name = 'name_' + str(i)
            try:
                volume_types.create(self.context, name,
                            extra_specs={'type': 'vsa_drive',
                                         'drive_name': name,
                                         'drive_type': 'type_' + str(drive_ix),
                                         'drive_size': 1 + 100 * (drive_ix)})
                self.created_types_lst.append(name)
            except exception.ApiError:
                # type is already created
                pass

            volume_type = volume_types.get_volume_type_by_name(self.context,
                                                                name)
            volume = {'size': size,
                      'snapshot_id': None,
                      'name': 'vol_' + str(i),
                      'description': None,
                      'volume_type_id': volume_type['id']}
            volume_params.append(volume)

        return {'num_volumes': len(volume_params),
                'vsa_id': 123,
                'volumes': volume_params}
예제 #10
0
    def test_vsa_sched_create_single_volume(self):
        global scheduled_volume
        scheduled_volume = {}
        self._set_service_states(host_num=10,
                                 drive_type_start_ix=0,
                                 drive_type_num=5,
                                 init_num_drives=10,
                                 exclude_host_list=['host_0', 'host_1'])
        prev = self._generate_default_service_states()

        global global_volume
        global_volume = {}

        drive_ix = 2
        name = 'name_' + str(drive_ix)
        volume_types.create(self.context, name,
                    extra_specs={'type': 'vsa_drive',
                                 'drive_name': name,
                                 'drive_type': 'type_' + str(drive_ix),
                                 'drive_size': 1 + 100 * (drive_ix)})
        self.created_types_lst.append(name)
        volume_type = volume_types.get_volume_type_by_name(self.context, name)

        global_volume['volume_type_id'] = volume_type['id']
        global_volume['size'] = 0

        self.sched.schedule_create_volume(self.context,
                123, availability_zone=None)

        self.assertEqual(scheduled_volume['id'], 123)
        self.assertEqual(scheduled_volume['host'], 'host_9')
예제 #11
0
파일: api.py 프로젝트: wendy-king/x7_venv
    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:
                raise exception.ApiError(
                    _("No drive_name param found in %s") % node)
            try:
                vol_type = volume_types.get_volume_type_by_name(context, name)
            except exception.NotFound:
                raise exception.ApiError(
                    _("Invalid drive type name %s") % 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
예제 #12
0
    def test_volume_type_get_by_id_and_name(self):
        """Ensure volume types get returns same entry"""
        volume_types.create(self.ctxt,
                            self.vol_type1_name,
                            self.vol_type1_specs)
        new = volume_types.get_volume_type_by_name(self.ctxt,
                                                   self.vol_type1_name)

        new2 = volume_types.get_volume_type(self.ctxt, new['id'])
        self.assertEqual(new, new2)
예제 #13
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:
                raise exception.ApiError(_("No drive_name param found in %s")
                                            % node)
            try:
                vol_type = volume_types.get_volume_type_by_name(context, name)
            except exception.NotFound:
                raise exception.ApiError(_("Invalid drive type name %s")
                                            % 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