Use caching for resource name/id finders
Use caching to reduce the number of client calls. Change-Id: Ic22dfac0a5ea8c0f1ae7b83d37492e935f259db8
This commit is contained in:
parent
dfbb0fb848
commit
54aa3ea5e1
@ -73,6 +73,24 @@ def register_cache_configurations(conf):
|
||||
conf.register_group(extension_cache_group)
|
||||
conf.register_opts(extension_cache_opts, group=extension_cache_group)
|
||||
|
||||
find_cache_group = cfg.OptGroup('resource_finder_cache')
|
||||
find_cache_opts = [
|
||||
cfg.IntOpt('expiration_time', default=3600,
|
||||
help=_(
|
||||
'TTL, in seconds, for any cached item in the '
|
||||
'dogpile.cache region used for caching of OpenStack '
|
||||
'service finder functions.')),
|
||||
cfg.BoolOpt('caching', default=True,
|
||||
help=_(
|
||||
'Toggle to enable/disable caching when Orchestration '
|
||||
'Engine looks for other OpenStack service resources '
|
||||
'using name or id. Please note that the global '
|
||||
'toggle for oslo.cache(enabled=True in [cache] group) '
|
||||
'must be enabled to use this feature.'))
|
||||
]
|
||||
conf.register_group(find_cache_group)
|
||||
conf.register_opts(find_cache_opts, group=find_cache_group)
|
||||
|
||||
return conf
|
||||
|
||||
|
||||
|
@ -16,6 +16,12 @@ from oslo_config import cfg
|
||||
|
||||
from heat.common import cache
|
||||
|
||||
MEMOIZE = core.get_memoization_decorator(conf=cfg.CONF,
|
||||
region=cache.get_cache_region(),
|
||||
group="service_extension_cache")
|
||||
MEMOIZE_EXTENSIONS = core.get_memoization_decorator(
|
||||
conf=cfg.CONF,
|
||||
region=cache.get_cache_region(),
|
||||
group="service_extension_cache")
|
||||
|
||||
MEMOIZE_FINDER = core.get_memoization_decorator(
|
||||
conf=cfg.CONF,
|
||||
region=cache.get_cache_region(),
|
||||
group="resource_finder_cache")
|
||||
|
@ -16,6 +16,7 @@ from glanceclient import exc
|
||||
from glanceclient.openstack.common.apiclient import exceptions
|
||||
|
||||
from heat.engine.clients import client_plugin
|
||||
from heat.engine.clients import os as os_client
|
||||
from heat.engine import constraints
|
||||
|
||||
CLIENT_NAME = 'glance'
|
||||
@ -83,6 +84,13 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
|
||||
:param image_identifier: image name or a UUID-like identifier
|
||||
:returns: the id of the requested :image_identifier:
|
||||
"""
|
||||
return self._find_image_id(self.context.tenant_id,
|
||||
image_identifier)
|
||||
|
||||
@os_client.MEMOIZE_FINDER
|
||||
def _find_image_id(self, tenant_id, image_identifier):
|
||||
# tenant id in the signature is used for the memoization key,
|
||||
# that would differentiate similar resource names across tenants.
|
||||
return self.get_image(image_identifier).id
|
||||
|
||||
def get_image(self, image_identifier):
|
||||
|
@ -74,10 +74,19 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
||||
|
||||
def find_resourceid_by_name_or_id(self, resource, name_or_id,
|
||||
cmd_resource=None):
|
||||
return self._find_resource_id(self.context.tenant_id,
|
||||
resource, name_or_id,
|
||||
cmd_resource)
|
||||
|
||||
@os_client.MEMOIZE_FINDER
|
||||
def _find_resource_id(self, tenant_id,
|
||||
resource, name_or_id, cmd_resource):
|
||||
# tenant id in the signature is used for the memoization key,
|
||||
# that would differentiate similar resource names across tenants.
|
||||
return neutronV20.find_resourceid_by_name_or_id(
|
||||
self.client(), resource, name_or_id, cmd_resource=cmd_resource)
|
||||
|
||||
@os_client.MEMOIZE
|
||||
@os_client.MEMOIZE_EXTENSIONS
|
||||
def _list_extensions(self):
|
||||
extensions = self.client().list_extensions().get('extensions')
|
||||
return set(extension.get('alias') for extension in extensions)
|
||||
|
@ -230,6 +230,13 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
|
||||
:param flavor: the name of the flavor to find
|
||||
:returns: the id of :flavor:
|
||||
"""
|
||||
return self._find_flavor_id(self.context.tenant_id,
|
||||
flavor)
|
||||
|
||||
@os_client.MEMOIZE_FINDER
|
||||
def _find_flavor_id(self, tenant_id, flavor):
|
||||
# tenant id in the signature is used for the memoization key,
|
||||
# that would differentiate similar resource names across tenants.
|
||||
return self.get_flavor(flavor).id
|
||||
|
||||
def get_flavor(self, flavor_identifier):
|
||||
@ -672,7 +679,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
||||
else:
|
||||
return False
|
||||
|
||||
@os_client.MEMOIZE
|
||||
@os_client.MEMOIZE_EXTENSIONS
|
||||
def _list_extensions(self):
|
||||
extensions = self.client().list_extensions.show_all()
|
||||
return set(extension.alias for extension in extensions)
|
||||
|
Loading…
Reference in New Issue
Block a user