# HG changeset patch # User bkearney@xxxxxxxxxxxxxxxxxxxxx # Date 1217876425 14400 # Node ID b75270d46d5c71e582ca4e850716dace951badb5 # Parent 6a207373b908ab521d33cd675c7c8d3854bdc1f1 multiple nic support for virt-image. Added support to allow multiple interface elements in the virt-image.xml. The command line can specify any number of -w or -b elements and the tool will add default networks up to the number of nics specified. It is assumbed that eth0 is the first item specified. diff -r 6a207373b908 -r b75270d46d5c doc/image.rng --- a/doc/image.rng Tue Jul 29 11:21:07 2008 -0400 +++ b/doc/image.rng Mon Aug 04 15:00:25 2008 -0400 @@ -47,8 +47,10 @@ <element name="vcpu"><ref name="countCPU"/></element> <!-- Size of memory (in kB) --> <element name="memory"><ref name="memoryKB"/></element> - <!-- Whether the VM should have a network interface --> - <element name="interface"><empty/></element> + <!--The number of network interfaces which should exist --> + <zeroOrMore> + <element name="interface"><empty/></element> + </zeroOrMore> <!-- Whether the VM has a graphical interface --> <element name="graphics"><empty/></element> </element> diff -r 6a207373b908 -r b75270d46d5c virt-image --- a/virt-image Tue Jul 29 11:21:07 2008 -0400 +++ b/virt-image Mon Aug 04 15:00:25 2008 -0400 @@ -59,17 +59,13 @@ cli.get_vcpus(vcpus, check_cpu, guest, conn) def get_networks(domain, macs, bridges, networks, guest): - (macs, networks) = cli.digest_networks(macs, bridges, networks) - - nnics = 0 - if domain.interface: - nnics = 1 + (macs, networks) = cli.digest_networks(macs, bridges, networks, domain.interface) if nnics == 0 and len(networks) > 0: print >> sys.stderr, _("Warning: image does not support networking, ignoring network related options") return - elif nnics == 1 and len(networks) == 0: - fail(_("The image needs one network interface")) + elif nnics > len(networks) : + fail(_("The image requires %i network interface") % nnics) map(lambda m, n: cli.get_network(m, n, guest), macs, networks) diff -r 6a207373b908 -r b75270d46d5c virtinst/ImageParser.py --- a/virtinst/ImageParser.py Tue Jul 29 11:21:07 2008 -0400 +++ b/virtinst/ImageParser.py Mon Aug 04 15:00:25 2008 -0400 @@ -90,7 +90,7 @@ self.boots = [] self.vcpu = None self.memory = None - self.interface = None + self.interface = 0 self.graphics = None if not node is None: self.parseXML(node) @@ -99,7 +99,7 @@ self.boots = [ Boot(b) for b in node.xpathEval("boot") ] self.vcpu = xpathString(node, "devices/vcpu", 1) self.memory = xpathString(node, "devices/memory") - self.interface = node.xpathEval("count(devices/interface)") > 0 + self.interface = node.xpathEval("count(devices/interface)") self.graphics = node.xpathEval("count(devices/graphics)") > 0 # FIXME: There must be a better way to check this diff -r 6a207373b908 -r b75270d46d5c virtinst/UnWare.py --- a/virtinst/UnWare.py Tue Jul 29 11:21:07 2008 -0400 +++ b/virtinst/UnWare.py Mon Aug 04 15:00:25 2008 -0400 @@ -143,7 +143,9 @@ self.label = image.label self.vcpu = domain.vcpu self.memory = domain.memory - self.interface = domain.interface + # Make this a boolean based on the existence of one or more + # interfaces in the domain + self.interface = domain.interface > 0 self.disks = [] for d in boot.drives: diff -r 6a207373b908 -r b75270d46d5c virtinst/cli.py --- a/virtinst/cli.py Tue Jul 29 11:21:07 2008 -0400 +++ b/virtinst/cli.py Mon Aug 04 15:00:25 2008 -0400 @@ -262,41 +262,41 @@ fail(_("Unknown network type ") + network) guest.nics.append(n) -def digest_networks(macs, bridges, networks): +def digest_networks(macs, bridges, networks, nics = 1): if type(bridges) != list and bridges != None: bridges = [ bridges ] if type(macs) != list and macs != None: macs = [ macs ] + elif macs is None: + macs = [] if type(networks) != list and networks != None: networks = [ networks ] + elif networks is None: + networks = [] if bridges is not None and networks != None: fail(_("Cannot mix both --bridge and --network arguments")) - # ensure we have equal length lists + if bridges != None: networks = map(lambda b: "bridge:" + b, bridges) - - if networks != None: - if macs != None: - if len(macs) != len(networks): - fail(_("Need to pass equal numbers of networks & mac addresses")) - else: - macs = [ None ] * len(networks) - else: - if os.getuid() == 0: - net = util.default_network() - networks = [net[0] + ":" + net[1]] - else: - networks = ["user"] - if macs != None: - if len(macs) > 1: - fail(_("Need to pass equal numbers of networks & mac addresses")) - else: - macs = [ None ] - + + # ensure we have equal length lists + if len(macs) != len(networks): + fail(_("Need to pass equal numbers of networks & mac addresses")) + + # Create extra networks up to the number of nics requested + if len(macs) < nics: + for cnt in range(len(macs),nics): + if os.getuid() == 0: + net = util.default_network() + networks.append(net[0] + ":" + net[1]) + else: + networks.append("user") + macs.append(None) + return (macs, networks) def get_graphics(vnc, vncport, nographics, sdl, keymap, guest): _______________________________________________ et-mgmt-tools mailing list et-mgmt-tools@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/et-mgmt-tools