From: Lucas Meneghel Rodrigues Subject: Re: [PATCH] KVM-Test: Add private bridge to use for communication Date: Thu, 25 Feb 2010 17:08:11 -0300 Message-ID: <1267128491.15621.30.camel@localhost.localdomain> References: <866519442.2675131267064040233.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: autotest@test.kernel.com, kvm@vger.kernel.org To: Shuxi Shang Return-path: Received: from mx1.redhat.com ([209.132.183.28]:30538 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933525Ab0BYUIR (ORCPT ); Thu, 25 Feb 2010 15:08:17 -0500 In-Reply-To: <866519442.2675131267064040233.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, 2010-02-24 at 21:14 -0500, Shuxi Shang wrote: > Hello, Lucas, I think there are two advantages of such a private brid= ge: > 1). With private bridge, not paying attention to the conflict of gues= t's mac address. > 2). segregating from public network which host locates. All right, please re-send it to the mailing list (I can't find your patch on patchwork). Also, we'll spend some time considering your approach, so the patch will stay on the queue for some time. Thanks! >=20 > ----- "Lucas Meneghel Rodrigues" =E5=86=99=E9=81=93=EF= =BC=9A >=20 > > On Tue, 2010-02-23 at 16:56 +0800, sshang wrote: > > > Add private bridge to use for communication between host and gues= t. > > > Config of parameter: > > > bridge =3D private > > > private_bridge_name =3D private(default) > > > private_bridge_addr =3D 192.168.0.1(default) > > > private_bridge_mask =3D 255.255.255.0(default) > > > pre_command =3D scripts/private_bridge_setup.py > >=20 > > Hi, I've checked your patch, seems fair enough. But can you elabora= te > > more on the advantages of having such a private bridge for > > communication > > between hosts and guests? We have mechanisms of doing so in both ta= p > > and > > user mode networking... > >=20 > > > Signed-off-by: sshang > > > --- > > > client/tests/kvm/scripts/private_bridge_setup.py | 90 > > ++++++++++++++++++++++ > > > 1 files changed, 90 insertions(+), 0 deletions(-) > > > create mode 100755 > > client/tests/kvm/scripts/private_bridge_setup.py > > >=20 > > > diff --git a/client/tests/kvm/scripts/private_bridge_setup.py > > b/client/tests/kvm/scripts/private_bridge_setup.py > > > new file mode 100755 > > > index 0000000..fe1b653 > > > --- /dev/null > > > +++ b/client/tests/kvm/scripts/private_bridge_setup.py > > > @@ -0,0 +1,90 @@ > > > +#!/usr/bin/python > > > +import os, sys, commands > > > + > > > +class SetupError(Exception): > > > + """ > > > + Simple wrapper for the builtin Exception class. > > > + """ > > > + pass > > > + > > > + > > > +class SetupPrivateBridge(object): > > > + """ > > > + Setup private bridge and running dnsmasq for communication > > > + between host and guest. > > > + """ > > > + def __init__(self): > > > + script_dir =3D > > os.path.dirname(sys.modules[__name__].__file__) > > > + kvm_test_dir =3D os.path.abspath(os.path.join(script_dir= , > > "..")) > > > + self.private_bridge_name =3D os.environ.get(\ > > > + =20 > > 'KVM_TEST_private_bridge_name','private') > > > + self.private_bridge_addr =3D os.environ.get(\ > > > + =20 > > 'KVM_TEST_private_bridge_addr','192.168.0.1') > > > + self.private_bridge_mask =3D os.environ.get(\ > > > + =20 > > 'KVM_TEST_private_bridge_mask','255.255.255.0') > > > + self.dhcp_boot =3D os.environ.get(\ > > > + 'KVM_TEST_dhcp_boot','/pxelinux.0') > > > + self.tftp_root =3D os.environ.get('KVM_TEST_tftp') > > > + if self.tftp_root: > > > + self.tftp_root =3D os.path.join(kvm_test_dir, > > self.tftp_root) > > > + self.qemu_ifup_file =3D os.path.join(script_dir, > > "qemu-ifup-private") > > > + > > > + > > > + def setup_private_bridge(self): > > > + """ > > > + Setup private bridge. > > > + """ > > > + > > > + text =3D """#!/bin/sh > > > +switch=3D%s > > > +/sbin/ifconfig $1 0.0.0.0 up > > > +/usr/sbin/brctl addif ${switch} $1 > > > +""" > > > + text =3D text % (self.private_bridge_name) > > > + f =3D open(self.qemu_ifup_file,"w") > > > + f.write(text) > > > + f.close() > > > + commands.getoutput('chmod a+x %s' % self.qemu_ifup_file) > > > + > > > + check_br_cmd =3D "brctl show | grep %s" % > > self.private_bridge_name > > > + s,o =3D commands.getstatusoutput(check_br_cmd) > > > + if s: > > > + add_br_cmd =3D "brctl addbr %s" % > > self.private_bridge_name > > > + s,o =3D commands.getstatusoutput(add_br_cmd) > > > + if s: > > > + raise SetupError('Add bridge error: %s' % o) > > > + else: > > > + ifdown_cmd =3D "ifconfig %s down" % > > self.private_bridge_name > > > + s,o =3D commands.getstatusoutput(ifdown_cmd) > > > + if s: > > > + raise SetupError('Down bridge error: %s' % o) > > > + > > > + ifconfig_cmd =3D "ifconfig %s %s netmask %s up" % \ > > > + =20 > > (self.private_bridge_name,self.private_bridge_addr,\ > > > + self.private_bridge_mask) > > > + s,o =3D commands.getstatusoutput(ifconfig_cmd) > > > + if s: > > > + raise SetupError('Config bridge error: %s' % o) > > > + > > > + commands.getoutput("pkill dnsmasq") > > > + > > > + addr_list =3D self.private_bridge_addr.split('.') > > > + addr_list[3] =3D str(int(addr_list[3]) + 1) > > > + dhcp_addr_begin =3D '.'.join(addr_list) > > > + addr_list[3] =3D '254' > > > + dhcp_addr_end =3D '.'.join(addr_list) > > > + > > > + dnsmasq_argument =3D " -u root --listen-address %s > > --dhcp-range %s,%s" %\ > > > + =20 > > (self.private_bridge_addr,dhcp_addr_begin,dhcp_addr_end) > > > + if self.tftp_root: > > > + dnsmasq_argument +=3D " --dhcp-boot %s --enable-tftp > > --tftp-root %s"\ > > > + % (self.dhcp_boot,self.tftp_root) > > > + dnsmasq_cmd =3D "dnsmasq" + dnsmasq_argument > > > + s,o =3D commands.getstatusoutput(dnsmasq_cmd) > > > + if s: > > > + raise SetupError("Running dnsmasq fail %s" % o) > > > + print "Private bridge dnsmasq setup finished successfuly= " > > > + > > > +if __name__ =3D=3D "__main__": > > > + setup =3D SetupPrivateBridge() > > > + setup.setup_private_bridge()