From: Shuxi Shang Subject: Re: [PATCH] KVM-Test: Add private bridge to use for communication Date: Wed, 24 Feb 2010 21:14:00 -0500 (EST) Message-ID: <866519442.2675131267064040233.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> References: <588192575.2675111267064009544.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: Lucas Meneghel Rodrigues Return-path: Received: from mx1.redhat.com ([209.132.183.28]:10280 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755121Ab0BYCOB convert rfc822-to-8bit (ORCPT ); Wed, 24 Feb 2010 21:14:01 -0500 In-Reply-To: <588192575.2675111267064009544.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Hello, Lucas, I think there are two advantages of such a private bridge= : 1). With private bridge, not paying attention to the conflict of guest'= s mac address. 2). segregating from public network which host locates. ----- "Lucas Meneghel Rodrigues" =E5=86=99=E9=81=93=EF= =BC=9A > On Tue, 2010-02-23 at 16:56 +0800, sshang wrote: > > Add private bridge to use for communication between host and guest. > > 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 elaborate > more on the advantages of having such a private bridge for > communication > between hosts and guests? We have mechanisms of doing so in both tap > 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()