mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
perf(interfaces): list only the host's network devices
The interfaces page read the XML of every node device (183 on a test host) to keep the network ones; libvirt now lists only those. Same names on both test hosts, 756 -> 261 ms over TCP and 475 -> 173 ms over SSH.
This commit is contained in:
parent
f1e83455e4
commit
4ea002f5a3
2 changed files with 23 additions and 14 deletions
|
|
@ -959,19 +959,11 @@ class wvmConnect(object):
|
|||
return instance
|
||||
|
||||
def get_net_devices(self):
|
||||
netdevice = []
|
||||
|
||||
def get_info(doc):
|
||||
dev_type = util.get_xpath(doc, "/device/capability/@type")
|
||||
interface = util.get_xpath(doc, "/device/capability/interface")
|
||||
return dev_type, interface
|
||||
|
||||
for dev in self.wvm.listAllDevices(0):
|
||||
xml = dev.XMLDesc(0)
|
||||
(dev_type, interface) = util.get_xml_path(xml, func=get_info)
|
||||
if dev_type == "net":
|
||||
netdevice.append(interface)
|
||||
return netdevice
|
||||
"""The host's network interface names; libvirt lists only the network devices"""
|
||||
return [
|
||||
util.get_xml_path(dev.XMLDesc(0), "/device/capability/interface")
|
||||
for dev in self.wvm.listAllDevices(libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET)
|
||||
]
|
||||
|
||||
def get_host_instances(self, raw_mem_size=False):
|
||||
vname = {}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
"""A wvmConnect reads the host's info and capabilities once, and its domain
|
||||
capabilities once per emulator, arch, machine and domain type: the create
|
||||
page's getters parse the capabilities some 60 times, the overview reads the
|
||||
info four times. An object lives for one request."""
|
||||
info four times. An object lives for one request. The interfaces page lists
|
||||
only the host's network devices, not all of them."""
|
||||
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if not settings.configured:
|
||||
settings.configure(MAC_OUI="52:54:10")
|
||||
|
||||
from libvirt import VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET
|
||||
from vrtManager.connection import wvmConnect
|
||||
from vrtManager.hostdetails import wvmHostDetails
|
||||
|
||||
|
|
@ -97,3 +100,17 @@ class CapabilitiesOnceTestCase(unittest.TestCase):
|
|||
conn.wvm = FakeConn()
|
||||
conn.get_cap_xml()
|
||||
self.assertEqual(conn.wvm.reads, ["capabilities"])
|
||||
|
||||
|
||||
class NetDevicesTestCase(unittest.TestCase):
|
||||
def test_only_the_network_devices_are_listed_and_read(self):
|
||||
conn = connection()
|
||||
devices = {
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET: [
|
||||
MagicMock(**{"XMLDesc.return_value": f"<device><capability type='net'><interface>{name}</interface>"
|
||||
"<capability type='80203'/></capability></device>"})
|
||||
for name in ("eth0", "br0")
|
||||
]
|
||||
}
|
||||
conn.wvm.listAllDevices = lambda flags: devices.get(flags, [])
|
||||
self.assertEqual(conn.get_net_devices(), ["eth0", "br0"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue