Merge "Remove datanetworks from interface commands in gui"

This commit is contained in:
Zuul 2019-06-27 18:45:29 +00:00 committed by Gerrit Code Review
commit 267c93389c
8 changed files with 126 additions and 37 deletions

View File

@ -2008,8 +2008,8 @@ class Interface(base.APIResourceWrapper):
"""Wrapper for Inventory Interfaces"""
_attrs = ['id', 'uuid', 'ifname', 'ifclass', 'iftype', 'imtu', 'imac',
'networks', 'aemode', 'txhashpolicy', 'vlan_id',
'uses', 'used_by', 'ihost_uuid', 'datanetworks',
'aemode', 'txhashpolicy', 'vlan_id',
'uses', 'used_by', 'ihost_uuid',
'ipv4_mode', 'ipv6_mode', 'ipv4_pool', 'ipv6_pool',
'sriov_numvfs', 'sriov_vf_driver']
@ -2018,10 +2018,6 @@ class Interface(base.APIResourceWrapper):
if not self.ifname:
self.ifname = '(' + str(self.uuid)[-8:] + ')'
@property
def datanetworks_csv(self):
return ",".join(self.datanetworks)
def host_interface_list(request, host_id):
interfaces = cgtsclient(request).iinterface.list(host_id)
@ -2124,6 +2120,49 @@ def interface_network_remove(request, interface_network_uuid):
return cgtsclient(request).interface_network.remove(interface_network_uuid)
class InterfaceDataNetwork(base.APIResourceWrapper):
"""Wrapper for Inventory Interface Networks"""
_attrs = ['forihostid', 'id', 'uuid', 'interface_id',
'interface_uuid', 'ifname', 'datanetwork_id',
'datanetwork_uuid', 'datanetwork_name', 'network_type']
def __init__(self, apiresource):
super(InterfaceDataNetwork, self).__init__(apiresource)
def interface_datanetwork_list_by_host(request, host_uuid):
interface_datanetworks = cgtsclient(request).interface_datanetwork.\
list_by_host(host_uuid)
return [InterfaceDataNetwork(n) for n in interface_datanetworks]
def interface_datanetwork_list_by_interface(request, interface_uuid):
interface_datanetworks = cgtsclient(request).interface_datanetwork.\
list_by_interface(interface_uuid)
return [InterfaceDataNetwork(n) for n in interface_datanetworks]
def interface_datanetwork_get(request, interface_datanetwork_uuid):
interface_datanetwork = cgtsclient(request).interface_datanetwork.get(
interface_datanetwork_uuid)
if not interface_datanetwork:
raise ValueError(
'No match found for interface_datanetwork_uuid "%s".'
% interface_datanetwork_uuid)
return InterfaceDataNetwork(interface_datanetwork)
def interface_datanetwork_assign(request, **kwargs):
interface_datanetwork = cgtsclient(request).interface_datanetwork.\
assign(**kwargs)
return InterfaceNetwork(interface_datanetwork)
def interface_datanetwork_remove(request, interface_datanetwork_uuid):
return cgtsclient(request).interface_datanetwork.remove(
interface_datanetwork_uuid)
class Address(base.APIResourceWrapper):
"""Wrapper for Inventory Addresses"""

View File

