[Kimchi-devel] [PATCH 1/3] Generate libvirt's interface XML definition for vlanned bridge

Sheldon shaohef at linux.vnet.ibm.com
Fri Jan 3 05:28:43 UTC 2014


On 01/03/2014 09:40 AM, Mark Wu wrote:
> On 01/03/2014 06:25 AM, Christy Perez wrote:
>>
>> On Thu, 2014-01-02 at 17:50 +0800, Mark Wu wrote:
>>> To support vlanned virtual network, kimchi needs create the underlying
>>> vlan and bridge interface. Libvirt's interface driver can do it with
>>> a given XML definition. This patch targets to generate the XML 
>>> according
>>> to the interface and vlan id.
>>>
>>> Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
>>> ---
>>> src/kimchi/networkxml.py | 17 +++++++++++++++++
>>> tests/test_networkxml.py | 20 ++++++++++++++++++++
>>> tests/utils.py | 6 ++++++
>>> 3 files changed, 43 insertions(+)
>>>
>>> diff --git a/src/kimchi/networkxml.py b/src/kimchi/networkxml.py
>>> index 786cb69..25157fd 100644
>>> --- a/src/kimchi/networkxml.py
>>> +++ b/src/kimchi/networkxml.py
>>> @@ -21,6 +21,8 @@
>>> # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
>>> 02110-1301 USA
>>>
>>> import ipaddr
>>> +import lxml.etree as ET
>>> +from lxml.builder import E
>>>
>>>
>>> # FIXME, do not support ipv6
>>> @@ -109,3 +111,18 @@ def to_network_xml(**kwargs):
>>> </network>
>>> """ % params
>>> return xml
>>> +
>>> +
>>> +def create_vlanned_bridge_xml(bridge, interface, vlan_id):
>>> + vlan = E.vlan(E.interface(name=interface))
>>> + vlan.set('tag', vlan_id)
>>> + m = E.interface(
>>> + E.start(mode='onboot'),
>>> + E.bridge(
>>> + E.interface(
>>> + vlan,
>>> + type='vlan',
>>> + name='.'.join([interface, vlan_id]))),
>>> + type='bridge',
>>> + name=bridge)
>>> + return ET.tostring(m)
>> Could you add a check to make sure the interface passed in exists before
>> adding a vlan bridge?
> The validation is done in _set_network_bridge:
> def _set_network_bridge(self, params):
> ...
> elif netinfo.is_bare_nic(iface) or netinfo.is_bonding(iface): ----> 
> this validation can guarantee the interface exists
> if params.get('vlan_id') is None:
> params['forward']['dev'] = iface
> else:
> params['bridge'] = \
> self._create_vlanned_bridge(str(iface),
> str(params['vlan_id']))
>
>
yes. the verify is in model.
this file is just create xml.

>>
>> And what if you call the routine, create_vlan_tagged_bridge_xml()? There
>> are untagged vlans, and the word 'vlanned' just sounds funny to me.
> ACK. I will update it in v2 patch. Thanks for the review.
>>> diff --git a/tests/test_networkxml.py b/tests/test_networkxml.py
>>> index 3073bce..1b2e77f 100644
>>> --- a/tests/test_networkxml.py
>>> +++ b/tests/test_networkxml.py
>>> @@ -26,6 +26,7 @@ import unittest
>>>
>>> import kimchi.networkxml as nxml
>>> from kimchi.xmlutils import xpath_get_text
>>> +import utils
>>>
>>>
>>> class NetworkXmlTests(unittest.TestCase):
>>> @@ -151,3 +152,22 @@ class NetworkXmlTests(unittest.TestCase):
>>> netmask = xpath_get_text(xml, "/network/ip/@netmask")[0]
>>> self.assertEquals(netmask,
>>> str(ipaddr.IPNetwork(params["net"]).netmask))
>>> +
>>> +
>>> +class InterfaceXmlTests(unittest.TestCase):
>>> +
>>> + def test_vlanned_bridge_no_ip(self):
>>> + expected_xml = """
>>> + <interface type='bridge' name='br10'>
>>> + <start mode='onboot'/>
>>> + <bridge>
>>> + <interface type='vlan' name='em1.10'>
>>> + <vlan tag='10'>
>>> + <interface name='em1'/>
>>> + </vlan>
>>> + </interface>
>>> + </bridge>
>>> + </interface>
>>> + """
>>> + actual_xml = nxml.create_vlanned_bridge_xml('br10', 'em1', '10')
>>> + self.assertEquals(actual_xml, utils.normalize_xml(expected_xml))
>>> diff --git a/tests/utils.py b/tests/utils.py
>>> index 008f668..79fc2e2 100644
>>> --- a/tests/utils.py
>>> +++ b/tests/utils.py
>>> @@ -32,6 +32,7 @@ import unittest
>>>
>>>
>>> from contextlib import closing
>>> +from lxml import etree
>>>
>>>
>>> import kimchi.server
>>> @@ -159,3 +160,8 @@ def patch_auth():
>>>
>>> import kimchi.auth
>>> kimchi.auth.authenticate = _authenticate
>>> +
>>> +
>>> +def normalize_xml(xml_str):
>>> + return etree.tostring(etree.fromstring(xml_str,
>>> + etree.XMLParser(remove_blank_text=True)))
>>
>> _______________________________________________
>> Kimchi-devel mailing list
>> Kimchi-devel at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>
>
>


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list