diff options
author | Lakshmi N Sampath <lakshmi.sampath@hp.com> | 2014-09-09 14:51:14 -0700 |
---|---|---|
committer | Stuart McLaren <stuart.mclaren@hp.com> | 2014-09-12 09:12:49 +0000 |
commit | 97b1506bdbccea9fbfcac731cf8b7e0cadebcbab (patch) | |
tree | 55347541817b05a37a7435f03c1ccc90be56fb76 /glanceclient/common/utils.py | |
parent | fde99a0a4df04609d7bb3a59bddc6cfe3508e71a (diff) | |
download | python-glanceclient-97b1506bdbccea9fbfcac731cf8b7e0cadebcbab.tar.gz |
Fix v2 requests to non-bleeding edge servers
In the case where v2 requests are sent to a server which is not running
head of tree which includes the v2 metadef code some 404 cases need to
be handled to enable standard requests to complete.
This patch aslo improves fetching schemas -- they are now only
fetched as needed.
Change-Id: I8c871f11b909337bd7df19b77e606772dbc634b2
Closes-bug: #1367326
Diffstat (limited to 'glanceclient/common/utils.py')
-rw-r--r-- | glanceclient/common/utils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index 9071065..d1a634e 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -21,6 +21,7 @@ import json import os import re import sys +import threading import uuid import six @@ -36,6 +37,8 @@ from glanceclient import exc from glanceclient.openstack.common import importutils from glanceclient.openstack.common import strutils +_memoized_property_lock = threading.Lock() + # Decorator for cli-args def arg(*args, **kwargs): @@ -367,3 +370,18 @@ def integrity_iter(iter, checksum): raise IOError(errno.EPIPE, 'Corrupt image download. Checksum was %s expected %s' % (md5sum, checksum)) + + +def memoized_property(fn): + attr_name = '_lazy_once_' + fn.__name__ + + @property + def _memoized_property(self): + if hasattr(self, attr_name): + return getattr(self, attr_name) + else: + with _memoized_property_lock: + if not hasattr(self, attr_name): + setattr(self, attr_name, fn(self)) + return getattr(self, attr_name) + return _memoized_property |