def test_provision_filter_on_size(self): share_types.create(self.context, "type1", extra_specs={ "key1": "val1", "key2": "val2", "driver_handles_share_servers": False}) share_types.create(self.context, "type2", extra_specs={ share_types.MIN_SIZE_KEY: "12", "key3": "val3", "driver_handles_share_servers": False}) share_types.create(self.context, "type3", extra_specs={ share_types.MAX_SIZE_KEY: "99", "key4": "val4", "driver_handles_share_servers": False}) share_types.create(self.context, "type4", extra_specs={ share_types.MIN_SIZE_KEY: "24", share_types.MAX_SIZE_KEY: "99", "key4": "val4", "driver_handles_share_servers": False}) # Make sure we don't raise if there are no min/max set type1 = share_types.get_share_type_by_name(self.context, 'type1') share_types.provision_filter_on_size(self.context, type1, "11") # verify minimum size requirements type2 = share_types.get_share_type_by_name(self.context, 'type2') self.assertRaises(exception.InvalidInput, share_types.provision_filter_on_size, self.context, type2, "11") share_types.provision_filter_on_size(self.context, type2, "12") share_types.provision_filter_on_size(self.context, type2, "100") # verify max size requirements type3 = share_types.get_share_type_by_name(self.context, 'type3') self.assertRaises(exception.InvalidInput, share_types.provision_filter_on_size, self.context, type3, "100") share_types.provision_filter_on_size(self.context, type3, "99") share_types.provision_filter_on_size(self.context, type3, "1") # verify min and max type4 = share_types.get_share_type_by_name(self.context, 'type4') self.assertRaises(exception.InvalidInput, share_types.provision_filter_on_size, self.context, type4, "20") self.assertRaises(exception.InvalidInput, share_types.provision_filter_on_size, self.context, type4, "100") share_types.provision_filter_on_size(self.context, type4, "24") share_types.provision_filter_on_size(self.context, type4, "99") share_types.provision_filter_on_size(self.context, type4, "30")
def _create(self, req, body, set_defaults=False): """Creates a new share type.""" context = req.environ['manila.context'] if (not self.is_valid_body(body, 'share_type') and not self.is_valid_body(body, 'volume_type')): raise webob.exc.HTTPBadRequest() elif self.is_valid_body(body, 'share_type'): share_type = body['share_type'] else: share_type = body['volume_type'] name = share_type.get('name') specs = share_type.get('extra_specs', {}) is_public = share_type.get( 'os-share-type-access:is_public', share_type.get('share_type_access:is_public', True), ) if name is None or name == "" or len(name) > 255: msg = _("Type name is not valid.") raise webob.exc.HTTPBadRequest(explanation=msg) # Note(cknight): Set the default extra spec value for snapshot_support # for API versions before it was required. if set_defaults: if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in specs: specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = True try: required_extra_specs = ( share_types.get_valid_required_extra_specs(specs) ) share_types.create(context, name, specs, is_public) share_type = share_types.get_share_type_by_name(context, name) share_type['required_extra_specs'] = required_extra_specs req.cache_db_share_type(share_type) notifier_info = dict(share_types=share_type) rpc.get_notifier('shareType').info( context, 'share_type.create', notifier_info) except exception.InvalidExtraSpec as e: raise webob.exc.HTTPBadRequest(explanation=six.text_type(e)) except exception.ShareTypeExists as err: notifier_err = dict(share_types=share_type, error_message=six.text_type(err)) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.NotFound as err: notifier_err = dict(share_types=share_type, error_message=six.text_type(err)) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_type)
def _create(self, req, body, set_defaults=False): """Creates a new share type.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share_type') and \ not self.is_valid_body(body, 'volume_type'): raise webob.exc.HTTPBadRequest() elif self.is_valid_body(body, 'share_type'): share_type = body['share_type'] else: share_type = body['volume_type'] name = share_type.get('name') specs = share_type.get('extra_specs', {}) is_public = share_type.get( 'os-share-type-access:is_public', share_type.get('share_type_access:is_public', True), ) if name is None or name == "" or len(name) > 255: msg = _("Type name is not valid.") raise webob.exc.HTTPBadRequest(explanation=msg) # Note(cknight): Set the default extra spec value for snapshot_support # for API versions before it was required. if set_defaults: if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in specs: specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = True try: required_extra_specs = ( share_types.get_valid_required_extra_specs(specs) ) share_types.create(context, name, specs, is_public) share_type = share_types.get_share_type_by_name(context, name) share_type['required_extra_specs'] = required_extra_specs req.cache_db_share_type(share_type) notifier_info = dict(share_types=share_type) rpc.get_notifier('shareType').info( context, 'share_type.create', notifier_info) except exception.InvalidExtraSpec as e: raise webob.exc.HTTPBadRequest(explanation=six.text_type(e)) except exception.ShareTypeExists as err: notifier_err = dict(share_types=share_type, error_message=six.text_type(err)) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.NotFound as err: notifier_err = dict(share_types=share_type, error_message=six.text_type(err)) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_type)
def _create(self, req, body): """Creates a new share type.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share_type') and \ not self.is_valid_body(body, 'volume_type'): raise webob.exc.HTTPBadRequest() elif self.is_valid_body(body, 'share_type'): share_type = body['share_type'] else: share_type = body['volume_type'] name = share_type.get('name', None) specs = share_type.get('extra_specs', {}) is_public = share_type.get( 'os-share-type-access:is_public', share_type.get('share_type_access:is_public', True), ) if name is None or name == "" or len(name) > 255: msg = _("Type name is not valid.") raise webob.exc.HTTPBadRequest(explanation=msg) try: required_extra_specs = ( share_types.get_valid_required_extra_specs(specs) ) except exception.InvalidExtraSpec as e: raise webob.exc.HTTPBadRequest(explanation=six.text_type(e)) try: share_types.create(context, name, specs, is_public) share_type = share_types.get_share_type_by_name(context, name) share_type['required_extra_specs'] = required_extra_specs req.cache_db_share_type(share_type) notifier_info = dict(share_types=share_type) rpc.get_notifier('shareType').info( context, 'share_type.create', notifier_info) except exception.ShareTypeExists as err: notifier_err = dict(share_types=share_type, error_message=six.text_type(err)) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.NotFound as err: notifier_err = dict(share_types=share_type, error_message=six.text_type(err)) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_type)
def _create(self, req, body): """Creates a new share.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share'): raise exc.HTTPUnprocessableEntity() share = body['share'] # NOTE(rushiagr): Manila API allows 'name' instead of 'display_name'. if share.get('name'): share['display_name'] = share.get('name') del share['name'] # NOTE(rushiagr): Manila API allows 'description' instead of # 'display_description'. if share.get('description'): share['display_description'] = share.get('description') del share['description'] size = share['size'] share_proto = share['share_proto'].upper() msg = (_LI("Create %(share_proto)s share of %(size)s GB") % {'share_proto': share_proto, 'size': size}) LOG.info(msg, context=context) availability_zone = share.get('availability_zone') if availability_zone: try: db.availability_zone_get(context, availability_zone) except exception.AvailabilityZoneNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) kwargs = { 'availability_zone': availability_zone, 'metadata': share.get('metadata'), 'is_public': share.get('is_public', False), 'consistency_group_id': share.get('consistency_group_id') } snapshot_id = share.get('snapshot_id') if snapshot_id: snapshot = self.share_api.get_snapshot(context, snapshot_id) else: snapshot = None kwargs['snapshot'] = snapshot share_network_id = share.get('share_network_id') if snapshot: # Need to check that share_network_id from snapshot's # parents share equals to share_network_id from args. # If share_network_id is empty than update it with # share_network_id of parent share. parent_share = self.share_api.get(context, snapshot['share_id']) parent_share_net_id = parent_share['share_network_id'] if share_network_id: if share_network_id != parent_share_net_id: msg = "Share network ID should be the same as snapshot's" \ " parent share's or empty" raise exc.HTTPBadRequest(explanation=msg) elif parent_share_net_id: share_network_id = parent_share_net_id if share_network_id: try: self.share_api.get_share_network( context, share_network_id) except exception.ShareNetworkNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) kwargs['share_network_id'] = share_network_id display_name = share.get('display_name') display_description = share.get('display_description') if 'share_type' in share and 'volume_type' in share: msg = 'Cannot specify both share_type and volume_type' raise exc.HTTPBadRequest(explanation=msg) req_share_type = share.get('share_type', share.get('volume_type')) if req_share_type: try: if not uuidutils.is_uuid_like(req_share_type): kwargs['share_type'] = \ share_types.get_share_type_by_name( context, req_share_type) else: kwargs['share_type'] = share_types.get_share_type( context, req_share_type) except exception.ShareTypeNotFound: msg = _("Share type not found.") raise exc.HTTPNotFound(explanation=msg) elif not snapshot: def_share_type = share_types.get_default_share_type() if def_share_type: kwargs['share_type'] = def_share_type new_share = self.share_api.create(context, share_proto, size, display_name, display_description, **kwargs) return self._view_builder.detail(req, dict(six.iteritems(new_share)))
def _create(self, req, body, check_create_share_from_snapshot_support=False): """Creates a new share.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share'): raise exc.HTTPUnprocessableEntity() share = body['share'] availability_zone_id = None # NOTE(rushiagr): Manila API allows 'name' instead of 'display_name'. if share.get('name'): share['display_name'] = share.get('name') del share['name'] # NOTE(rushiagr): Manila API allows 'description' instead of # 'display_description'. if share.get('description'): share['display_description'] = share.get('description') del share['description'] size = share['size'] share_proto = share['share_proto'].upper() msg = ("Create %(share_proto)s share of %(size)s GB" % { 'share_proto': share_proto, 'size': size }) LOG.info(msg, context=context) availability_zone = share.get('availability_zone') if availability_zone: try: availability_zone_id = db.availability_zone_get( context, availability_zone).id except exception.AvailabilityZoneNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) share_group_id = share.get('share_group_id') if share_group_id: try: share_group = db.share_group_get(context, share_group_id) except exception.ShareGroupNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) sg_az_id = share_group['availability_zone_id'] if availability_zone and availability_zone_id != sg_az_id: msg = _("Share cannot have AZ ('%(s_az)s') different than " "share group's one (%(sg_az)s).") % { 's_az': availability_zone_id, 'sg_az': sg_az_id } raise exception.InvalidInput(msg) availability_zone_id = sg_az_id kwargs = { 'availability_zone': availability_zone_id, 'metadata': share.get('metadata'), 'is_public': share.get('is_public', False), 'share_group_id': share_group_id, } snapshot_id = share.get('snapshot_id') if snapshot_id: snapshot = self.share_api.get_snapshot(context, snapshot_id) else: snapshot = None kwargs['snapshot_id'] = snapshot_id share_network_id = share.get('share_network_id') if snapshot: # Need to check that share_network_id from snapshot's # parents share equals to share_network_id from args. # If share_network_id is empty then update it with # share_network_id of parent share. parent_share = self.share_api.get(context, snapshot['share_id']) parent_share_net_id = parent_share.instance['share_network_id'] if share_network_id: if share_network_id != parent_share_net_id: msg = ("Share network ID should be the same as snapshot's" " parent share's or empty") raise exc.HTTPBadRequest(explanation=msg) elif parent_share_net_id: share_network_id = parent_share_net_id # Verify that share can be created from a snapshot if (check_create_share_from_snapshot_support and not parent_share['create_share_from_snapshot_support']): msg = (_("A new share may not be created from snapshot '%s', " "because the snapshot's parent share does not have " "that capability.") % snapshot_id) LOG.error(msg) raise exc.HTTPBadRequest(explanation=msg) if share_network_id: try: self.share_api.get_share_network(context, share_network_id) except exception.ShareNetworkNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) kwargs['share_network_id'] = share_network_id display_name = share.get('display_name') display_description = share.get('display_description') if 'share_type' in share and 'volume_type' in share: msg = 'Cannot specify both share_type and volume_type' raise exc.HTTPBadRequest(explanation=msg) req_share_type = share.get('share_type', share.get('volume_type')) share_type = None if req_share_type: try: if not uuidutils.is_uuid_like(req_share_type): share_type = share_types.get_share_type_by_name( context, req_share_type) else: share_type = share_types.get_share_type( context, req_share_type) except exception.ShareTypeNotFound: msg = _("Share type not found.") raise exc.HTTPNotFound(explanation=msg) elif not snapshot: def_share_type = share_types.get_default_share_type() if def_share_type: share_type = def_share_type # Only use in create share feature. Create share from snapshot # and create share with share group features not # need this check. if (not share_network_id and not snapshot and not share_group_id and share_type and share_type.get('extra_specs') and (strutils.bool_from_string( share_type.get('extra_specs').get( 'driver_handles_share_servers')))): msg = _('Share network must be set when the ' 'driver_handles_share_servers is true.') raise exc.HTTPBadRequest(explanation=msg) if share_type: kwargs['share_type'] = share_type new_share = self.share_api.create(context, share_proto, size, display_name, display_description, **kwargs) return self._view_builder.detail(req, new_share)
def create(self, req, body): """Creates a new share.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share'): raise exc.HTTPUnprocessableEntity() share = body['share'] # NOTE(rushiagr): v2 API allows name instead of display_name if share.get('name'): share['display_name'] = share.get('name') del share['name'] # NOTE(rushiagr): v2 API allows description instead of # display_description if share.get('description'): share['display_description'] = share.get('description') del share['description'] size = share['size'] share_proto = share['share_proto'].upper() msg = (_LI("Create %(share_proto)s share of %(size)s GB") % { 'share_proto': share_proto, 'size': size }) LOG.info(msg, context=context) kwargs = { 'availability_zone': share.get('availability_zone'), 'metadata': share.get('metadata'), 'is_public': share.get('is_public', False), } snapshot_id = share.get('snapshot_id') if snapshot_id: snapshot = self.share_api.get_snapshot(context, snapshot_id) else: snapshot = None kwargs['snapshot'] = snapshot share_network_id = share.get('share_network_id') if snapshot: # Need to check that share_network_id from snapshot's # parents share equals to share_network_id from args. # If share_network_id is empty than update it with # share_network_id of parent share. parent_share = self.share_api.get(context, snapshot['share_id']) parent_share_net_id = parent_share['share_network_id'] if share_network_id: if share_network_id != parent_share_net_id: msg = "Share network ID should be the same as snapshot's" \ " parent share's or empty" raise exc.HTTPBadRequest(explanation=msg) elif parent_share_net_id: share_network_id = parent_share_net_id if share_network_id: try: self.share_api.get_share_network(context, share_network_id) except exception.ShareNetworkNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) kwargs['share_network_id'] = share_network_id display_name = share.get('display_name') display_description = share.get('display_description') if 'share_type' in share and 'volume_type' in share: msg = 'Cannot specify both share_type and volume_type' raise exc.HTTPBadRequest(explanation=msg) req_share_type = share.get('share_type', share.get('volume_type')) if req_share_type: try: if not uuidutils.is_uuid_like(req_share_type): kwargs['share_type'] = \ share_types.get_share_type_by_name( context, req_share_type) else: kwargs['share_type'] = share_types.get_share_type( context, req_share_type) except exception.ShareTypeNotFound: msg = _("Share type not found.") raise exc.HTTPNotFound(explanation=msg) elif not snapshot: def_share_type = share_types.get_default_share_type() if def_share_type: kwargs['share_type'] = def_share_type new_share = self.share_api.create(context, share_proto, size, display_name, display_description, **kwargs) return self._view_builder.detail(req, dict(six.iteritems(new_share)))
def _create(self, req, body, check_create_share_from_snapshot_support=False, check_availability_zones_extra_spec=False): """Creates a new share.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share'): raise exc.HTTPUnprocessableEntity() share = body['share'] share = common.validate_public_share_policy(context, share) # NOTE(rushiagr): Manila API allows 'name' instead of 'display_name'. if share.get('name'): share['display_name'] = share.get('name') del share['name'] # NOTE(rushiagr): Manila API allows 'description' instead of # 'display_description'. if share.get('description'): share['display_description'] = share.get('description') del share['description'] size = share['size'] share_proto = share['share_proto'].upper() msg = ("Create %(share_proto)s share of %(size)s GB" % {'share_proto': share_proto, 'size': size}) LOG.info(msg, context=context) availability_zone_id = None availability_zone = share.get('availability_zone') if availability_zone: try: availability_zone_id = db.availability_zone_get( context, availability_zone).id except exception.AvailabilityZoneNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) share_group_id = share.get('share_group_id') if share_group_id: try: share_group = db.share_group_get(context, share_group_id) except exception.ShareGroupNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) sg_az_id = share_group['availability_zone_id'] if availability_zone and availability_zone_id != sg_az_id: msg = _("Share cannot have AZ ('%(s_az)s') different than " "share group's one (%(sg_az)s).") % { 's_az': availability_zone_id, 'sg_az': sg_az_id} raise exception.InvalidInput(msg) availability_zone_id = sg_az_id kwargs = { 'availability_zone': availability_zone_id, 'metadata': share.get('metadata'), 'is_public': share.get('is_public', False), 'share_group_id': share_group_id, } snapshot_id = share.get('snapshot_id') if snapshot_id: snapshot = self.share_api.get_snapshot(context, snapshot_id) else: snapshot = None kwargs['snapshot_id'] = snapshot_id share_network_id = share.get('share_network_id') parent_share_type = {} if snapshot: # Need to check that share_network_id from snapshot's # parents share equals to share_network_id from args. # If share_network_id is empty then update it with # share_network_id of parent share. parent_share = self.share_api.get(context, snapshot['share_id']) parent_share_net_id = parent_share.instance['share_network_id'] parent_share_type = share_types.get_share_type( context, parent_share.instance['share_type_id']) if share_network_id: if share_network_id != parent_share_net_id: msg = ("Share network ID should be the same as snapshot's" " parent share's or empty") raise exc.HTTPBadRequest(explanation=msg) elif parent_share_net_id: share_network_id = parent_share_net_id # Verify that share can be created from a snapshot if (check_create_share_from_snapshot_support and not parent_share['create_share_from_snapshot_support']): msg = (_("A new share may not be created from snapshot '%s', " "because the snapshot's parent share does not have " "that capability.") % snapshot_id) LOG.error(msg) raise exc.HTTPBadRequest(explanation=msg) if share_network_id: try: self.share_api.get_share_network( context, share_network_id) except exception.ShareNetworkNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) kwargs['share_network_id'] = share_network_id display_name = share.get('display_name') display_description = share.get('display_description') if 'share_type' in share and 'volume_type' in share: msg = 'Cannot specify both share_type and volume_type' raise exc.HTTPBadRequest(explanation=msg) req_share_type = share.get('share_type', share.get('volume_type')) share_type = None if req_share_type: try: if not uuidutils.is_uuid_like(req_share_type): share_type = share_types.get_share_type_by_name( context, req_share_type) else: share_type = share_types.get_share_type( context, req_share_type) except exception.ShareTypeNotFound: msg = _("Share type not found.") raise exc.HTTPNotFound(explanation=msg) elif not snapshot: def_share_type = share_types.get_default_share_type() if def_share_type: share_type = def_share_type # Only use in create share feature. Create share from snapshot # and create share with share group features not # need this check. if (not share_network_id and not snapshot and not share_group_id and share_type and share_type.get('extra_specs') and (strutils.bool_from_string(share_type.get('extra_specs'). get('driver_handles_share_servers')))): msg = _('Share network must be set when the ' 'driver_handles_share_servers is true.') raise exc.HTTPBadRequest(explanation=msg) type_chosen = share_type or parent_share_type if type_chosen and check_availability_zones_extra_spec: type_azs = type_chosen.get( 'extra_specs', {}).get('availability_zones', '') type_azs = type_azs.split(',') if type_azs else [] kwargs['availability_zones'] = type_azs if (availability_zone and type_azs and availability_zone not in type_azs): msg = _("Share type %(type)s is not supported within the " "availability zone chosen %(az)s.") type_chosen = ( req_share_type or "%s (from source snapshot)" % ( parent_share_type.get('name') or parent_share_type.get('id')) ) payload = {'type': type_chosen, 'az': availability_zone} raise exc.HTTPBadRequest(explanation=msg % payload) if share_type: kwargs['share_type'] = share_type new_share = self.share_api.create(context, share_proto, size, display_name, display_description, **kwargs) return self._view_builder.detail(req, new_share)
def _create(self, req, body, set_defaults=False): """Creates a new share type.""" context = req.environ['manila.context'] if (not self.is_valid_body(body, 'share_type') and not self.is_valid_body(body, 'volume_type')): raise webob.exc.HTTPBadRequest() elif self.is_valid_body(body, 'share_type'): share_type = body['share_type'] else: share_type = body['volume_type'] name = share_type.get('name') specs = share_type.get('extra_specs', {}) description = share_type.get('description') if (description and req.api_version_request < api_version.APIVersionRequest("2.41")): msg = _("'description' key is not supported by this " "microversion. Use 2.41 or greater microversion " "to be able to use 'description' in share type.") raise webob.exc.HTTPBadRequest(explanation=msg) is_public = share_type.get( 'os-share-type-access:is_public', share_type.get('share_type_access:is_public', True), ) if (name is None or name == "" or len(name) > 255 or (description and len(description) > 255)): msg = _("Type name or description is not valid.") raise webob.exc.HTTPBadRequest(explanation=msg) # Note(cknight): Set the default extra spec value for snapshot_support # for API versions before it was required. if set_defaults: if constants.ExtraSpecs.SNAPSHOT_SUPPORT not in specs: specs[constants.ExtraSpecs.SNAPSHOT_SUPPORT] = True try: required_extra_specs = ( share_types.get_valid_required_extra_specs(specs)) share_types.create(context, name, specs, is_public, description=description) share_type = share_types.get_share_type_by_name(context, name) share_type['required_extra_specs'] = required_extra_specs req.cache_db_share_type(share_type) self._notify_share_type_info(context, 'share_type.create', share_type) except exception.InvalidExtraSpec as e: raise webob.exc.HTTPBadRequest(explanation=e.message) except exception.ShareTypeExists as err: notifier_err = dict(share_types=share_type, error_message=err.message) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPConflict(explanation=err.message) except exception.NotFound as err: notifier_err = dict(share_types=share_type, error_message=err.message) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_type)