diff --git a/vmware_nsx/plugins/nsx_v/vshield/vcns.py b/vmware_nsx/plugins/nsx_v/vshield/vcns.py index 38dfef5560..bf1402d895 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/vcns.py +++ b/vmware_nsx/plugins/nsx_v/vshield/vcns.py @@ -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, diff --git a/vmware_nsx/shell/admin/plugins/common/constants.py b/vmware_nsx/shell/admin/plugins/common/constants.py index 86eaad20f0..095e5b1887 100644 --- a/vmware_nsx/shell/admin/plugins/common/constants.py +++ b/vmware_nsx/shell/admin/plugins/common/constants.py @@ -31,3 +31,4 @@ SPOOFGUARD_POLICY = 'spoofguard-policy' DHCP_BINDING = 'dhcp-binding' BACKUP_EDGES = 'backup-edges' ORPHANED_EDGES = 'orphaned-edges' +NETWORKS = 'networks' diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/networks.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/networks.py new file mode 100644 index 0000000000..0a9c7037d2 --- /dev/null +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/networks.py @@ -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) diff --git a/vmware_nsx/shell/nsxadmin.py b/vmware_nsx/shell/nsxadmin.py index 0ca68fb869..7ef7ee87e7 100644 --- a/vmware_nsx/shell/nsxadmin.py +++ b/vmware_nsx/shell/nsxadmin.py @@ -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())