Add caching for nova extensions
This patch adds caching for nova extensions. Change-Id: I6170f1075a923b7fb2dfb50d4008ff9722fcee48 Partial-Bug: #1506875
This commit is contained in:
parent
868b4616e9
commit
4e909f0d88
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_cache import core
|
||||
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")
|
|
@ -14,18 +14,11 @@
|
|||
from neutronclient.common import exceptions
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
from neutronclient.v2_0 import client as nc
|
||||
from oslo_cache import core
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from heat.common import cache
|
||||
from heat.common import exception
|
||||
from heat.engine.clients import client_plugin
|
||||
|
||||
|
||||
MEMOIZE = core.get_memoization_decorator(conf=cfg.CONF,
|
||||
region=cache.get_cache_region(),
|
||||
group="service_extension_cache")
|
||||
from heat.engine.clients import os as os_client
|
||||
|
||||
|
||||
class NeutronClientPlugin(client_plugin.ClientPlugin):
|
||||
|
@ -79,7 +72,7 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
|||
return neutronV20.find_resourceid_by_name_or_id(
|
||||
self.client(), key_type, props.get(key))
|
||||
|
||||
@MEMOIZE
|
||||
@os_client.MEMOIZE
|
||||
def _list_extensions(self):
|
||||
extensions = self.client().list_extensions().get('extensions')
|
||||
return set(extension.get('alias') for extension in extensions)
|
||||
|
|
|
@ -33,6 +33,7 @@ from heat.common.i18n import _
|
|||
from heat.common.i18n import _LI
|
||||
from heat.common.i18n import _LW
|
||||
from heat.engine.clients import client_plugin
|
||||
from heat.engine.clients import os as os_client
|
||||
from heat.engine import constraints
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -656,10 +657,14 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
|||
else:
|
||||
return False
|
||||
|
||||
def has_extension(self, alias):
|
||||
"""Check if extension is present."""
|
||||
@os_client.MEMOIZE
|
||||
def _list_extensions(self):
|
||||
extensions = self.client().list_extensions.show_all()
|
||||
return alias in [extension.alias for extension in extensions]
|
||||
return set(extension.alias for extension in extensions)
|
||||
|
||||
def has_extension(self, alias):
|
||||
"""Check if specific extension is present."""
|
||||
return alias in self._list_extensions()
|
||||
|
||||
|
||||
class ServerConstraint(constraints.BaseCustomConstraint):
|
||||
|
|
Loading…
Reference in New Issue