From 1981431c08f4c9fa0d206157baf55eccca17c1be Mon Sep 17 00:00:00 2001 From: Davide Guerri Date: Mon, 11 May 2015 16:24:16 +0100 Subject: [PATCH] Rewrite extension checking methods Old implementation didn't work, was using ad-hoc caching and its name was too generic. Moreover it exposed 2 methods that should be private as Shade aims to hide implementation details. This change-set gets rid of extension_cache() and has_extension() methods and create _nova_extensions() and _has_nova_extension() methods. Caching is performed using _cache_on_arguments decorator. Change-Id: I6aa3ed5a306159ba477d15810138b3a4fb5a3649 --- shade/__init__.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/shade/__init__.py b/shade/__init__.py index 6c3d19bee..e77516ef0 100644 --- a/shade/__init__.py +++ b/shade/__init__.py @@ -750,23 +750,27 @@ class OpenStackCloud(object): def delete_keypair(self, name): return self.manager.submitTask(_tasks.KeypairDelete(key=name)) - @property - def extension_cache(self): - if not self._extension_cache: - self._extension_cache = set() + @_cache_on_arguments() + def _nova_extensions(self): + extensions = set() - try: - resp, body = self.manager.submitTask( - _tasks.NovaUrlGet(url='/extensions')) - if resp.status_code == 200: - for x in body['extensions']: - self._extension_cache.add(x['alias']) - except nova_exceptions.NotFound: - pass - return self._extension_cache + try: + resp, body = self.manager.submitTask( + _tasks.NovaUrlGet(url='/extensions')) + for x in body['extensions']: + extensions.add(x['alias']) + except Exception as e: + self.log.debug( + "nova could not list extensions: {msg}".format( + msg=str(e)), exc_info=True) + raise OpenStackCloudException( + "error fetching extension list for nova: {msg}".format( + msg=str(e))) - def has_extension(self, extension_name): - return extension_name in self.extension_cache + return extensions + + def _has_nova_extension(self, extension_name): + return extension_name in self._nova_extensions() def _filter_list(self, data, name_or_id, filters): """Filter a list by name/ID and arbitrary meta data.