1414"""Subnet action implementations"""
1515import copy
1616
17- from json .encoder import JSONEncoder
18-
1917from openstackclient .common import command
2018from openstackclient .common import exceptions
2119from openstackclient .common import parseractions
@@ -31,10 +29,8 @@ def _format_allocation_pools(data):
3129
3230
3331def _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