From f753bad742476cc9a0fc1e5fef8e6c8253eff7a7 Mon Sep 17 00:00:00 2001 From: Richard Theis Date: Tue, 19 Apr 2016 16:08:12 -0500 Subject: [PATCH] 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 --- openstackclient/network/v2/subnet.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py index 715e662026..fb441cbf46 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -14,8 +14,6 @@ """Subnet action implementations""" import copy -from json.encoder import JSONEncoder - from openstackclient.common import command from openstackclient.common import exceptions from openstackclient.common import parseractions @@ -31,10 +29,8 @@ def _format_allocation_pools(data): def _format_host_routes(data): - try: - return '\n'.join([JSONEncoder().encode(route) for route in data]) - except (TypeError, KeyError): - return '' + # Map the host route keys to match --host-route option. + return utils.format_list_of_dicts(convert_entries_to_gateway(data)) _formatters = { @@ -89,8 +85,9 @@ def convert_entries_to_nexthop(entries): # Change 'gateway' entry to 'nexthop' changed_entries = copy.deepcopy(entries) for entry in changed_entries: - entry['nexthop'] = entry['gateway'] - del entry['gateway'] + if 'gateway' in entry: + entry['nexthop'] = entry['gateway'] + del entry['gateway'] return changed_entries @@ -99,8 +96,9 @@ def convert_entries_to_gateway(entries): # Change 'nexthop' entry to 'gateway' changed_entries = copy.deepcopy(entries) for entry in changed_entries: - entry['gateway'] = entry['nexthop'] - del entry['nexthop'] + if 'nexthop' in entry: + entry['gateway'] = entry['nexthop'] + del entry['nexthop'] return changed_entries