本文整理汇总了Python中neutron.quota.resource_registry.register_resource_by_name函数的典型用法代码示例。如果您正苦于以下问题:Python register_resource_by_name函数的具体用法?Python register_resource_by_name怎么用?Python register_resource_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register_resource_by_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
super(QuotaExtensionTestCase, self).setUp()
resource_registry.register_resource_by_name('pool')
resource_registry.register_resource_by_name('loadbalancer')
resource_registry.register_resource_by_name('listener')
resource_registry.register_resource_by_name('healthmonitor')
resource_registry.register_resource_by_name('member')
示例2: register_resources_from_config
def register_resources_from_config():
# This operation is now deprecated. All the neutron core and extended
# resource for which quota limits are enforced explicitly register
# themselves with the quota engine.
for resource_item in (set(cfg.CONF.QUOTAS.quota_items) -
set(default_quota_items)):
resource_registry.register_resource_by_name(resource_item)
示例3: setUp
def setUp(self):
super(QuotaExtensionTestCase, self).setUp()
# Ensure existing ExtensionManager is not used
extensions.PluginAwareExtensionManager._instance = None
self.useFixture(tools.AttributeMapMemento())
# Create the default configurations
self.config_parse()
# Update the plugin and extensions path
self.setup_coreplugin(TARGET_PLUGIN)
cfg.CONF.set_override(
'quota_items',
['network', 'subnet', 'port', 'extra1'],
group='QUOTAS')
quota.QUOTAS = quota.QuotaEngine()
quota.register_resources_from_config()
self._plugin_patcher = mock.patch(TARGET_PLUGIN, autospec=True)
self.plugin = self._plugin_patcher.start()
self.plugin.return_value.supported_extension_aliases = ['quotas']
# QUOTAS will register the items in conf when starting
# extra1 here is added later, so have to do it manually
resource_registry.register_resource_by_name('extra1')
ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
app = config.load_paste_app('extensions_test_app')
ext_middleware = extensions.ExtensionMiddleware(app, ext_mgr=ext_mgr)
self.api = webtest.TestApp(ext_middleware)
# Initialize the router for the core API in order to ensure core quota
# resources are registered
router.APIRouter()
示例4: initialize_all
def initialize_all():
ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
ext_mgr.extend_resources("2.0", attributes.RESOURCE_ATTRIBUTE_MAP)
# At this stage we have a fully populated resource attribute map;
# build Pecan controllers and routes for every resource (both core
# and extensions)
pecanized_exts = [ext for ext in ext_mgr.extensions.values() if hasattr(ext, "get_pecan_controllers")]
pecan_controllers = {}
for ext in pecanized_exts:
LOG.debug("Extension %s is pecan-enabled. Fetching resources " "and controllers", ext.get_name())
controllers = ext.get_pecan_controllers()
# controllers is actually a list of pairs where the first element is
# the collection name and the second the actual controller
for (collection, coll_controller) in controllers:
pecan_controllers[collection] = coll_controller
for collection in attributes.RESOURCE_ATTRIBUTE_MAP:
if collection not in pecan_controllers:
resource = _handle_plurals(collection)
LOG.debug("Building controller for resource:%s", resource)
plugin = _plugin_for_resource(collection)
if plugin:
manager.NeutronManager.set_plugin_for_resource(resource, plugin)
controller = root.CollectionsController(collection, resource)
manager.NeutronManager.set_controller_for_resource(collection, controller)
LOG.info(
_LI("Added controller for resource %(resource)s " "via URI path segment:%(collection)s"),
{"resource": resource, "collection": collection},
)
else:
LOG.debug("There are already controllers for resource:%s", resource)
# NOTE(salv-orlando): If you are care about code quality, please read below
# Hackiness is strong with the piece of code below. It is used for
# populating resource plurals and registering resources with the quota
# engine, but the method it calls were not conceived with this aim.
# Therefore it only leverages side-effects from those methods. Moreover,
# as it is really not advisable to load an instance of
# neutron.api.v2.router.APIRouter just to register resources with the
# quota engine, core resources are explicitly registered here.
# TODO(salv-orlando): The Pecan WSGI support should provide its own
# solution to manage resource plurals and registration of resources with
# the quota engine
for resource in router.RESOURCES.keys():
resource_registry.register_resource_by_name(resource)
for ext in ext_mgr.extensions.values():
# make each extension populate its plurals
if hasattr(ext, "get_resources"):
ext.get_resources()
if hasattr(ext, "get_extended_resources"):
ext.get_extended_resources("v2.0")
# Certain policy checks require that the extensions are loaded
# and the RESOURCE_ATTRIBUTE_MAP populated before they can be
# properly initialized. This can only be claimed with certainty
# once this point in the code has been reached. In the event
# that the policies have been initialized before this point,
# calling reset will cause the next policy check to
# re-initialize with all of the required data in place.
policy.reset()
示例5: build_resource_info
def build_resource_info(plural_mappings, resource_map, which_service,
action_map=None, register_quota=False,
translate_name=False, allow_bulk=False):
"""Build resources for advanced services.
Takes the resource information, and singular/plural mappings, and creates
API resource objects for advanced services extensions. Will optionally
translate underscores to dashes in resource names, register the resource,
and accept action information for resources.
:param plural_mappings: mappings between singular and plural forms
:param resource_map: attribute map for the WSGI resources to create
:param which_service: The name of the service for which the WSGI resources
are being created. This name will be used to pass
the appropriate plugin to the WSGI resource.
It can be set to None or "CORE" to create WSGI
resources for the core plugin
:param action_map: custom resource actions
:param register_quota: it can be set to True to register quotas for the
resource(s) being created
:param translate_name: replaces underscores with dashes
:param allow_bulk: True if bulk create are allowed
"""
resources = []
if not which_service:
which_service = constants.CORE
if action_map is None:
action_map = {}
if which_service != constants.CORE:
plugin = manager.NeutronManager.get_service_plugins()[which_service]
else:
plugin = manager.NeutronManager.get_plugin()
path_prefix = getattr(plugin, "path_prefix", "")
LOG.debug('Service %(service)s assigned prefix: %(prefix)s',
{'service': which_service, 'prefix': path_prefix})
for collection_name in resource_map:
resource_name = plural_mappings[collection_name]
params = resource_map.get(collection_name, {})
if translate_name:
collection_name = collection_name.replace('_', '-')
if register_quota:
resource_registry.register_resource_by_name(resource_name)
member_actions = action_map.get(resource_name, {})
controller = base.create_resource(
collection_name, resource_name, plugin, params,
member_actions=member_actions,
allow_bulk=allow_bulk,
allow_pagination=cfg.CONF.allow_pagination,
allow_sorting=cfg.CONF.allow_sorting)
resource = extensions.ResourceExtension(
collection_name,
controller,
path_prefix=path_prefix,
member_actions=member_actions,
attr_map=params)
resources.append(resource)
return resources
示例6: get_resources
def get_resources(cls):
plural_mappings = resource_helper.build_plural_mappings(
{}, RESOURCE_ATTRIBUTE_MAP)
attr.PLURALS.update(plural_mappings)
for resource_name in ['servicechain_node', 'servicechain_spec',
'servicechain_instance', 'service_profile']:
resource_registry.register_resource_by_name(resource_name)
return resource_helper.build_resource_info(plural_mappings,
RESOURCE_ATTRIBUTE_MAP,
constants.SERVICECHAIN)
示例7: __init__
def __init__(self, **local_config):
mapper = routes_mapper.Mapper()
plugin = manager.NeutronManager.get_plugin()
ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
ext_mgr.extend_resources("2.0", attributes.RESOURCE_ATTRIBUTE_MAP)
col_kwargs = dict(collection_actions=COLLECTION_ACTIONS, member_actions=MEMBER_ACTIONS)
def _map_resource(collection, resource, params, parent=None):
allow_bulk = cfg.CONF.allow_bulk
allow_pagination = cfg.CONF.allow_pagination
allow_sorting = cfg.CONF.allow_sorting
controller = base.create_resource(
collection,
resource,
plugin,
params,
allow_bulk=allow_bulk,
parent=parent,
allow_pagination=allow_pagination,
allow_sorting=allow_sorting,
)
path_prefix = None
if parent:
path_prefix = "/%s/{%s_id}/%s" % (parent["collection_name"], parent["member_name"], collection)
mapper_kwargs = dict(
controller=controller, requirements=REQUIREMENTS, path_prefix=path_prefix, **col_kwargs
)
return mapper.collection(collection, resource, **mapper_kwargs)
mapper.connect("index", "/", controller=Index(RESOURCES))
for resource in RESOURCES:
_map_resource(
RESOURCES[resource], resource, attributes.RESOURCE_ATTRIBUTE_MAP.get(RESOURCES[resource], dict())
)
resource_registry.register_resource_by_name(resource)
for resource in SUB_RESOURCES:
_map_resource(
SUB_RESOURCES[resource]["collection_name"],
resource,
attributes.RESOURCE_ATTRIBUTE_MAP.get(SUB_RESOURCES[resource]["collection_name"], dict()),
SUB_RESOURCES[resource]["parent"],
)
# Certain policy checks require that the extensions are loaded
# and the RESOURCE_ATTRIBUTE_MAP populated before they can be
# properly initialized. This can only be claimed with certainty
# once this point in the code has been reached. In the event
# that the policies have been initialized before this point,
# calling reset will cause the next policy check to
# re-initialize with all of the required data in place.
policy.reset()
super(APIRouter, self).__init__(mapper)
示例8: register_resources_from_config
def register_resources_from_config():
# This operation is now deprecated. All the neutron core and extended
# resource for which quota limits are enforced explicitly register
# themselves with the quota engine.
versionutils.report_deprecated_feature(
LOG, _LW("Registering resources to apply quota limits to using the "
"quota_items option is deprecated as of Liberty."
"Resource REST controllers should take care of registering "
"resources with the quota engine."))
for resource_item in (set(cfg.CONF.QUOTAS.quota_items) -
set(default_quota_items)):
resource_registry.register_resource_by_name(resource_item)
示例9: get_resources
def get_resources(cls):
"""Returns Ext Resources."""
plural_mappings = {"rbac_policies": "rbac_policy"}
attr.PLURALS.update(plural_mappings)
plugin = manager.NeutronManager.get_plugin()
params = RESOURCE_ATTRIBUTE_MAP["rbac_policies"]
collection_name = "rbac-policies"
resource_name = "rbac_policy"
resource_registry.register_resource_by_name(resource_name)
controller = base.create_resource(
collection_name, resource_name, plugin, params, allow_bulk=True, allow_pagination=False, allow_sorting=True
)
return [extensions.ResourceExtension(collection_name, controller, attr_map=params)]
示例10: get_resources
def get_resources(cls):
"""Returns Ext Resources."""
plugin = directory.get_plugin()
params = RESOURCE_ATTRIBUTE_MAP['rbac_policies']
collection_name = 'rbac-policies'
resource_name = 'rbac_policy'
resource_registry.register_resource_by_name(resource_name)
controller = base.create_resource(collection_name, resource_name,
plugin, params, allow_bulk=True,
allow_pagination=False,
allow_sorting=True)
return [extensions.ResourceExtension(collection_name, controller,
attr_map=params)]
示例11: get_resources
def get_resources(cls):
"""Returns Ext Resources."""
exts = []
plugin = manager.NeutronManager.get_service_plugins()[
nuage_constants.NUAGE_PORT_ATTRIBUTES_SERVICE_PLUGIN]
resource_name = 'nuage_policy_group'
collection_name = resource_name.replace('_', '-') + "s"
params = RESOURCE_ATTRIBUTE_MAP.get(resource_name + "s", dict())
resource_registry.register_resource_by_name(resource_name)
controller = base.create_resource(collection_name, resource_name,
plugin, params, allow_bulk=True)
ex = extensions.ResourceExtension(collection_name, controller)
exts.append(ex)
return exts
示例12: get_resources
def get_resources(cls):
"""Returns Ext Resources."""
my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()]
attr.PLURALS.update(dict(my_plurals))
exts = []
plugin = manager.NeutronManager.get_plugin()
for resource_name in ["nuage_gateway", "nuage_gateway_port", "nuage_gateway_vlan", "nuage_gateway_vport"]:
collection_name = resource_name.replace("_", "-") + "s"
params = RESOURCE_ATTRIBUTE_MAP.get(resource_name + "s", dict())
resource_registry.register_resource_by_name(resource_name)
controller = base.create_resource(collection_name, resource_name, plugin, params, allow_bulk=True)
ex = extensions.ResourceExtension(collection_name, controller)
exts.append(ex)
return exts
示例13: get_resources
def get_resources(cls):
"""Returns Ext Resources."""
exts = []
plugin = manager.NeutronManager.get_plugin()
resource_name = 'net_partition'
collection_name = resource_name.replace('_', '-') + "s"
params = RESOURCE_ATTRIBUTE_MAP.get(resource_name + "s", dict())
resource_registry.register_resource_by_name(resource_name)
controller = base.create_resource(collection_name,
resource_name,
plugin, params, allow_bulk=True)
ex = extensions.ResourceExtension(collection_name,
controller)
exts.append(ex)
return exts
示例14: get_resources
def get_resources(cls):
special_mappings = {
'l2_policies': 'l2_policy', 'l3_policies': 'l3_policy',
'network_service_policies': 'network_service_policy',
'external_policies': 'external_policy'}
plural_mappings = resource_helper.build_plural_mappings(
special_mappings, RESOURCE_ATTRIBUTE_MAP)
attr.PLURALS.update(plural_mappings)
for resource_name in ['l3_policy', 'l2_policy', 'policy_target_group',
'policy_target', 'policy_classifier',
'policy_action', 'policy_rule',
'policy_rule_set', 'external_policy',
'external_segment', 'nat_pool',
'network_service_policy']:
resource_registry.register_resource_by_name(resource_name)
return resource_helper.build_resource_info(plural_mappings,
RESOURCE_ATTRIBUTE_MAP,
constants.GROUP_POLICY)
示例15: get_resources
def get_resources(cls):
"""Returns Ext Resources."""
my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()]
attr.PLURALS.update(dict(my_plurals))
exts = []
plugin = manager.NeutronManager.get_plugin()
for resource_name in ['vsd_organisation', 'vsd_domain', 'vsd_zone',
'vsd_subnet']:
collection_name = resource_name.replace('_', '-') + "s"
params = RESOURCE_ATTRIBUTE_MAP.get(resource_name + "s", dict())
resource_registry.register_resource_by_name(resource_name)
controller = base.create_resource(collection_name,
resource_name,
plugin, params, allow_bulk=True)
ex = extensions.ResourceExtension(collection_name,
controller)
exts.append(ex)
return exts