@ -401,15 +401,14 @@ class AddInterface(forms.SelfHandlingForm):
# Populate Data Network Choices by querying SysInv
self.extras = {}
interfaces = sysinv.host_interface_list(self.request, host_uuid)
used_datanets = []
for i in interfaces:
if i.ifclass == 'data' and \
i.datanetworks_csv and \
i.uuid != this_interface_id:
used_datanets = used_datanets + \
i.datanetworks_csv.split(",")
ifdns = sysinv.interface_datanetwork_list_by_host(self.request,
host_uuid)
for i in ifdns:
if not current_interface or \
i.interface_uuid != current_interface.uuid:
used_datanets.append(i.datanetwork_name)
datanet_choices = []
datanet_filtered = []
@ -692,6 +691,20 @@ class UpdateInterface(AddInterface):
else:
self.fields['aemode'].choices = self.AE_MODE_CHOICES
if ifclass_val == 'data':
interface_datanetworks =\
sysinv.interface_datanetwork_list_by_interface(
self.request, this_interface_id)
# Load the networks associated with this interface
datanetwork_choices = self.fields['datanetworks_data'].choices
datanetwork_choice_dict = dict(datanetwork_choices)
initial_datanetworks = []
for i in interface_datanetworks:
for name in datanetwork_choice_dict.keys():
if i.datanetwork_name == name:
initial_datanetworks.append(name)
self.fields['datanetworks_data'].initial = initial_datanetworks
# Populate Address Pool selections
pools = sysinv.address_pool_list(self.request)
self.fields['ipv4_pool'].choices = _get_ipv4_pool_choices(pools)
@ -776,6 +789,7 @@ class UpdateInterface(AddInterface):
networks = cleaned_data.pop('networks', [])
interface_networks = sysinv.interface_network_list_by_interface(
self.request, interface_id)
network_ids = []
networks_to_add = []
networks_to_remove = []
@ -800,6 +814,38 @@ class UpdateInterface(AddInterface):
cleaned_data['networks_to_add'] = networks_to_add
cleaned_data['interface_networks_to_remove'] = \
interface_networks_to_remove
datanetwork_names = cleaned_data.pop('datanetworks', [])
interface_datanetworks = \
sysinv.interface_datanetwork_list_by_interface(
self.request, interface_id)
datanetwork_uuids = []
datanetworks_to_add = []
datanetworks_to_remove = []
interface_datanetworks_to_remove = []
if ifclass == 'data' and datanetwork_names:
for i in interface_datanetworks:
datanetworks_to_remove.append(i.datanetwork_name)
datanetworks_list = sysinv.data_network_list(self.request)
for n in datanetwork_names.split(","):
for dn in datanetworks_list:
if dn.name == n:
datanetwork_uuids.append(dn.uuid)
if dn.name in datanetworks_to_remove:
datanetworks_to_remove.remove(dn.name)
else:
datanetworks_to_add.append(dn.uuid)
for i in interface_datanetworks:
if i.datanetwork_name in datanetworks_to_remove:
interface_datanetworks_to_remove.append(i.uuid)
else:
for i in interface_datanetworks:
interface_datanetworks_to_remove.append(i.uuid)
cleaned_data['datanetworks'] = datanetwork_uuids
cleaned_data['datanetworks_to_add'] = datanetworks_to_add
cleaned_data['interface_datanetworks_to_remove'] = \
interface_datanetworks_to_remove
return cleaned_data
def handle(self, request, data):
@ -844,12 +890,6 @@ class UpdateInterface(AddInterface):
data['ifname'] = p.get_port_display_name()
break
if current_interface.ifclass == 'data':
data['datanetworks'] = 'none'
if not data['datanetworks']:
del data['datanetworks']
if 'sriov_numvfs' in data:
data['sriov_numvfs'] = str(data['sriov_numvfs'])
@ -883,6 +923,9 @@ class UpdateInterface(AddInterface):
if data['interface_networks_to_remove']:
for n in data['interface_networks_to_remove']:
sysinv.interface_network_remove(request, n)
if data['interface_datanetworks_to_remove']:
for n in data['interface_datanetworks_to_remove']:
sysinv.interface_datanetwork_remove(request, n)
# Assign networks to the interface
ifnet_data = {}
@ -893,10 +936,17 @@ class UpdateInterface(AddInterface):
for n in data['networks_to_add']:
ifnet_data['network_uuid'] = n
sysinv.interface_network_assign(request, **ifnet_data)
elif data['datanetworks_to_add']:
for n in data['datanetworks_to_add']:
ifnet_data['datanetwork_uuid'] = n
sysinv.interface_datanetwork_assign(request, **ifnet_data)
del data['networks']
del data['networks_to_add']
del data['interface_networks_to_remove']
del data['datanetworks']
del data['datanetworks_to_add']
del data['interface_datanetworks_to_remove']
interface = sysinv.host_interface_update(request,
interface_id,
**data)

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2013-2016 Wind River Systems, Inc.
# Copyright (c) 2013-2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@ -158,6 +158,11 @@ def get_platform_networks(interface):
return platform_networks
def get_data_networks(interface):
data_networks = ", ".join(interface.data_network_names)
return data_networks
def get_link_url(interface):
return reverse("horizon:admin:inventory:viewinterface",
args=(interface.host_id, interface.uuid))
@ -194,8 +199,9 @@ class InterfacesTable(tables.DataTable):
platform_networks = tables.Column(get_platform_networks,
verbose_name=_('Platform Network(s)'))
datanetworks_csv = tables.Column('datanetworks_csv',
datanetworks_csv = tables.Column(get_data_networks,
verbose_name=_('Data Network(s)'))
attributes = tables.Column(get_attributes,
verbose_name=_('Attributes'))

View File

@ -260,10 +260,7 @@ class UpdateView(forms.ModalFormView):
def get_initial(self):
interface = self._get_object()
datanetworks_csv = []
if interface.datanetworks_csv:
for pn in interface.datanetworks_csv.split(","):
datanetworks_csv.append(str(pn))
try:
host = stx_api.sysinv.host_get(self.request, interface.host_id)
except Exception:
@ -289,10 +286,6 @@ class UpdateView(forms.ModalFormView):
# 'ports': interface.ports,
# 'uses': interface.uses,
'ifclass': interface.ifclass,
'datanetworks_csv_data': datanetworks_csv,
'datanetworks_csv_data-external': datanetworks_csv,
'datanetworks_csv_pci': datanetworks_csv,
'datanetworks_csv_sriov': datanetworks_csv,
'sriov_numvfs': interface.sriov_numvfs,
'sriov_vf_driver': interface.sriov_vf_driver,
'imtu': interface.imtu,

View File

@ -556,6 +556,15 @@ class InterfacesTab(tabs.TableTab):
interface_network.network_name)
i.platform_network_names = platform_network_names
data_network_names = []
if i.ifclass == 'data':
for interface_datanetwork in stx_api.sysinv.\
interface_datanetwork_list_by_interface(
self.request, i.uuid):
data_network_names.append(
interface_datanetwork.datanetwork_name)
i.data_network_names = data_network_names
if i.iftype == 'ethernet':
i.dpdksupport = [p.dpdksupport for p in host.ports if
i.uuid == p.interface_uuid]

