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/security_group.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/security_group.py')
| -rw-r--r-- | openstackclient/network/v2/security_group.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index ed6c8d7c..e3894738 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -15,6 +15,7 @@ import argparse +from cliff import columns as cliff_columns from osc_lib.command import command from osc_lib import utils import six @@ -65,13 +66,23 @@ def _format_compute_security_group_rules(sg_rules): return utils.format_list(rules, separator='\n') +class NetworkSecurityGroupRulesColumn(cliff_columns.FormattableColumn): + def human_readable(self): + return _format_network_security_group_rules(self._value) + + +class ComputeSecurityGroupRulesColumn(cliff_columns.FormattableColumn): + def human_readable(self): + return _format_compute_security_group_rules(self._value) + + _formatters_network = { - 'security_group_rules': _format_network_security_group_rules, + 'security_group_rules': NetworkSecurityGroupRulesColumn, } _formatters_compute = { - 'rules': _format_compute_security_group_rules, + 'rules': ComputeSecurityGroupRulesColumn, } |
