diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-12-19 11:54:22 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-12-19 11:54:22 +0000 |
commit | 7a06f8632e638510bc00df4e96801ecd295aeb8e (patch) | |
tree | c43674183a57604bab02eeb8b1b3fd46e7fea89a | |
parent | 5ea85dad65644719f53e16220a624f9ccac4aba7 (diff) | |
parent | a90a669c9c03d6bdbecaef8fad162b73d8d0fa9f (diff) | |
download | python-troveclient-7a06f8632e638510bc00df4e96801ecd295aeb8e.tar.gz |
Merge "Fallback to flavor's str_id when id is None"
-rw-r--r-- | troveclient/utils.py | 13 | ||||
-rw-r--r-- | troveclient/v1/shell.py | 17 |
2 files changed, 20 insertions, 10 deletions
diff --git a/troveclient/utils.py b/troveclient/utils.py index 9210d6d..67b600c 100644 --- a/troveclient/utils.py +++ b/troveclient/utils.py @@ -205,20 +205,15 @@ def print_dict(d, property="Property"): def find_resource(manager, name_or_id): """Helper for the _find_* methods.""" # first try to get entity as integer id - try: - if isinstance(name_or_id, int) or name_or_id.isdigit(): - return manager.get(int(name_or_id)) - except exceptions.NotFound: - pass - if sys.version_info <= (3, 0): + if isinstance(name_or_id, int) or name_or_id.isdigit(): + name_or_id = int(name_or_id) + elif sys.version_info <= (3, 0): name_or_id = strutils.safe_decode(name_or_id) - # now try to get entity as uuid try: - uuid.UUID(name_or_id) return manager.get(name_or_id) - except (ValueError, exceptions.NotFound): + except exceptions.NotFound: pass try: diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index dd9408e..5981f44 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -87,6 +87,13 @@ def _print_object(obj): # Get rid of those ugly links if obj._info.get('links'): del(obj._info['links']) + + # Fallback to str_id for flavors, where necessary + if hasattr(obj, 'str_id'): + if hasattr(obj, 'id') and not obj.id: + obj._info['id'] = obj.str_id + del(obj._info['str_id']) + utils.print_dict(obj._info) @@ -128,7 +135,15 @@ def do_flavor_list(cs, args): err_msg = ("Specify both <datastore_type> and <datastore_version_id>" " to list datastore version associated flavors.") raise exceptions.CommandError(err_msg) - utils.print_list(flavors, ['id', 'name', 'ram'], + + # Fallback to str_id where necessary. + _flavors = [] + for f in flavors: + if not f.id and hasattr(f, 'str_id'): + f.id = f.str_id + _flavors.append(f) + + utils.print_list(_flavors, ['id', 'name', 'ram'], labels={'ram': 'RAM'}) |