View File

@ -1,9 +1,6 @@
{% for interfaces in ifProfile.interfaces %}
<li>
<strong>{{ interfaces.ifname }}</strong> {{": "}} {{ interfaces.ifclass }}
{% if interfaces.ifclass == 'data' %}
{{"("}} {{ interfaces.datanetworks_csv }} {{")"}}
{% endif %}
{{ " | " }} {{ interfaces.iftype }}
{% if interfaces.iftype != 'ae' and interfaces.iftype != 'vlan' %}
{{ " | " }}<u>{{"PORTS ="}} {{ interfaces.ports }}</u>

View File

@ -28,9 +28,6 @@
{% for interfaces in host.interfaces %}
<li>
<strong>{{ interfaces.ifname }}</strong> {{": "}} {{ interfaces.ifclass }}
{% if interfaces.ifclass == 'data' %}
{{"("}} {{ interfaces.datanetworks_csv }} {{")"}}
{% endif %}
{{ " | " }} {{ interfaces.iftype }}
{% if interfaces.iftype != 'ae' and interfaces.iftype != 'vlan' %}
{{ " | " }}<u>{{"PORTS ="}} {{ interfaces.ports }}</u>

View File

@ -19,8 +19,6 @@
<dt>{% trans "Interface Class" %}</dt>
<dd>{{ interface.ifclass|default:_("None") }}</dd>
{% if interface.ifclass == "data" %}
<dt>{% trans "Data Networks" %}</dt>
<dd>{{ interface.datanetworks_csv|default:_("None") }}</dd>
<dt>{% trans "IPv4 Mode" %}</dt>
<dd>{{ interface.ipv4_mode|default:_("Disabled") }}</dd>
{% if interface.ipv4_mode == "pool" %}