diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2013-07-18 11:10:34 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2013-07-21 13:59:11 -0500 |
| commit | 818c94875221f606ed56f276c1cbd320a9106754 (patch) | |
| tree | b22d2c5ed42a2fde5ed9500f341177e934842f1c /openstackclient/common/utils.py | |
| parent | ce7225692970ee0036d785f540fa2a0dba882cc3 (diff) | |
| download | python-openstackclient-818c94875221f606ed56f276c1cbd320a9106754.tar.gz | |
Clean up properties (metadata) formatting
* Reformat default dict output to key='value' using utils.format_dict()
* Changes utils.get_item_properties() to pass the specific field to
the formatter function rather than the entire resource object, this
allows the formatter to handle multiple attributes.
* Updates server, volume, volume type commands
Change-Id: I90eebf6b84ae200532f09cd925f371598ea54a64
Diffstat (limited to 'openstackclient/common/utils.py')
| -rw-r--r-- | openstackclient/common/utils.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 06542887..2f2f5718 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -1,4 +1,4 @@ -# Copyright 2012-2013 OpenStack, LLC. +# Copyright 2012-2013 OpenStack Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -73,6 +73,20 @@ def find_resource(manager, name_or_id): raise +def format_dict(data): + """Return a formatted string of key value pairs + + :param data: a dict + :param format: optional formatting hints + :rtype: a string formatted to key='value' + """ + + output = "" + for s in data: + output = output + s + "='" + data[s] + "', " + return output[:-2] + + def get_item_properties(item, fields, mixed_case_fields=[], formatters={}): """Return a tuple containing the item properties. @@ -85,14 +99,14 @@ def get_item_properties(item, fields, mixed_case_fields=[], formatters={}): row = [] for field in fields: + if field in mixed_case_fields: + field_name = field.replace(' ', '_') + else: + field_name = field.lower().replace(' ', '_') + data = getattr(item, field_name, '') if field in formatters: - row.append(formatters[field](item)) + row.append(formatters[field](data)) 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) |
