From 97b1506bdbccea9fbfcac731cf8b7e0cadebcbab Mon Sep 17 00:00:00 2001 From: Lakshmi N Sampath Date: Tue, 9 Sep 2014 14:51:14 -0700 Subject: 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 --- glanceclient/common/utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'glanceclient/common/utils.py') 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 -- cgit v1.2.1