diff --git a/vmware_nsx/plugins/nsx_v/vshield/vcns.py b/vmware_nsx/plugins/nsx_v/vshield/vcns.py index 12e3483af6..e638d076b8 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/vcns.py +++ b/vmware_nsx/plugins/nsx_v/vshield/vcns.py @@ -81,6 +81,8 @@ IPAM_POOL_SERVICE = "ipam/pools" CSR = "csr" CERTIFICATE = "certificate" +NETWORK_TYPES = ['Network', 'VirtualWire', 'DistributedVirtualPortgroup'] + def retry_upon_exception(exc, delay=500, max_delay=4000, max_attempts=cfg.CONF.nsxv.retries): @@ -791,14 +793,14 @@ class Vcns(object): format='xml') return scoping_objects - def _scopingobjects_lookup(self, type_name, object_id, name=None): + def _scopingobjects_lookup(self, type_names, object_id, name=None): uri = '%s/usermgmt/scopingobjects' % SERVICES_PREFIX h, so_list = self.do_request(HTTP_GET, uri, decode=False, format='xml') root = et.fromstring(so_list) for obj in root.iter('object'): - if (obj.find('objectTypeName').text == type_name and + if (obj.find('objectTypeName').text in type_names and obj.find('objectId').text == object_id and (name is None or obj.find('name').text == name)): return True @@ -806,19 +808,13 @@ class Vcns(object): return False def validate_datacenter_moid(self, object_id): - return self._scopingobjects_lookup('Datacenter', object_id) + return self._scopingobjects_lookup(['Datacenter'], object_id) def validate_network(self, object_id): - return (self._scopingobjects_lookup('Network', object_id) or - self._scopingobjects_lookup('DistributedVirtualPortgroup', - object_id) or - self._scopingobjects_lookup('VirtualWire', object_id)) + return self._scopingobjects_lookup(NETWORK_TYPES, object_id) def validate_network_name(self, object_id, name): - return (self._scopingobjects_lookup('Network', object_id, name) or - self._scopingobjects_lookup('DistributedVirtualPortgroup', - object_id, name) or - self._scopingobjects_lookup('VirtualWire', object_id, name)) + return self._scopingobjects_lookup(NETWORK_TYPES, object_id, name) def validate_vdn_scope(self, object_id): uri = '%s/scopes' % VDN_PREFIX