diff options
| author | Akihiro Motoki <amotoki@gmail.com> | 2017-05-03 14:19:27 +0000 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2019-05-09 21:51:57 -0500 |
| commit | c44f26eb7e41c28bb13ef9bd31c8ddda9e638862 (patch) | |
| tree | 062fc4fea3e465ac7da63516ee77489e1acbc45a /openstackclient/network/v2/network_agent.py | |
| parent | 6385d64237c9973dd4c7dd53efb6664ea2c719da (diff) | |
| download | python-openstackclient-c44f26eb7e41c28bb13ef9bd31c8ddda9e638862.tar.gz | |
Use cliff formattable columns in network commands
Use cliff formattable columns not to convert complex fields
into a string when a machine readable format like JSON or YAML
is requested.
Partial-Bug: #1687955
Partially implement blueprint osc-formattable-columns
Change-Id: I9878f327e39f56852cc0fb6e4eee9105b7141da9
Diffstat (limited to 'openstackclient/network/v2/network_agent.py')
| -rw-r--r-- | openstackclient/network/v2/network_agent.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/openstackclient/network/v2/network_agent.py b/openstackclient/network/v2/network_agent.py index 46e8d4b2..16784854 100644 --- a/openstackclient/network/v2/network_agent.py +++ b/openstackclient/network/v2/network_agent.py @@ -15,6 +15,8 @@ import logging +from cliff import columns as cliff_columns +from osc_lib.cli import format_columns from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils @@ -26,19 +28,22 @@ from openstackclient.network import sdk_utils LOG = logging.getLogger(__name__) -def _format_alive(alive): - return ":-)" if alive else "XXX" +class AliveColumn(cliff_columns.FormattableColumn): + def human_readable(self): + return ":-)" if self._value else "XXX" -def _format_admin_state(state): - return 'UP' if state else 'DOWN' +class AdminStateColumn(cliff_columns.FormattableColumn): + def human_readable(self): + return 'UP' if self._value else 'DOWN' + _formatters = { - 'is_alive': _format_alive, - 'alive': _format_alive, - 'admin_state_up': _format_admin_state, - 'is_admin_state_up': _format_admin_state, - 'configurations': utils.format_dict, + 'is_alive': AliveColumn, + 'alive': AliveColumn, + 'admin_state_up': AdminStateColumn, + 'is_admin_state_up': AdminStateColumn, + 'configurations': format_columns.DictColumn, } |
