Re: [PATCH] KVM-Test: Add private bridge to use for communication

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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" <lmr@xxxxxxxxxx> 写道:

> 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 = private
> >        private_bridge_name = private(default)
> >        private_bridge_addr = 192.168.0.1(default)
> >        private_bridge_mask = 255.255.255.0(default)
> >        pre_command = scripts/private_bridge_setup.py
> 
> 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...
> 
> > Signed-off-by: sshang <sshang@xxxxxxxxxx>
> > ---
> >  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
> > 
> > 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 =
> os.path.dirname(sys.modules[__name__].__file__)
> > +        kvm_test_dir = os.path.abspath(os.path.join(script_dir,
> ".."))
> > +        self.private_bridge_name = os.environ.get(\
> > +                         
> 'KVM_TEST_private_bridge_name','private')
> > +        self.private_bridge_addr = os.environ.get(\
> > +                         
> 'KVM_TEST_private_bridge_addr','192.168.0.1')
> > +        self.private_bridge_mask = os.environ.get(\
> > +                         
> 'KVM_TEST_private_bridge_mask','255.255.255.0')
> > +        self.dhcp_boot = os.environ.get(\
> > +                          'KVM_TEST_dhcp_boot','/pxelinux.0')
> > +        self.tftp_root = os.environ.get('KVM_TEST_tftp')
> > +        if self.tftp_root:
> > +            self.tftp_root = os.path.join(kvm_test_dir,
> self.tftp_root)
> > +        self.qemu_ifup_file = os.path.join(script_dir,
> "qemu-ifup-private")
> > +
> > +
> > +    def setup_private_bridge(self):
> > +        """
> > +        Setup private bridge.
> > +        """
> > +
> > +        text = """#!/bin/sh
> > +switch=%s
> > +/sbin/ifconfig $1 0.0.0.0 up
> > +/usr/sbin/brctl addif ${switch} $1
> > +"""
> > +        text = text % (self.private_bridge_name)
> > +        f = open(self.qemu_ifup_file,"w")
> > +        f.write(text)
> > +        f.close()
> > +        commands.getoutput('chmod a+x %s' % self.qemu_ifup_file)
> > +
> > +        check_br_cmd = "brctl show | grep %s" %
> self.private_bridge_name
> > +        s,o = commands.getstatusoutput(check_br_cmd)
> > +        if s:
> > +            add_br_cmd = "brctl addbr %s" %
> self.private_bridge_name
> > +            s,o = commands.getstatusoutput(add_br_cmd)
> > +            if s:
> > +                raise SetupError('Add bridge error: %s' % o)
> > +        else:
> > +            ifdown_cmd = "ifconfig %s down" %
> self.private_bridge_name
> > +            s,o = commands.getstatusoutput(ifdown_cmd)
> > +            if s:
> > +                raise SetupError('Down bridge error: %s' % o)
> > +
> > +        ifconfig_cmd = "ifconfig %s %s netmask %s up" % \
> > +                 
> (self.private_bridge_name,self.private_bridge_addr,\
> > +                      self.private_bridge_mask)
> > +        s,o = commands.getstatusoutput(ifconfig_cmd)
> > +        if s:
> > +            raise SetupError('Config bridge error: %s' % o)
> > +
> > +        commands.getoutput("pkill dnsmasq")
> > +
> > +        addr_list = self.private_bridge_addr.split('.')
> > +        addr_list[3] = str(int(addr_list[3]) + 1)
> > +        dhcp_addr_begin = '.'.join(addr_list)
> > +        addr_list[3] = '254'
> > +        dhcp_addr_end = '.'.join(addr_list)
> > +
> > +        dnsmasq_argument = " -u root --listen-address %s
> --dhcp-range %s,%s" %\
> > +                   
> (self.private_bridge_addr,dhcp_addr_begin,dhcp_addr_end)
> > +        if self.tftp_root:
> > +            dnsmasq_argument += " --dhcp-boot %s --enable-tftp
> --tftp-root %s"\
> > +                           % (self.dhcp_boot,self.tftp_root)
> > +        dnsmasq_cmd = "dnsmasq" + dnsmasq_argument
> > +        s,o = commands.getstatusoutput(dnsmasq_cmd)
> > +        if s:
> > +            raise SetupError("Running dnsmasq fail %s" % o)
> > +        print "Private bridge dnsmasq setup finished successfuly"
> > +
> > +if __name__ == "__main__":
> > +    setup = SetupPrivateBridge()
> > +    setup.setup_private_bridge()
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux