summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2012-05-10 16:25:31 -0500
committerDean Troyer <dtroyer@gmail.com>2012-05-11 12:08:05 -0500
commit5378322906a636bc2b9685e7403950549ef213f5 (patch)
tree8732f15445641e36c44d501f959d81b59a415dc2 /openstackclient/common
parent712a8c7f9c5c89071f7f3d87a8d4484921581cf6 (diff)
downloadpython-openstackclient-5378322906a636bc2b9685e7403950549ef213f5.tar.gz
Add tenant CRUD commands
* add {create|delete|set} tenant commands * move get_XXXX_properties() to common.utils.get_item_properties() add mixed_case_fields as an optional arg Change-Id: I7b3bd9cefb08e39730886b31213cbe422b5a8453
Diffstat (limited to 'openstackclient/common')
-rw-r--r--openstackclient/common/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index e0f35ad4..6c613d94 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -53,6 +53,30 @@ def find_resource(manager, name_or_id):
raise exceptions.CommandError(msg)
+def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):
+ """Return a tuple containing the item properties.
+
+ :param item: a single item resource (e.g. Server, Tenant, etc)
+ :param fields: tuple of strings with the desired field names
+ :param mixed_case_fields: tuple of field names to preserve case
+ :param formatters: dictionary mapping field names to callables
+ to format the values
+ """
+ row = []
+
+ for field in fields:
+ if field in formatters:
+ row.append(formatters[field](item))
+ else:
+ if field in mixed_case_fields:
+ field_name = field.replace(' ', '_')
+ else:
+ field_name = field.lower().replace(' ', '_')
+ data = getattr(item, field_name, '')
+ row.append(data)
+ return tuple(row)
+
+
def string_to_bool(arg):
return arg.strip().lower() in ('t', 'true', 'yes', '1')