Multiple nic patch with DLutterkort's comments applied
# HG changeset patch
# User bkearney@localhost.localdomain
# Date 1217876425 14400
# Node ID d9910a83bbf6a7aa85ebcc14f949071c9e9c5eb6
# 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.
# FIXME: There must be a better way to check this
diff -r 6a207373b908 -r d9910a83bbf6 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 d9910a83bbf6 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:
+ if macs is None:
+ macs = []
+ elif type(macs) != list:
macs = [ macs ]
-
- if type(networks) != list and networks != None:
- networks = [ networks ]
+
+ if networks is None:
+ networks = []
+ elif type(networks) != list:
+ networks = [ macs ]
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)
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
08-05-2008, 09:28 PM
David Lutterkort
Multiple nic patch with DLutterkort's comments applied
On Tue, 2008-08-05 at 16:39 -0400, bkearney@redhat.com wrote:
> diff -r 6a207373b908 -r d9910a83bbf6 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:
> + if macs is None:
> + macs = []
> + elif type(macs) != list:
> macs = [ macs ]
> -
> - if type(networks) != list and networks != None:
> - networks = [ networks ]
> +
> + if networks is None:
> + networks = []
> + elif type(networks) != list:
> + networks = [ macs ]
>
> 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)
I didn't notice this the first time through: it used to be that you
could just specify the network/bridge to connect to, without giving an
explicit MAC (so that you use a random MAC)
We definitely want to keep that ability. I think the above should be
changed so that the behavior is (1) you need to specify nnics networks
and/or bridges (2) you may specify up to nnics explicit MACS, with the
meaning that successive -w and -b options talk about successive
interfaces, and explicit MACS are assigned to them in sequence. For
interfaces that don't have an explicit MAC assigned, we'll generate a
random MAC.
For example,
virt-image -b br0 -w default -m 00:16:..
would connect the first interface to the bridge 'br0' on the host, and
the second interface to the 'default' network. The first interface would
get the explicit MAC assigned, whereas the second one would get some
random MAC.
David
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
08-06-2008, 12:08 PM
Bryan Kearney
Multiple nic patch with DLutterkort's comments applied
David Lutterkort wrote:
On Tue, 2008-08-05 at 16:39 -0400, bkearney@redhat.com wrote:
+def digest_networks(macs, bridges, networks, nics = 1):
if type(bridges) != list and bridges != None:
bridges = [ bridges ]
- if type(macs) != list and macs != None:
+ if macs is None:
+ macs = []
+ elif type(macs) != list:
macs = [ macs ]
-
- if type(networks) != list and networks != None:
- networks = [ networks ]
+
+ if networks is None:
+ networks = []
+ elif type(networks) != list:
+ networks = [ macs ]
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)
I didn't notice this the first time through: it used to be that you
could just specify the network/bridge to connect to, without giving an
explicit MAC (so that you use a random MAC)
We definitely want to keep that ability. I think the above should be
changed so that the behavior is (1) you need to specify nnics networks
and/or bridges (2) you may specify up to nnics explicit MACS, with the
meaning that successive -w and -b options talk about successive
interfaces, and explicit MACS are assigned to them in sequence. For
interfaces that don't have an explicit MAC assigned, we'll generate a
random MAC.
For example,
virt-image -b br0 -w default -m 00:16:..
would connect the first interface to the bridge 'br0' on the host, and
the second interface to the 'default' network. The first interface would
get the explicit MAC assigned, whereas the second one would get some
random MAC.
I will rework and submit. I will error out if you pass more MAC
addresses then networks or bridges.
-- bk
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools