[Admin-Util][NSX-v3]: list networks which are missing from backend

To run this: nsxadmin -r networks -o list-mismatches

Positive output example:
All internal networks exist on the NSX manager

Negative output example:
Found 4 internal networks missing from the NSX manager
+---------+--------------------------------------+--------------------------------------+
| name    | neutron_id                           | nsx_id                               |
+---------+--------------------------------------+--------------------------------------+
| net3    | 577eced7-cf03-4048-9b49-5180112137a7 | 731d0a8a-d7ec-4ea5-8852-3825b51a8fd4 |
| private | c42e10e6-a6ab-47b1-869a-b9bc15a86db9 | 92aa4713-bcb9-4248-829b-2e9e907d1c03 |
| net1    | 951039e4-84ca-43a2-a64e-24f37ca7a5ce | d45faea4-1320-4cdd-8bd3-7093afca0e2f |
| net2    | b11685f8-4481-4ee4-aa8c-726f0cdedb13 | 34afd33f-6c01-4ef6-8e25-00cfa3e77fef |
+---------+--------------------------------------+--------------------------------------+

Change-Id: I526c80ce2eb9b49feaed50ce64781b3f7a928b23
This commit is contained in:
Adit Sarfaty 2016-05-29 17:29:52 +03:00
parent 8486010cd4
commit 6a183663c8
3 changed files with 81 additions and 2 deletions

View File

@ -20,6 +20,9 @@ NSX_INI = '/etc/neutron/plugins/vmware/nsx.ini'
NSXV3_PLUGIN = 'vmware_nsx.plugin.NsxV3Plugin'
NSXV_PLUGIN = 'vmware_nsx.plugin.NsxVPlugin'
# Common Resource Constants
NETWORKS = 'networks'
# NSXV3 Resource Constants
FIREWALL_SECTIONS = 'firewall-sections'
FIREWALL_NSX_GROUPS = 'nsx-security-groups'
@ -32,5 +35,4 @@ DHCP_BINDING = 'dhcp-binding'
BACKUP_EDGES = 'backup-edges'
ORPHANED_EDGES = 'orphaned-edges'
MISSING_EDGES = 'missing-edges'
NETWORKS = 'networks'
METADATA = 'metadata'

View File

@ -0,0 +1,75 @@
# Copyright 2016 VMware, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from vmware_nsx._i18n import _LI
from vmware_nsx.common import exceptions as nsx_exc
from vmware_nsx.db import db as nsx_db
from vmware_nsx.nsxlib import v3 as nsxlib
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 import nsxadmin as shell
from neutron.callbacks import registry
from neutron import context as neutron_context
from neutron.db import db_base_plugin_v2
LOG = logging.getLogger(__name__)
def get_network_nsx_id(context, neutron_id):
# get the nsx switch id from the DB mapping
mappings = nsx_db.get_nsx_switch_ids(context.session, neutron_id)
if mappings and len(mappings) > 0:
return mappings[0]
@admin_utils.output_header
def list_missing_networks(resource, event, trigger, **kwargs):
"""List neutron networks that are missing the NSX backend network
"""
plugin = db_base_plugin_v2.NeutronDbPluginV2()
admin_cxt = neutron_context.get_admin_context()
neutron_networks = plugin.get_networks(admin_cxt)
networks = []
for net in neutron_networks:
neutron_id = net['id']
# get the network nsx id from the mapping table
nsx_id = get_network_nsx_id(admin_cxt, neutron_id)
if not nsx_id:
# skip external networks
pass
else:
try:
nsxlib.get_logical_switch(nsx_id)
except nsx_exc.ResourceNotFound:
networks.append({'name': net['name'],
'neutron_id': neutron_id,
'nsx_id': nsx_id})
if len(networks) > 0:
title = _LI("Found %d internal networks missing from the NSX "
"manager:") % len(networks)
LOG.info(formatters.output_formatter(
title, networks,
['name', 'neutron_id', 'nsx_id']))
else:
LOG.info(_LI("All internal networks exist on the NSX manager"))
registry.subscribe(list_missing_networks,
constants.NETWORKS,
shell.Operations.LIST_MISMATCHES.value)

View File

@ -82,7 +82,9 @@ nsxv3_resources = {
Operations.NSX_LIST.value,
Operations.NSX_CLEAN.value,
Operations.NEUTRON_LIST.value,
Operations.NEUTRON_CLEAN.value])
Operations.NEUTRON_CLEAN.value]),
constants.NETWORKS: Resource(constants.NETWORKS,
[Operations.LIST_MISMATCHES.value])
}
# Add supported NSX-V resources in this dictionary