virtinst: parse "bandwith" node in network definition

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2014-06-25 12:27:00 +02:00
parent 72d0d5d8ea
commit 57d26e6265
4 changed files with 71 additions and 1 deletions

View File

@ -40,4 +40,8 @@
<outbound average='128' peak='256' burst='256'/>
</bandwidth>
</portgroup>
<bandwidth>
<inbound average="1000" peak="5000" burst="5120"/>
<outbound average="1000" peak="5000" burst="5120"/>
</bandwidth>
</network>

View File

@ -42,6 +42,10 @@
<outbound average="128" peak="256" burst="256"/>
</bandwidth>
</portgroup>
<bandwidth>
<inbound average="3000" peak="4000" burst="5220"/>
<outbound average="2000" peak="3000" burst="5120"/>
</bandwidth>
<mac address="52:54:00:69:eb:FF"/>
<route family="ipv4" address="192.168.8.0" prefix="24" gateway="192.168.8.10"/>
</network>

View File

@ -1143,6 +1143,15 @@ class XMLParseTest(unittest.TestCase):
check("mode", "nat", "route")
check("dev", None, "eth22")
check = self._make_checker(net.bandwidth)
check("inbound_average", "1000", "3000")
check("inbound_peak", "5000", "4000")
check("inbound_burst", "5120", "5220")
check("inbound_floor", None, None)
check("outbound_average", "1000", "2000")
check("outbound_peak", "5000", "3000")
check("outbound_burst", "5120", "5120")
self.assertEquals(len(net.portgroups), 2)
check = self._make_checker(net.portgroups[0])
check("name", "engineering", "foo")

View File

@ -82,6 +82,58 @@ class _NetworkForward(XMLBuilder):
return Network.pretty_forward_desc(self.mode, self.dev)
class _NetworkBandwidth(XMLBuilder):
_XML_ROOT_NAME = "bandwidth"
inbound_average = XMLProperty("./inbound/@average")
inbound_peak = XMLProperty("./inbound/@peak")
inbound_burst = XMLProperty("./inbound/@burst")
inbound_floor = XMLProperty("./inbound/@floor")
outbound_average = XMLProperty("./outbound/@average")
outbound_peak = XMLProperty("./outbound/@peak")
outbound_burst = XMLProperty("./outbound/@burst")
def is_inbound(self):
return bool(self.inbound_average or self.inbound_peak
or self.inbound_burst or self.inbound_floor)
def is_outbound(self):
return bool(self.outbound_average or self.outbound_peak
or self.outbound_burst)
def pretty_desc(self, inbound=True, outbound=True):
items_in = [(self.inbound_average, _("Average"), "KiB/s"),
(self.inbound_peak, _("Peak"), "KiB"),
(self.inbound_burst, _("Burst"), "KiB/s"),
(self.inbound_floor, _("Floor"), "KiB/s")]
items_out = [(self.outbound_average, _("Average"), "KiB/s"),
(self.outbound_peak, _("Peak"), "KiB"),
(self.outbound_burst, _("Burst"), "KiB/s")]
def stringify_items(items):
return ", ".join(["%s: %s %s" % (desc, val, unit)
for val, desc, unit in items if val])
ret = ""
show_name = inbound and outbound
if inbound:
if show_name:
ret += _("Inbound: ")
ret += stringify_items(items_in)
if outbound:
if ret:
ret += "\n"
if show_name:
ret += _("Outbound: ")
ret += stringify_items(items_out)
return ret
class _NetworkPortgroup(XMLBuilder):
_XML_ROOT_NAME = "portgroup"
@ -161,7 +213,7 @@ class Network(XMLBuilder):
_XML_ROOT_NAME = "network"
_XML_PROP_ORDER = ["ipv6", "name", "uuid", "forward",
"bridge", "stp", "delay", "domain_name",
"macaddr", "ips", "routes"]
"macaddr", "ips", "routes", "bandwidth"]
ipv6 = XMLProperty("./@ipv6", is_yesno=True)
name = XMLProperty("./name", validate_cb=_validate_name)
@ -182,6 +234,7 @@ class Network(XMLBuilder):
portgroups = XMLChildProperty(_NetworkPortgroup)
ips = XMLChildProperty(_NetworkIP)
routes = XMLChildProperty(_NetworkRoute)
bandwidth = XMLChildProperty(_NetworkBandwidth, is_single=True)
def add_ip(self):
ip = _NetworkIP(self.conn)