network: Parse <portgroup> XML

This commit is contained in:
Cole Robinson 2014-05-31 14:20:56 -04:00
parent 519e3b5768
commit 1c608f3ba8
5 changed files with 69 additions and 1 deletions

View File

@ -1115,10 +1115,28 @@ ba</description>
<network>
<name>plainbridge</name>
<name>plainbridge-portgroups</name>
<uuid>b1b9d7c6-f620-048f-71ee-ca3ba1ac3e98</uuid>
<forward mode='bridge'/>
<bridge name='br2' />
<portgroup name='engineering' default='yes'>
<virtualport type='802.1Qbh'>
<parameters profileid='test'/>
</virtualport>
<bandwidth>
<inbound average='1000' peak='5000' burst='5120'/>
<outbound average='1000' peak='5000' burst='5120'/>
</bandwidth>
</portgroup>
<portgroup name='sales'>
<virtualport type='802.1Qbh'>
<parameters profileid='salestest'/>
</virtualport>
<bandwidth>
<inbound average='500' peak='2000' burst='2560'/>
<outbound average='128' peak='256' burst='256'/>
</bandwidth>
</portgroup>
</network>

View File

@ -22,4 +22,22 @@
</ip>
<ip family="ipv4" address="192.168.19.0" netmask="255.255.255.0">
</ip>
<portgroup name='engineering' default='yes'>
<virtualport type='802.1Qbh'>
<parameters profileid='test'/>
</virtualport>
<bandwidth>
<inbound average='1000' peak='5000' burst='5120'/>
<outbound average='1000' peak='5000' burst='5120'/>
</bandwidth>
</portgroup>
<portgroup name='sales'>
<virtualport type='802.1Qbh'>
<parameters profileid='salestest'/>
</virtualport>
<bandwidth>
<inbound average='500' peak='2000' burst='2560'/>
<outbound average='128' peak='256' burst='256'/>
</bandwidth>
</portgroup>
</network>

View File

@ -24,6 +24,24 @@
</ip>
<ip family="ipv4" address="192.168.19.0" netmask="255.255.255.0">
</ip>
<portgroup name="foo" default="no">
<virtualport type="802.1Qbh">
<parameters profileid="test"/>
</virtualport>
<bandwidth>
<inbound average="1000" peak="5000" burst="5120"/>
<outbound average="1000" peak="5000" burst="5120"/>
</bandwidth>
</portgroup>
<portgroup name="sales">
<virtualport type="802.1Qbh">
<parameters profileid="salestest"/>
</virtualport>
<bandwidth>
<inbound average="500" peak="2000" burst="2560"/>
<outbound average="128" peak="256" burst="256"/>
</bandwidth>
</portgroup>
<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

@ -1135,6 +1135,11 @@ class XMLParseTest(unittest.TestCase):
check("mode", "nat", "route")
check("dev", None, "eth22")
self.assertEquals(len(net.portgroups), 2)
check = self._make_checker(net.portgroups[0])
check("name", "engineering", "foo")
check("default", True, False)
self.assertEqual(len(net.ips), 4)
check = self._make_checker(net.ips[0])
check("address", "192.168.7.1", "192.168.8.1")

View File

@ -82,6 +82,13 @@ class _NetworkForward(XMLBuilder):
return Network.pretty_forward_desc(self.mode, self.dev)
class _NetworkPortgroup(XMLBuilder):
_XML_ROOT_NAME = "portgroup"
name = XMLProperty("./@name")
default = XMLProperty("./@default", is_yesno=True)
class Network(XMLBuilder):
"""
Top level class for <network> object XML
@ -172,6 +179,7 @@ class Network(XMLBuilder):
delay = XMLProperty("./bridge/@delay", is_int=True)
macaddr = XMLProperty("./mac/@address")
portgroups = XMLChildProperty(_NetworkPortgroup)
ips = XMLChildProperty(_NetworkIP)
routes = XMLChildProperty(_NetworkRoute)
@ -184,6 +192,7 @@ class Network(XMLBuilder):
self._add_child(route)
return route
##################
# build routines #
##################