From db7ec670100028877af43120c5f17738ed8ac235 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Tue, 20 Feb 2018 14:22:43 +0200 Subject: [PATCH] NSX-V Admin Utils: List BGP GW edges Usage: nsxadmin -r bgp-gw-edge -o list Change-Id: Icc82895e6c981ec35b2dbb31c32ceaa05d9e9f11 --- doc/source/admin_util.rst | 4 ++++ .../admin/plugins/nsxv/resources/gw_edges.py | 21 +++++++++++++++++++ vmware_nsx/shell/resources.py | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/source/admin_util.rst b/doc/source/admin_util.rst index d51634b7f2..1b9223601e 100644 --- a/doc/source/admin_util.rst +++ b/doc/source/admin_util.rst @@ -440,6 +440,10 @@ BGP GW edges nsxadmin -r bgp-gw-edge -o delete --property gw-edge-id= +- List BGP GW edges:: + + nsxadmin -r bgp-gw-edge -o list + - Add a redistribution rule to a BGP GW edges:: nsxadmin -r routing-redistribution-rule -o create --property edge-ids=[,...] [--property prefix=] --property learner-protocol= --property learn-from=ospf,bgp,connected,static --property action= diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/gw_edges.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/gw_edges.py index 38d0367ba0..3b27f8969a 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/gw_edges.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/gw_edges.py @@ -27,6 +27,7 @@ from vmware_nsx.services.dynamic_routing.nsx_v import driver as nsxv_bgp from vmware_nsx.shell.admin.plugins.common import constants from vmware_nsx.shell.admin.plugins.common import formatters from vmware_nsx.shell.admin.plugins.common import utils as admin_utils +from vmware_nsx.shell.admin.plugins.nsxv.resources import utils as v_utils from vmware_nsx.shell import resources as shell LOG = logging.getLogger(__name__) @@ -218,6 +219,23 @@ def delete_bgp_gw(resource, event, trigger, **kwargs): return +def list_bgp_edges(resource, event, trigger, **kwargs): + bgp_edges = [] + edges = v_utils.get_nsxv_backend_edges() + for edge in edges: + bgp_config = nsxv.get_routing_bgp_config(edge['id']) + if bgp_config['bgp']['enabled']: + bgp_edges.append({'name': edge['name'], + 'edge_id': edge['id'], + 'local_as': bgp_config['bgp']['localAS']}) + if not bgp_edges: + LOG.info("No BGP GW edges found") + return + + headers = ['name', 'edge_id', 'local_as'] + LOG.info(formatters.output_formatter(constants.EDGES, bgp_edges, headers)) + + @admin_utils.output_header def create_redis_rule(resource, event, trigger, **kwargs): usage = ("nsxadmin -r routing-redistribution-rule -o create " @@ -365,6 +383,9 @@ registry.subscribe(create_bgp_gw, registry.subscribe(delete_bgp_gw, constants.BGP_GW_EDGE, shell.Operations.DELETE.value) +registry.subscribe(list_bgp_edges, + constants.BGP_GW_EDGE, + shell.Operations.LIST.value) registry.subscribe(create_redis_rule, constants.ROUTING_REDIS_RULE, shell.Operations.CREATE.value) diff --git a/vmware_nsx/shell/resources.py b/vmware_nsx/shell/resources.py index b665980f3b..aedd13bd0d 100644 --- a/vmware_nsx/shell/resources.py +++ b/vmware_nsx/shell/resources.py @@ -202,7 +202,8 @@ nsxv_resources = { [Operations.VALIDATE.value]), constants.BGP_GW_EDGE: Resource(constants.BGP_GW_EDGE, [Operations.CREATE.value, - Operations.DELETE.value]), + Operations.DELETE.value, + Operations.LIST.value]), constants.ROUTING_REDIS_RULE: Resource(constants.ROUTING_REDIS_RULE, [Operations.CREATE.value, Operations.DELETE.value]),