From ace73ed0a36f3fc9f23c3e4893a725fbba5438ed Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Wed, 12 Feb 2014 10:21:40 +0200 Subject: [PATCH] Update apiclient.base and reuse new functional Module apiclient.base has several updates in oslo, so we need to sync latest code to have ability to reuse new functional. Updates in oslo which related to usage of apiclient.base in heatclient: - I491f9b54c7074546cf738c6150666bfcc3966a78 - I1db6c12a1f798de7f7fafd0c34fb0ef523610153 Related to bp common-client-library-2 Change-Id: I509d6efb0c8eef87ba2e4aa02ebb44ba149a9860 --- heatclient/openstack/common/apiclient/base.py | 16 +++++++++------- heatclient/v1/events.py | 4 ---- heatclient/v1/resources.py | 5 ----- heatclient/v1/software_configs.py | 4 ---- heatclient/v1/software_deployments.py | 4 ---- heatclient/v1/stacks.py | 7 ++----- 6 files changed, 11 insertions(+), 29 deletions(-) diff --git a/heatclient/openstack/common/apiclient/base.py b/heatclient/openstack/common/apiclient/base.py index 3e842ecf..c0c71ac3 100644 --- a/heatclient/openstack/common/apiclient/base.py +++ b/heatclient/openstack/common/apiclient/base.py @@ -24,6 +24,7 @@ Base utilities to build API operation managers and objects on top of. # pylint: disable=E1102 import abc +import copy import six @@ -456,17 +457,17 @@ class Resource(object): def __getattr__(self, k): if k not in self.__dict__: #NOTE(bcwaldon): disallow lazy-loading if already loaded once - if not self.is_loaded(): - self.get() + if not self.is_loaded: + self._get() return self.__getattr__(k) raise AttributeError(k) else: return self.__dict__[k] - def get(self): - # set_loaded() first ... so if we have to bail, we know we tried. - self.set_loaded(True) + def _get(self): + # set _loaded first ... so if we have to bail, we know we tried. + self._loaded = True if not hasattr(self.manager, 'get'): return @@ -484,8 +485,9 @@ class Resource(object): return self.id == other.id return self._info == other._info + @property def is_loaded(self): return self._loaded - def set_loaded(self, val): - self._loaded = val + def to_dict(self): + return copy.deepcopy(self._info) diff --git a/heatclient/v1/events.py b/heatclient/v1/events.py index 161de39b..cb246642 100644 --- a/heatclient/v1/events.py +++ b/heatclient/v1/events.py @@ -12,7 +12,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import copy from heatclient.openstack.common.apiclient import base from heatclient.openstack.common.py3kcompat import urlutils @@ -35,9 +34,6 @@ class Event(base.Resource): def data(self, **kwargs): return self.manager.data(self, **kwargs) - def to_dict(self): - return copy.deepcopy(self._info) - class EventManager(stacks.StackChildManager): resource_class = Event diff --git a/heatclient/v1/resources.py b/heatclient/v1/resources.py index 2d22dcf2..9d66a15d 100644 --- a/heatclient/v1/resources.py +++ b/heatclient/v1/resources.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import copy - from heatclient.openstack.common.apiclient import base from heatclient.openstack.common.py3kcompat import urlutils from heatclient.openstack.common import strutils @@ -36,9 +34,6 @@ class Resource(base.Resource): def data(self, **kwargs): return self.manager.data(self, **kwargs) - def to_dict(self): - return copy.deepcopy(self._info) - class ResourceManager(stacks.StackChildManager): resource_class = Resource diff --git a/heatclient/v1/software_configs.py b/heatclient/v1/software_configs.py index 9fa77d3e..cf038db5 100644 --- a/heatclient/v1/software_configs.py +++ b/heatclient/v1/software_configs.py @@ -9,7 +9,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import copy from heatclient.openstack.common.apiclient import base @@ -24,9 +23,6 @@ class SoftwareConfig(base.Resource): def data(self, **kwargs): return self.manager.data(self, **kwargs) - def to_dict(self): - return copy.deepcopy(self._info) - class SoftwareConfigManager(base.BaseManager): resource_class = SoftwareConfig diff --git a/heatclient/v1/software_deployments.py b/heatclient/v1/software_deployments.py index 2a178685..4bbdf3d9 100644 --- a/heatclient/v1/software_deployments.py +++ b/heatclient/v1/software_deployments.py @@ -9,7 +9,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import copy from heatclient.openstack.common.apiclient import base from heatclient.openstack.common.py3kcompat import urlutils @@ -25,9 +24,6 @@ class SoftwareDeployment(base.Resource): def delete(self): return self.manager.delete(deployment_id=self.id) - def to_dict(self): - return copy.deepcopy(self._info) - class SoftwareDeploymentManager(base.BaseManager): resource_class = SoftwareDeployment diff --git a/heatclient/v1/stacks.py b/heatclient/v1/stacks.py index efbbef7f..2d1ba6da 100644 --- a/heatclient/v1/stacks.py +++ b/heatclient/v1/stacks.py @@ -12,7 +12,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import copy + import six from heatclient.openstack.common.apiclient import base @@ -37,7 +37,7 @@ class Stack(base.Resource): def get(self): # set_loaded() first ... so if we have to bail, we know we tried. - self.set_loaded(True) + self._loaded = True if not hasattr(self.manager, 'get'): return @@ -61,9 +61,6 @@ class Stack(base.Resource): def identifier(self): return '%s/%s' % (self.stack_name, self.id) - def to_dict(self): - return copy.deepcopy(self._info) - class StackManager(base.BaseManager): resource_class = Stack