summaryrefslogtreecommitdiff
path: root/openstackclient/network/v2/subnet.py
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2017-05-03 14:19:27 +0000
committerDean Troyer <dtroyer@gmail.com>2019-05-09 21:51:57 -0500
commitc44f26eb7e41c28bb13ef9bd31c8ddda9e638862 (patch)
tree062fc4fea3e465ac7da63516ee77489e1acbc45a /openstackclient/network/v2/subnet.py
parent6385d64237c9973dd4c7dd53efb6664ea2c719da (diff)
downloadpython-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/subnet.py')
-rw-r--r--openstackclient/network/v2/subnet.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index 0733f37c..1f0c2d94 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -16,6 +16,8 @@
import copy
import logging
+from cliff import columns as cliff_columns
+from osc_lib.cli import format_columns
from osc_lib.cli import parseractions
from osc_lib.command import command
from osc_lib import exceptions
@@ -40,23 +42,27 @@ def _update_arguments(obj_list, parsed_args_list, option):
raise exceptions.CommandError(msg)
-def _format_allocation_pools(data):
- pool_formatted = ['%s-%s' % (pool.get('start', ''), pool.get('end', ''))
- for pool in data]
- return ','.join(pool_formatted)
+class AllocationPoolsColumn(cliff_columns.FormattableColumn):
+ def human_readable(self):
+ pool_formatted = ['%s-%s' % (pool.get('start', ''),
+ pool.get('end', ''))
+ for pool in self._value]
+ return ','.join(pool_formatted)
-def _format_host_routes(data):
- # Map the host route keys to match --host-route option.
- return utils.format_list_of_dicts(convert_entries_to_gateway(data))
+class HostRoutesColumn(cliff_columns.FormattableColumn):
+ def human_readable(self):
+ # Map the host route keys to match --host-route option.
+ return utils.format_list_of_dicts(
+ convert_entries_to_gateway(self._value))
_formatters = {
- 'allocation_pools': _format_allocation_pools,
- 'dns_nameservers': utils.format_list,
- 'host_routes': _format_host_routes,
- 'service_types': utils.format_list,
- 'tags': utils.format_list,
+ 'allocation_pools': AllocationPoolsColumn,
+ 'dns_nameservers': format_columns.ListColumn,
+ 'host_routes': HostRoutesColumn,
+ 'service_types': format_columns.ListColumn,
+ 'tags': format_columns.ListColumn,
}