From 0738ec7ec48710c34bd1a525b270ee2153dcaa07 Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 4 Nov 2019 12:03:13 +0300 Subject: [PATCH] adds bridge slave list to details of interface --- interfaces/templates/interface.html | 34 ++++++++++++++++++++++++++--- interfaces/views.py | 1 + vrtManager/interface.py | 30 +++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/interfaces/templates/interface.html b/interfaces/templates/interface.html index 1693d81..2ac89d9 100644 --- a/interfaces/templates/interface.html +++ b/interfaces/templates/interface.html @@ -38,12 +38,12 @@

{% trans "Interface" %}:

-

{% trans "IPv4" %}: ({% ifequal ipv4 None %}{% trans 'None' %}{% else %}{{ ipv4_type }}{% endifequal %})

-

{% trans "IPv6" %}: ({% ifequal ipv6 None %}{% trans 'None' %}{% else %}{{ ipv6_type }}{% endifequal %})

+

{% trans "IPv4" %} ({% ifequal ipv4 None %}{% trans 'None' %}{% else %}{{ ipv4_type }}{% endifequal %}):

+

{% trans "IPv6" %} ({% ifequal ipv6 None %}{% trans 'None' %}{% else %}{{ ipv6_type }}{% endifequal %}):

{% trans "MAC Adress" %}:

{% trans "Interface Type" %}:

{% ifequal itype 'bridge' %} -

{% trans "Bridge device" %}

+

{% trans "Bridge Device" %}:

{% endifequal %}

{% trans "Boot Mode" %}:

{% trans "State" %}:

@@ -69,5 +69,33 @@

+
+ {% ifequal itype 'bridge' %} + + + + + + + + + + + + + {% for iface in slave_ifaces %} + + + + + + + + {% endfor %} + +
{% trans 'Slaves' %}
{% trans 'MAC' %}{% trans 'Name' %}{% trans 'Type' %}{% trans 'Speed' %}{% trans 'State' %}
{{ iface.mac }}{{ iface.name }}{{ iface.type }}{{ iface.speed }}{{ iface.state }}
+ {% endifequal %} +
+ {% endblock %} \ No newline at end of file diff --git a/interfaces/views.py b/interfaces/views.py index acbf440..a747120 100644 --- a/interfaces/views.py +++ b/interfaces/views.py @@ -88,6 +88,7 @@ def interface(request, compute_id, iface): ipv6 = conn.get_ipv6() ipv6_type = conn.get_ipv6_type() bridge = conn.get_bridge() + slave_ifaces = conn.get_bridge_slave_ifaces() if request.method == 'POST': if 'stop' in request.POST: diff --git a/vrtManager/interface.py b/vrtManager/interface.py index c91aaf9..ceaea18 100644 --- a/vrtManager/interface.py +++ b/vrtManager/interface.py @@ -1,5 +1,6 @@ from vrtManager.connection import wvmConnect from vrtManager import util +from xml.etree import ElementTree from libvirt import VIR_INTERFACE_XML_INACTIVE @@ -119,9 +120,34 @@ class wvmInterface(wvmConnect): return int_ipv6_ip + '/' + int_ipv6_mask def get_bridge(self): + bridge = None if self.get_type() == 'bridge': - xml = self._XMLDesc() - return util.get_xml_path(xml, "/interface/bridge/interface/@name") + bridge = util.get_xml_path(self._XMLDesc(), "/interface/bridge/interface/@name") + for iface in self.get_bridge_slave_ifaces(): + if iface.get('state') == 'up' and iface.get('speed') is not 'unknown': + bridge = iface.get('name') + return bridge + return bridge + else: + return None + + def get_bridge_slave_ifaces(self): + ifaces = list() + if self.get_type() == 'bridge': + tree = ElementTree.fromstring(self._XMLDesc()) + for iface in tree.findall("./bridge/"): + address = state = speed = None + name = iface.get('name') + type = iface.get('type') + link = iface.find('link') + if link is not None: + state = link.get('state') + speed = link.get('speed') + mac = iface.find('mac') + if mac is not None: + address = mac.get('address') + ifaces.append({'name': name, 'type': type, 'state': state, 'speed': speed, 'mac': address}) + return ifaces else: return None