Admin util: add support to get network morefs

Add a command that will make getting the network moref a lot
simpler.

nsxadmin -r networks -o list

Output:-

NSX Plugin in use: nsxv
==== [NEUTRON] List Networks ====
networks
+-----------------------------+----------------+--------------------------------------+
| type                        | moref          | name                                 |
+-----------------------------+----------------+--------------------------------------+
| DistributedVirtualPortgroup | dvportgroup-61 | edge-8-1-18d92ccd5-9f9f-4abf-9c5e-0e |
| DistributedVirtualPortgroup | dvportgroup-44 | edge-6-1-1d99f80d0-58af-436e-9f02-8b |
| Network                     | network-85     | none                                 |
| DistributedVirtualPortgroup | dvportgroup-71 | edge-9-1-113708c82-3a38-458c-80ce-8c |
| DistributedVirtualPortgroup | dvportgroup-65 | edge-7-1-17c1cc8da-0642-4014-abce-ba |
| Network                     | network-17     | VM Network                           |
| DistributedVirtualPortgroup | dvportgroup-81 | edge-14-1-1490d7f36-7558-4519-a602-3 |
| DistributedVirtualPortgroup | dvportgroup-39 | edge-4-1-13fdc6af0-f2f5-4335-9a2d-af |
| DistributedVirtualPortgroup | dvportgroup-32 | edge-2-1-1ba392d5a-66cc-4c6d-8a45-f4 |
| VirtualWire                 | virtualwire-3  | 9d0d1049-e1bf-473d-8489-5fe3d7679753 |
| DistributedVirtualPortgroup | dvportgroup-86 | edge-16-1-1ffc203ca-717d-4bb2-b7f9-e |
| VirtualWire                 | virtualwire-13 | 90a21c2d-2167-470e-b44f-34a3deb428f2 |
+-----------------------------+----------------+--------------------------------------+

Change-Id: I809a7b12c883fea22b8bacc77df924dad1a394e6
This commit is contained in:
Gary Kotton 2016-02-14 04:06:31 -08:00
parent b6b224ea98
commit 4b6add4aa9
4 changed files with 65 additions and 0 deletions

View File

@ -725,6 +725,12 @@ class Vcns(object):
else:
return uri_path
def get_scoping_objects(self):
uri = '%s/usermgmt/scopingobjects' % SERVICES_PREFIX
h, scoping_objects = self.do_request(HTTP_GET, uri, decode=False,
format='xml')
return scoping_objects
def _scopingobjects_lookup(self, type_name, object_id, name=None):
uri = '%s/usermgmt/scopingobjects' % SERVICES_PREFIX
h, so_list = self.do_request(HTTP_GET, uri, decode=False,

View File

@ -31,3 +31,4 @@ SPOOFGUARD_POLICY = 'spoofguard-policy'
DHCP_BINDING = 'dhcp-binding'
BACKUP_EDGES = 'backup-edges'
ORPHANED_EDGES = 'orphaned-edges'
NETWORKS = 'networks'

View File

@ -0,0 +1,56 @@
# 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
import xml.etree.ElementTree as et
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 utils
from vmware_nsx.shell import nsxadmin as shell
from neutron.callbacks import registry
LOG = logging.getLogger(__name__)
nsxv = utils.get_nsxv_client()
def get_networks():
nsxv = utils.get_nsxv_client()
so_list = nsxv.get_scoping_objects()
networks = []
root = et.fromstring(so_list)
for obj in root.iter('object'):
if (obj.find('objectTypeName').text == 'Network' or
obj.find('objectTypeName').text == 'VirtualWire' or
obj.find('objectTypeName').text == 'DistributedVirtualPortgroup'):
networks.append({'type': obj.find('objectTypeName').text,
'moref': obj.find('objectId').text,
'name': obj.find('name').text})
return networks
@admin_utils.output_header
def neutron_list_networks(resource, event, trigger,
**kwargs):
LOG.info(formatters.output_formatter(constants.NETWORKS, get_networks(),
['type', 'moref', 'name']))
registry.subscribe(neutron_list_networks,
constants.NETWORKS,
shell.Operations.LIST.value)

View File

@ -98,6 +98,8 @@ nsxv_resources = {
constants.DHCP_BINDING: Resource(constants.DHCP_BINDING,
[Operations.LIST.value,
Operations.NSX_UPDATE.value]),
constants.NETWORKS: Resource(constants.NETWORKS,
[Operations.LIST.value]),
}
nsxv3_resources_names = map(lambda res: res.name, nsxv3_resources.itervalues())