From 2f1b11b3caefae61e398b8dcec97da438f416188 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 12 Feb 2021 16:05:16 +0300 Subject: [PATCH] reorganize host interfaces. remove it from instance methods --- instances/models.py | 4 ---- instances/templates/add_instance_network_block.html | 2 +- instances/templates/instances/settings_tab.html | 2 +- interfaces/views.py | 3 ++- vrtManager/connection.py | 4 ++-- vrtManager/interface.py | 13 ++++++------- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/instances/models.py b/instances/models.py index ef95154..68d2ecc 100644 --- a/instances/models.py +++ b/instances/models.py @@ -204,10 +204,6 @@ class Instance(models.Model): def formats(self): return self.proxy.get_image_formats() - @cached_property - def interfaces(self): - return self.proxy.get_ifaces() - class PermissionSet(models.Model): """ diff --git a/instances/templates/add_instance_network_block.html b/instances/templates/add_instance_network_block.html index 6d82fd5..724ca80 100644 --- a/instances/templates/add_instance_network_block.html +++ b/instances/templates/add_instance_network_block.html @@ -27,7 +27,7 @@ {% for c_net in networks_host %} {% endfor %} - {% for c_iface in instance.interfaces %} + {% for c_iface in interfaces_host %} {% endfor %} diff --git a/instances/templates/instances/settings_tab.html b/instances/templates/instances/settings_tab.html index 2371258..de17658 100644 --- a/instances/templates/instances/settings_tab.html +++ b/instances/templates/instances/settings_tab.html @@ -401,7 +401,7 @@ {% for c_net in networks_host %} {% endfor %} - {% for c_iface in instance.interfaces %} + {% for c_iface in interfaces_host %} {% endfor %} diff --git a/interfaces/views.py b/interfaces/views.py index a6f8c0b..0ef2cb6 100644 --- a/interfaces/views.py +++ b/interfaces/views.py @@ -29,7 +29,8 @@ def interfaces(request, compute_id): netdevs = ["eth0", "eth1"] for iface in ifaces: - ifaces_all.append(conn.get_iface_info(iface)) + interf = wvmInterface(compute.hostname, compute.login, compute.password, compute.type, iface) + ifaces_all.append(interf.get_details()) if request.method == "POST": if "create" in request.POST: diff --git a/vrtManager/connection.py b/vrtManager/connection.py index 0272353..3f49667 100644 --- a/vrtManager/connection.py +++ b/vrtManager/connection.py @@ -482,7 +482,7 @@ class wvmConnect(object): def get_networks(self): """ - :return: list of networks + :return: list of host networks """ virtnet = [] for net in self.wvm.listNetworks(): @@ -493,7 +493,7 @@ class wvmConnect(object): def get_ifaces(self): """ - :return: list of network interfaces + :return: list of host interfaces """ interface = [] for inface in self.wvm.listInterfaces(): diff --git a/vrtManager/interface.py b/vrtManager/interface.py index b6e7c56..d422623 100644 --- a/vrtManager/interface.py +++ b/vrtManager/interface.py @@ -6,13 +6,6 @@ from vrtManager.connection import wvmConnect class wvmInterfaces(wvmConnect): - def get_iface_info(self, name): - iface = self.get_iface(name) - xml = iface.XMLDesc(0) - mac = iface.MACString() - itype = util.get_xml_path(xml, "/interface/@type") - state = iface.isActive() - return {"name": name, "type": itype, "state": state, "mac": mac} def define_iface(self, xml, flag=0): self.wvm.interfaceDefineXML(xml, flag) @@ -153,6 +146,12 @@ class wvmInterface(wvmConnect): else: return None + def get_details(self): + mac = self.get_mac() + itype = self.get_type() + state = self.is_active() + return {"name": self.iface, "type": itype, "state": state, "mac": mac} + def stop_iface(self): self.iface.destroy()