NSX|V: fix validations for non-ascii characters
A non-ascii names will be ignored. Change-Id: Ia7aa1b054f6b01111f7fb25f921a6e3469001395
This commit is contained in:
parent
db4ba11c4f
commit
3a65ce0ae0
@ -108,10 +108,15 @@ def check_and_truncate(display_name):
|
||||
return display_name or ''
|
||||
|
||||
|
||||
def normalize_xml(data):
|
||||
data = data.encode('ascii', 'ignore')
|
||||
return et.fromstring(data)
|
||||
|
||||
|
||||
def _get_bad_request_error_code(e):
|
||||
"""Get the error code out of the exception"""
|
||||
try:
|
||||
desc = et.fromstring(e.response)
|
||||
desc = normalize_xml(e.response)
|
||||
return int(desc.find('errorCode').text)
|
||||
except Exception:
|
||||
pass
|
||||
|
@ -85,15 +85,6 @@ CERTIFICATE = "certificate"
|
||||
NETWORK_TYPES = ['Network', 'VirtualWire', 'DistributedVirtualPortgroup']
|
||||
|
||||
|
||||
def _get_bad_request_error_code(e):
|
||||
"""Get the error code out of the exception"""
|
||||
try:
|
||||
desc = et.fromstring(e.response)
|
||||
return int(desc.find('errorCode').text)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def retry_upon_exception_exclude_error_codes(
|
||||
exc, excluded_errors, delay=0.5, max_delay=4, max_attempts=0):
|
||||
if not max_attempts:
|
||||
@ -549,7 +540,7 @@ class Vcns(object):
|
||||
def get_security_group_id(self, sg_name):
|
||||
"""Returns NSXv security group id which match the given name."""
|
||||
h, secgroups = self.list_security_groups()
|
||||
root = et.fromstring(secgroups)
|
||||
root = utils.normalize_xml(secgroups)
|
||||
for sg in root.iter('securitygroup'):
|
||||
if sg.find('name').text == sg_name:
|
||||
return sg.find('objectId').text
|
||||
@ -624,7 +615,7 @@ class Vcns(object):
|
||||
def get_section_id(self, section_name):
|
||||
"""Retrieve the id of a section from nsx."""
|
||||
h, firewall_config = self.get_dfw_config()
|
||||
root = et.fromstring(firewall_config)
|
||||
root = utils.normalize_xml(firewall_config)
|
||||
for sec in root.iter('section'):
|
||||
if sec.attrib['name'] == section_name:
|
||||
return sec.attrib['id']
|
||||
@ -814,7 +805,7 @@ class Vcns(object):
|
||||
uri = '%s/usermgmt/scopingobjects' % SERVICES_PREFIX
|
||||
h, so_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||
format='xml')
|
||||
root = et.fromstring(so_list)
|
||||
root = utils.normalize_xml(so_list)
|
||||
for obj in root.iter('object'):
|
||||
if (obj.find('objectTypeName').text in type_names and
|
||||
obj.find('objectId').text == object_id and
|
||||
@ -836,8 +827,7 @@ class Vcns(object):
|
||||
uri = '%s/scopes' % VDN_PREFIX
|
||||
h, scope_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||
format='xml')
|
||||
|
||||
root = et.fromstring(scope_list)
|
||||
root = utils.normalize_xml(scope_list)
|
||||
for obj_id in root.iter('objectId'):
|
||||
if obj_id.text == object_id:
|
||||
return True
|
||||
@ -848,8 +838,7 @@ class Vcns(object):
|
||||
uri = '%s/switches' % VDN_PREFIX
|
||||
h, dvs_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||
format='xml')
|
||||
|
||||
root = et.fromstring(dvs_list)
|
||||
root = utils.normalize_xml(dvs_list)
|
||||
for obj_id in root.iter('objectId'):
|
||||
if obj_id.text == object_id:
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user