summaryrefslogtreecommitdiff
path: root/openstackclient/network/v2
diff options
context:
space:
mode:
authorycx <yanpq@awcloud.com>2017-06-27 10:12:06 +0800
committerDean Troyer <dtroyer@gmail.com>2017-11-15 22:28:46 +0000
commite7ef9e855677051383446e18e393b1f96158331b (patch)
treeb50e1b1ba001f25a9beb4f940068822ad509b64e /openstackclient/network/v2
parentb230ba73cdfd91e07fe168ee46a928f5556fad55 (diff)
downloadpython-openstackclient-e7ef9e855677051383446e18e393b1f96158331b.tar.gz
Network: Add interfaces info in router show
Add a list of interfaces info in the output of 'openstack router show'. The information of router interface are: IP address, subnet ID and port ID. Co-Authored-By: Dongcan Ye <hellochosen@gmail.com> Change-Id: I1252986122122defffe795292b83dc4e84481c7e Closes-Bug: #1675489
Diffstat (limited to 'openstackclient/network/v2')
-rw-r--r--openstackclient/network/v2/router.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index 4f908537..caf3236a 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -36,7 +36,7 @@ def _format_admin_state(state):
return 'UP' if state else 'DOWN'
-def _format_external_gateway_info(info):
+def _format_router_info(info):
try:
return json.dumps(info)
except (TypeError, KeyError):
@@ -54,7 +54,7 @@ def _format_routes(routes):
_formatters = {
'admin_state_up': _format_admin_state,
'is_admin_state_up': _format_admin_state,
- 'external_gateway_info': _format_external_gateway_info,
+ 'external_gateway_info': _format_router_info,
'availability_zones': utils.format_list,
'availability_zone_hints': utils.format_list,
'routes': _format_routes,
@@ -69,6 +69,8 @@ def _get_columns(item):
'is_distributed': 'distributed',
'is_admin_state_up': 'admin_state_up',
}
+ if hasattr(item, 'interfaces_info'):
+ column_map['interfaces_info'] = 'interfaces_info'
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
@@ -657,7 +659,22 @@ class ShowRouter(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_router(parsed_args.router, ignore_missing=False)
+ interfaces_info = []
+ filters = {}
+ filters['device_id'] = obj.id
+ for port in client.ports(**filters):
+ if port.device_owner != "network:router_gateway":
+ for ip_spec in port.fixed_ips:
+ int_info = {
+ 'port_id': port.id,
+ 'ip_address': ip_spec.get('ip_address'),
+ 'subnet_id': ip_spec.get('subnet_id')
+ }
+ interfaces_info.append(int_info)
+
+ setattr(obj, 'interfaces_info', interfaces_info)
display_columns, columns = _get_columns(obj)
+ _formatters['interfaces_info'] = _format_router_info
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (display_columns, data)