NSX|V: validate that entries exist

The VC does not commit to returning values if data does not exist.
So we need to check prior if the actual values are set prior to
reading

Change-Id: I9d7d4a8420e2f1af1103b8fed27da14075745397
This commit is contained in:
Gary Kotton 2017-02-15 22:35:22 +02:00
parent 39166ed163
commit 102a2c0347

View File

@ -549,7 +549,10 @@ class DvsManager(object):
for index in range(2): for index in range(2):
vm_group = None vm_group = None
entry_id = index + 1 entry_id = index + 1
for group in cluster_config.group: groups = []
if hasattr(cluster_config, 'group'):
groups = cluster_config.group
for group in groups:
if 'neutron-group-%s' % entry_id in group.name: if 'neutron-group-%s' % entry_id in group.name:
vm_group = group vm_group = group
break break
@ -577,7 +580,10 @@ class DvsManager(object):
num_host_groups = len(host_group_names) num_host_groups = len(host_group_names)
for index, vm in enumerate(vms, start=1): for index, vm in enumerate(vms, start=1):
vmGroup = None vmGroup = None
for group in cluster_config.group: groups = []
if hasattr(cluster_config, 'group'):
groups = cluster_config.group
for group in groups:
if 'neutron-group-%s' % index in group.name: if 'neutron-group-%s' % index in group.name:
vmGroup = group vmGroup = group
break break
@ -588,8 +594,11 @@ class DvsManager(object):
[vm], vmGroup) [vm], vmGroup)
config_spec.groupSpec.append(groupSpec) config_spec.groupSpec.append(groupSpec)
config_rule = None config_rule = None
rules = []
if hasattr(cluster_config, 'rule'):
rules = cluster_config.rule
# Create the config rule if it does not exist # Create the config rule if it does not exist
for rule in cluster_config.rule: for rule in rules:
if 'neutron-rule-%s' % index in rule.name: if 'neutron-rule-%s' % index in rule.name:
config_rule = rule config_rule = rule
break break
@ -614,7 +623,10 @@ class DvsManager(object):
"configurationEx") "configurationEx")
for host_group_name in host_group_names: for host_group_name in host_group_names:
found = False found = False
for group in cluster_config.group: groups = []
if hasattr(cluster_config, 'group'):
groups = cluster_config.group
for group in groups:
if host_group_name == group.name: if host_group_name == group.name:
found = True found = True
break break
@ -627,7 +639,10 @@ class DvsManager(object):
for index in range(2): for index in range(2):
entry_id = index + 1 entry_id = index + 1
vmGroup = None vmGroup = None
for group in cluster_config.group: groups = []
if hasattr(cluster_config, 'group'):
groups = cluster_config.group
for group in groups:
if 'neutron-group-%s' % entry_id in group.name: if 'neutron-group-%s' % entry_id in group.name:
vmGroup = group vmGroup = group
break break
@ -640,8 +655,11 @@ class DvsManager(object):
update_cluster = True update_cluster = True
config_rule = None config_rule = None
rules = []
if hasattr(cluster_config, 'rule'):
rules = cluster_config.rule
# Create the config rule if it does not exist # Create the config rule if it does not exist
for rule in cluster_config.rule: for rule in rules:
if 'neutron-rule-%s' % entry_id in rule.name: if 'neutron-rule-%s' % entry_id in rule.name:
config_rule = rule config_rule = rule
break break