diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2013-08-13 17:14:42 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2013-08-23 12:08:32 -0500 |
| commit | 17f13f7bf4cea80e8e1380fbc8295318de5be383 (patch) | |
| tree | 611a7a512eae39341911db529b36035d737730e2 /openstackclient/common/utils.py | |
| parent | b440986e6e0e90c220fe3e52f893bc5dd51cae5a (diff) | |
| download | python-openstackclient-17f13f7bf4cea80e8e1380fbc8295318de5be383.tar.gz | |
Create a new base REST API interface
* restapi module provides basic REST API support
* uses dicts rather than Resource classes
* JSON serialization/deserialization
* log requests in 'curl' format
* basic API boilerplate for create/delete/list/set/show verbs
* ignore H302 due to urllib import
Change-Id: I3cb91e44e631ee19e9f5dea19b6bac5d599d19ce
Diffstat (limited to 'openstackclient/common/utils.py')
| -rw-r--r-- | openstackclient/common/utils.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index f72bb505..91a20895 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -115,6 +115,30 @@ def get_item_properties(item, fields, mixed_case_fields=[], formatters={}): return tuple(row) +def get_dict_properties(item, fields, mixed_case_fields=[], formatters={}): + """Return a tuple containing the item properties. + + :param item: a single dict resource + :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 mixed_case_fields: + field_name = field.replace(' ', '_') + else: + field_name = field.lower().replace(' ', '_') + data = item[field_name] if field_name in item else '' + if field in formatters: + row.append(formatters[field](data)) + else: + row.append(data) + return tuple(row) + + def string_to_bool(arg): return arg.strip().lower() in ('t', 'true', 'yes', '1') |
