Fixed subnet command host route output

Fixed the "os subnet create", "os subnet list" and
"os subnet show" command output for host routes to
improve readability and to align with the "--host-route"
option on the "os subnet create" and "os subnet set"
commands.

Change-Id: Ida69ae1a0bdb2e1648f8b5c978fc80cf1bbe752f
Closes-Bug: #1572309
This commit is contained in:
Richard Theis
2016-04-19 16:08:12 -05:00
parent a06bb28bcc
commit f753bad742

@ -14,8 +14,6 @@
"""Subnet action implementations""" """Subnet action implementations"""
import copy import copy
from json.encoder import JSONEncoder
from openstackclient.common import command from openstackclient.common import command
from openstackclient.common import exceptions from openstackclient.common import exceptions
from openstackclient.common import parseractions from openstackclient.common import parseractions
@ -31,10 +29,8 @@ def _format_allocation_pools(data):
def _format_host_routes(data): def _format_host_routes(data):
try: # Map the host route keys to match --host-route option.
return '\n'.join([JSONEncoder().encode(route) for route in data]) return utils.format_list_of_dicts(convert_entries_to_gateway(data))
except (TypeError, KeyError):
return ''
_formatters = { _formatters = {
@ -89,8 +85,9 @@ def convert_entries_to_nexthop(entries):
# Change 'gateway' entry to 'nexthop' # Change 'gateway' entry to 'nexthop'
changed_entries = copy.deepcopy(entries) changed_entries = copy.deepcopy(entries)
for entry in changed_entries: for entry in changed_entries:
entry['nexthop'] = entry['gateway'] if 'gateway' in entry:
del entry['gateway'] entry['nexthop'] = entry['gateway']
del entry['gateway']
return changed_entries return changed_entries
@ -99,8 +96,9 @@ def convert_entries_to_gateway(entries):
# Change 'nexthop' entry to 'gateway' # Change 'nexthop' entry to 'gateway'
changed_entries = copy.deepcopy(entries) changed_entries = copy.deepcopy(entries)
for entry in changed_entries: for entry in changed_entries:
entry['gateway'] = entry['nexthop'] if 'nexthop' in entry:
del entry['nexthop'] entry['gateway'] = entry['nexthop']
del entry['nexthop']
return changed_entries return changed_entries