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
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
def _create(self, req, body): """Creates a new volume type.""" context = req.environ['nova.context'] authorize(context) if not body or body == "": raise webob.exc.HTTPUnprocessableEntity() vol_type = body.get('volume_type', None) if vol_type is None or vol_type == "": raise webob.exc.HTTPUnprocessableEntity() name = vol_type.get('name', None) specs = vol_type.get('extra_specs', {}) if name is None or name == "": raise webob.exc.HTTPUnprocessableEntity() try: volume_types.create(context, name, specs) vol_type = volume_types.get_volume_type_by_name(context, name) except exception.VolumeTypeExists as err: raise webob.exc.HTTPConflict(explanation=str(err)) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, vol_type)
def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.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}
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.elevated(), 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 }
def _create(self, req, body): """Creates a new volume type.""" context = req.environ['nova.context'] authorize(context) if not body or body == "": raise webob.exc.HTTPUnprocessableEntity() vol_type = body.get('volume_type', None) if vol_type is None or vol_type == "": raise webob.exc.HTTPUnprocessableEntity() name = vol_type.get('name', None) specs = vol_type.get('extra_specs', {}) if name is None or name == "": raise webob.exc.HTTPUnprocessableEntity() try: volume_types.create(context, name, specs) vol_type = volume_types.get_volume_type_by_name(context, name) except exception.VolumeTypeExists as err: raise webob.exc.HTTPConflict(explanation=str(err)) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, vol_type)
def create(self, req, body): context = req.environ['nova.context'] vol = body['volume'] 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: return faults.Fault(exc.HTTPNotFound()) metadata = vol.get('metadata', None) new_volume = self.local_volume_api.create_local(context, instance_id=vol['instance_id'], snapshot_id=vol.get('snapshot_id'), device=vol['device'], size=self._get_size(vol.get('size')), description=vol.get('display_description'), volume_type=vol_type, metadata=metadata) new_volume = self.local_volume_api.get(context, new_volume['id']) retval = _translate_volume_detail_view(new_volume) return {'volume': retval}
def create(self, req, body): """Creates a new volume type.""" context = req.environ['nova.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}
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')
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')
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)
def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.context'] if not body: return faults.Fault(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: return faults.Fault(exc.HTTPNotFound()) metadata = vol.get('metadata', None) new_volume = self.volume_api.create(context, size, None, 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}
def create(self, req, body): """Creates a new volume type.""" context = req.environ['nova.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}
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.elevated(), 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.driver.schedule_create_volume(self.context, 123, availability_zone=None) self.assertEqual(scheduled_volume['id'], 123) self.assertEqual(scheduled_volume['host'], 'host_9')
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')
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.elevated(), 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.driver.schedule_create_volume(self.context, 123, availability_zone=None) self.assertEqual(scheduled_volume['id'], 123) self.assertEqual(scheduled_volume['host'], 'host_9')
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.elevated(), 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.VolumeTypeExists: # 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}
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')
def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.context'] if not body: raise exc.HTTPUnprocessableEntity() volume = body['volume'] def as_int(s): try: return int(s) except ValueError: return s # NOTE(eglynn): we're tolerant of non-int sizes here, as type # integrity is enforced later in the creation codepath size = as_int(volume['size']) LOG.audit(_("Create volume of %s GB"), size, context=context) kwargs = {} req_volume_type = volume.get('volume_type', None) if req_volume_type: try: kwargs['volume_type'] = volume_types.get_volume_type_by_name( context, req_volume_type) except exception.NotFound: raise exc.HTTPNotFound() kwargs['metadata'] = volume.get('metadata', None) snapshot_id = volume.get('snapshot_id') if snapshot_id is not None: kwargs['snapshot'] = self.volume_api.get_snapshot(context, snapshot_id) else: kwargs['snapshot'] = None kwargs['availability_zone'] = volume.get('availability_zone', None) new_volume = self.volume_api.create(context, size, volume.get('display_name'), volume.get('display_description'), **kwargs) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume)) result = {'volume': retval} location = '%s/%s' % (req.url, new_volume['id']) return wsgi.ResponseObject(result, headers=dict(location=location))
def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.context'] if not body: raise exc.HTTPUnprocessableEntity() volume = body['volume'] def as_int(s): try: return int(s) except ValueError: return s # NOTE(eglynn): we're tolerant of non-int sizes here, as type # integrity is enforced later in the creation codepath size = as_int(volume['size']) LOG.audit(_("Create volume of %s GB"), size, context=context) kwargs = {} req_volume_type = volume.get('volume_type', None) if req_volume_type: try: kwargs['volume_type'] = volume_types.get_volume_type_by_name( context, req_volume_type) except exception.NotFound: raise exc.HTTPNotFound() kwargs['metadata'] = volume.get('metadata', None) snapshot_id = volume.get('snapshot_id') if snapshot_id is not None: kwargs['snapshot'] = self.volume_api.get_snapshot( context, snapshot_id) else: kwargs['snapshot'] = None kwargs['availability_zone'] = volume.get('availability_zone', None) new_volume = self.volume_api.create(context, size, volume.get('display_name'), volume.get('display_description'), **kwargs) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume)) result = {'volume': retval} location = '%s/%s' % (req.url, new_volume['id']) return wsgi.ResponseObject(result, headers=dict(location=location))
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)
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
def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.context'] authorize(context) if not self.is_valid_body(body, 'volume'): raise exc.HTTPUnprocessableEntity() vol = body['volume'] 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) snapshot_id = vol.get('snapshot_id') if snapshot_id is not None: snapshot = self.volume_api.get_snapshot(context, snapshot_id) else: snapshot = None size = vol.get('size', None) if size is None and snapshot is not None: size = snapshot['volume_size'] LOG.audit(_("Create volume of %s GB"), size, context=context) availability_zone = vol.get('availability_zone', None) new_volume = self.volume_api.create(context, size, vol.get('display_name'), vol.get('display_description'), snapshot=snapshot, volume_type=vol_type, metadata=metadata, availability_zone=availability_zone ) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume)) result = {'volume': retval} location = '%s/%s' % (req.url, new_volume['id']) return wsgi.ResponseObject(result, headers=dict(location=location))
def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.context'] authorize(context) if not self.is_valid_body(body, 'volume'): raise exc.HTTPUnprocessableEntity() vol = body['volume'] 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) snapshot_id = vol.get('snapshot_id') if snapshot_id is not None: snapshot = self.volume_api.get_snapshot(context, snapshot_id) else: snapshot = None size = vol.get('size', None) if size is None and snapshot is not None: size = snapshot['volume_size'] LOG.audit(_("Create volume of %s GB"), size, context=context) availability_zone = vol.get('availability_zone', None) new_volume = self.volume_api.create(context, size, vol.get('display_name'), vol.get('display_description'), snapshot=snapshot, volume_type=vol_type, metadata=metadata, availability_zone=availability_zone ) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume)) result = {'volume': retval} location = '%s/%s' % (req.url, new_volume['id']) return wsgi.ResponseObject(result, headers=dict(location=location))
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
def create(self, req, body): """Creates a new volume.""" context = req.environ["nova.context"] authorize(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) snapshot_id = vol.get("snapshot_id") if snapshot_id is not None: snapshot = self.volume_api.get_snapshot(context, snapshot_id) else: snapshot = None availability_zone = vol.get("availability_zone", None) new_volume = self.volume_api.create( context, size, vol.get("display_name"), vol.get("display_description"), snapshot=snapshot, volume_type=vol_type, metadata=metadata, availability_zone=availability_zone, ) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume)) result = {"volume": retval} location = "%s/%s" % (req.url, new_volume["id"]) return wsgi.ResponseObject(result, headers=dict(location=location))
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
def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.context'] if not body: raise exc.HTTPUnprocessableEntity() volume = body['volume'] size = volume['size'] LOG.audit(_("Create volume of %s GB"), size, context=context) kwargs = {} req_volume_type = volume.get('volume_type', None) if req_volume_type: try: kwargs['volume_type'] = volume_types.get_volume_type_by_name( context, req_volume_type) except exception.NotFound: raise exc.HTTPNotFound() kwargs['metadata'] = volume.get('metadata', None) snapshot_id = volume.get('snapshot_id') if snapshot_id is not None: kwargs['snapshot'] = self.volume_api.get_snapshot(context, snapshot_id) else: kwargs['snapshot'] = None kwargs['availability_zone'] = volume.get('availability_zone', None) new_volume = self.volume_api.create(context, size, volume.get('display_name'), volume.get('display_description'), **kwargs) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume)) return {'volume': retval}
def create(self, req, body): """Creates a new volume.""" context = req.environ["nova.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) snapshot_id = vol.get("snapshot_id") if snapshot_id is not None: snapshot = self.volume_api.get_snapshot(context, snapshot_id) else: snapshot = None new_volume = self.volume_api.create( context, size, vol.get("display_name"), vol.get("display_description"), snapshot=snapshot, 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}
def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.context'] if not body: raise exc.HTTPUnprocessableEntity() volume = body['volume'] size = volume['size'] LOG.audit(_("Create volume of %s GB"), size, context=context) kwargs = {} req_volume_type = volume.get('volume_type', None) if req_volume_type: try: kwargs['volume_type'] = volume_types.get_volume_type_by_name( context, req_volume_type) except exception.NotFound: raise exc.HTTPNotFound() kwargs['metadata'] = volume.get('metadata', None) snapshot_id = volume.get('snapshot_id') if snapshot_id is not None: snapshot = self.volume_api.get_snapshot(context, snapshot_id) else: snapshot = None new_volume = self.volume_api.create(context, size, snapshot, volume.get('display_name'), volume.get('display_description'), **kwargs) # 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}
def create(self, req, body): """Creates a new volume type.""" context = req.environ['nova.context'] authorize(context) if not self.is_valid_body(body, 'volume_type'): raise exc.HTTPUnprocessableEntity() vol_type = body['volume_type'] 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.NotFound: raise exc.HTTPNotFound() return {'volume_type': vol_type}
def create(self, req, body): """Creates a new volume.""" if not self.is_valid_body(body, 'volume'): msg = _("Invalid request body. 'volume' not found") raise exc.HTTPUnprocessableEntity(explanation=msg) context = req.environ['nova.context'] volume = body['volume'] kwargs = {} req_volume_type = volume.get('volume_type', None) if req_volume_type: try: kwargs['volume_type'] = volume_types.get_volume_type_by_name( context, req_volume_type) except exception.NotFound: raise exc.HTTPNotFound() kwargs['metadata'] = volume.get('metadata', None) snapshot_id = volume.get('snapshot_id') if snapshot_id is not None: kwargs['snapshot'] = self.volume_api.get_snapshot(context, snapshot_id) else: kwargs['snapshot'] = None size = volume.get('size', None) if size is None and kwargs['snapshot'] is not None: size = kwargs['snapshot']['volume_size'] if size is None: msg = _("Invalid request body. 'size' not found") raise exc.HTTPUnprocessableEntity(explanation=msg) LOG.audit(_("Create volume of %s GB"), size, context=context) image_href = None image_uuid = None if self.ext_mgr.is_loaded('os-image-create'): image_href = volume.get('imageRef') if snapshot_id and image_href: msg = _("Snapshot and image cannot be specified together.") raise exc.HTTPBadRequest(explanation=msg) if image_href: image_uuid = self._image_uuid_from_href(image_href) kwargs['image_id'] = image_uuid kwargs['availability_zone'] = volume.get('availability_zone', None) new_volume = self.volume_api.create(context, size, volume.get('display_name'), volume.get('display_description'), **kwargs) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume), image_uuid) result = {'volume': retval} location = '%s/%s' % (req.url, new_volume['id']) return wsgi.ResponseObject(result, headers=dict(location=location))
def create(self, req, body): """Creates a new volume.""" if not self.is_valid_body(body, 'volume'): raise exc.HTTPUnprocessableEntity() context = req.environ['nova.context'] volume = body['volume'] kwargs = {} req_volume_type = volume.get('volume_type', None) if req_volume_type: try: kwargs['volume_type'] = volume_types.get_volume_type_by_name( context, req_volume_type) except exception.NotFound: raise exc.HTTPNotFound() kwargs['metadata'] = volume.get('metadata', None) snapshot_id = volume.get('snapshot_id') if snapshot_id is not None: kwargs['snapshot'] = self.volume_api.get_snapshot( context, snapshot_id) else: kwargs['snapshot'] = None size = volume.get('size', None) if size is None and kwargs['snapshot'] is not None: size = kwargs['snapshot']['volume_size'] LOG.audit(_("Create volume of %s GB"), size, context=context) image_href = None image_uuid = None if self.ext_mgr.is_loaded('os-image-create'): image_href = volume.get('imageRef') if snapshot_id and image_href: msg = _("Snapshot and image cannot be specified together.") raise exc.HTTPBadRequest(explanation=msg) if image_href: image_uuid = self._image_uuid_from_href(image_href) kwargs['image_id'] = image_uuid kwargs['availability_zone'] = volume.get('availability_zone', None) new_volume = self.volume_api.create(context, size, volume.get('display_name'), volume.get('display_description'), **kwargs) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume), image_uuid) result = {'volume': retval} location = '%s/%s' % (req.url, new_volume['id']) return wsgi.ResponseObject(result, headers=dict(location=location))