Skip to content

Commit f753bad

Browse files
committed
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
1 parent a06bb28 commit f753bad

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

openstackclient/network/v2/subnet.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
"""Subnet action implementations"""
1515
import copy
1616

17-
from json.encoder import JSONEncoder
18-
1917
from openstackclient.common import command
2018
from openstackclient.common import exceptions
2119
from openstackclient.common import parseractions
@@ -31,10 +29,8 @@ def _format_allocation_pools(data):
3129

3230

3331
def _format_host_routes(data):
34-
try:
35-
return '\n'.join([JSONEncoder().encode(route) for route in data])
36-
except (TypeError, KeyError):
37-
return ''
32+
# Map the host route keys to match --host-route option.
33+
return utils.format_list_of_dicts(convert_entries_to_gateway(data))
3834

3935

4036
_formatters = {
@@ -89,8 +85,9 @@ def convert_entries_to_nexthop(entries):
8985
# Change 'gateway' entry to 'nexthop'
9086
changed_entries = copy.deepcopy(entries)
9187
for entry in changed_entries:
92-
entry['nexthop'] = entry['gateway']
93-
del entry['gateway']
88+
if 'gateway' in entry:
89+
entry['nexthop'] = entry['gateway']
90+
del entry['gateway']
9491

9592
return changed_entries
9693

@@ -99,8 +96,9 @@ def convert_entries_to_gateway(entries):
9996
# Change 'nexthop' entry to 'gateway'
10097
changed_entries = copy.deepcopy(entries)
10198
for entry in changed_entries:
102-
entry['gateway'] = entry['nexthop']
103-
del entry['nexthop']
99+
if 'nexthop' in entry:
100+
entry['gateway'] = entry['nexthop']
101+
del entry['nexthop']
104102

105103
return changed_entries
106104

0 commit comments

Comments
 (0)