Handling vnic type as optional

Currently there is no way to check vnci_type is supported or not from the
outside of neutron. If it's not supported, when trying to "edit port" a
Traceback was issued.
This patch checks if there is a vnci_type before accessing it in the
"edit port" view.

Change-Id: Ia3b75cb300832f01efbc933c3d5784af9b93f308
Closes-bug: #1477100
This commit is contained in:
Yves-Gwenael Bourhis 2015-07-22 13:41:43 +02:00
parent ede7402604
commit 2c2cf962c2
4 changed files with 31 additions and 25 deletions

View File

@ -892,6 +892,8 @@ types will be available to choose from.
Example ``['normal', 'direct']``
To disable VNIC type selection, set an empty list or None.
``segmentation_id_range``:
.. versionadded:: 2014.2(Juno)

View File

@ -69,19 +69,21 @@ class CreatePort(forms.SelfHandlingForm):
'OPENSTACK_NEUTRON_NETWORK', {})
supported_vnic_types = neutron_settings.get(
'supported_vnic_types', ['*'])
if supported_vnic_types == ['*']:
vnic_type_choices = VNIC_TYPES
else:
vnic_type_choices = [
vnic_type for vnic_type in VNIC_TYPES
if vnic_type[0] in supported_vnic_types
]
if supported_vnic_types:
if supported_vnic_types == ['*']:
vnic_type_choices = VNIC_TYPES
else:
vnic_type_choices = [
vnic_type for vnic_type in VNIC_TYPES
if vnic_type[0] in supported_vnic_types
]
self.fields['binding__vnic_type'] = forms.ChoiceField(
choices=vnic_type_choices,
label=_("Binding: VNIC Type"),
help_text=_("The VNIC type that is bound to the neutron port"),
required=False)
self.fields['binding__vnic_type'] = forms.ChoiceField(
choices=vnic_type_choices,
label=_("Binding: VNIC Type"),
help_text=_(
"The VNIC type that is bound to the neutron port"),
required=False)
if api.neutron.is_extension_supported(request, 'mac-learning'):
self.fields['mac_state'] = forms.BooleanField(

View File

@ -51,19 +51,21 @@ class UpdatePort(forms.SelfHandlingForm):
'OPENSTACK_NEUTRON_NETWORK', {})
supported_vnic_types = neutron_settings.get(
'supported_vnic_types', ['*'])
if supported_vnic_types == ['*']:
vnic_type_choices = VNIC_TYPES
else:
vnic_type_choices = [
vnic_type for vnic_type in VNIC_TYPES
if vnic_type[0] in supported_vnic_types
]
if supported_vnic_types:
if supported_vnic_types == ['*']:
vnic_type_choices = VNIC_TYPES
else:
vnic_type_choices = [
vnic_type for vnic_type in VNIC_TYPES
if vnic_type[0] in supported_vnic_types
]
self.fields['binding__vnic_type'] = forms.ChoiceField(
choices=vnic_type_choices,
label=_("Binding: VNIC Type"),
help_text=_("The VNIC type that is bound to the neutron port"),
required=False)
self.fields['binding__vnic_type'] = forms.ChoiceField(
choices=vnic_type_choices,
label=_("Binding: VNIC Type"),
help_text=_(
"The VNIC type that is bound to the neutron port"),
required=False)
if api.neutron.is_extension_supported(request, 'mac-learning'):
self.fields['mac_state'] = forms.BooleanField(

View File

@ -122,7 +122,7 @@ class UpdateView(forms.ModalFormView):
'tenant_id': port['tenant_id'],
'name': port['name'],
'admin_state': port['admin_state_up']}
if port['binding__vnic_type']:
if port.get('binding__vnic_type'):
initial['binding__vnic_type'] = port['binding__vnic_type']
try:
initial['mac_state'] = port['mac_learning_enabled']