FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora/Linux Management Tools

 
 
LinkBack Thread Tools
 
Old 08-05-2008, 12:15 PM
 
Default Resend of multiple nic patch

# HG changeset patch
# User bkearney@localhost.localdomain
# Date 1217876425 14400
# Node ID 3507f83147d566fb690dc9b87c0dbb35cd9e6f4c
# 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 3507f83147d5 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 3507f83147d5 tests/image.py
--- a/tests/image.py Tue Jul 29 11:21:07 2008 -0400
+++ b/tests/image.py Mon Aug 04 15:00:25 2008 -0400
@@ -31,7 +31,16 @@
self.assertTrue(img.domain)
self.assertEqual(5, len(img.storage))
self.assertEqual(2, len(img.domain.boots))
+ self.assertEqual(1, img.domain.interface)
boot = img.domain.boots[0]
self.assertEqual("xvdb", boot.drives[1].target)
+
+ def testMultipleNics(self):
+ file = open(os.path.join("tests", "image2nics.xml"), "r")
+ xml = file.read()
+ file.close()
+
+ img = virtinst.ImageParser.parse(xml, ".")
+ self.assertEqual(2, img.domain.interface)
if __name__ == "__main__":
unittest.main()
diff -r 6a207373b908 -r 3507f83147d5 tests/image.xml
--- a/tests/image.xml Tue Jul 29 11:21:07 2008 -0400
+++ b/tests/image.xml Mon Aug 04 15:00:25 2008 -0400
@@ -28,10 +28,12 @@
<drive disk="data.raw" target="hdb"/>
<drive disk="scratch.raw" target="hdd"/>
</boot>
- <vcpu>7</vcpu>
- <memory>262144</memory>
- <interface/>
- <graphics/>
+ <devices>
+ <vcpu>7</vcpu>
+ <memory>262144</memory>
+ <interface/>
+ <graphics/>
+ </devices>
</domain>
<storage>
<disk file="disk.img"/>
diff -r 6a207373b908 -r 3507f83147d5 tests/image2nics.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/image2nics.xml Mon Aug 04 15:00:25 2008 -0400
@@ -0,0 +1,49 @@
+<image>
+ <name>test-image</name>
+ <label>A simple test image</label>
+ <domain>
+ <boot type='xen'>
+ <guest>
+ <os_type>xen</os_type>
+ <arch>i386</arch>
+ <features><pae/></features>
+ </guest>
+ <os>
+ <loader>pygrub</loader>
+ </os>
+ <drive disk="root.raw" target="xvda"/>
+ <drive disk="data.raw" target="xvdb"/>
+ <drive disk="scratch.raw" target="xvdc"/>
+ </boot>
+ <boot type="hvm">
+ <guest>
+ <arch>i686</arch>
+ <features><pae/></features>
+ </guest>
+ <os>
+ <type>hvm</type>
+ <loader dev="hd"/>
+ </os>
+ <drive disk="root.raw" target="hda"/>
+ <drive disk="data.raw" target="hdb"/>
+ <drive disk="scratch.raw" target="hdd"/>
+ </boot>
+ <devices>
+ <vcpu>7</vcpu>
+ <memory>262144</memory>
+ <interface/>
+ <interface/>
+ <graphics/>
+ </devices>
+ </domain>
+ <storage>
+ <disk file="disk.img"/>
+ <disk size="4096" use="system">
+ <partition file="boot.img"/>
+ <partition file="root.img"/>
+ </disk>
+ <disk file="root.raw" format="raw" size="4096" use="system"/>
+ <disk file="data.raw" format="raw" size='2048' use="data"/>
+ <disk file="scratch.raw" format="raw" size='100' use='scratch'/>
+ </storage>
+</image>
diff -r 6a207373b908 -r 3507f83147d5 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,14 @@
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
+ nnics = domain.interface
+ (macs, networks) = cli.digest_networks(macs, bridges, networks, nnics)

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 3507f83147d5 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 = int(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 3507f83147d5 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 3507f83147d5 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@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 08-05-2008, 06:28 PM
David Lutterkort
 
Default Resend of multiple nic patch

On Tue, 2008-08-05 at 08:15 -0400, bkearney@redhat.com wrote:
> # HG changeset patch
> # User bkearney@localhost.localdomain
> # Date 1217876425 14400
> # Node ID 3507f83147d566fb690dc9b87c0dbb35cd9e6f4c
> # 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.

Looks good. Two small nits:

> diff -r 6a207373b908 -r 3507f83147d5 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,14 @@
> 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
> + nnics = domain.interface
> + (macs, networks) = cli.digest_networks(macs, bridges, networks, nnics)
>
> if nnics == 0 and len(networks) > 0:
> print >> sys.stderr, _("Warning: image does not support networking, ignoring network related options")
> return

This check should be 'if len(networks) > nnics' and then warn that the
last len(networks) - nnics network specs will be ignored.

> diff -r 6a207373b908 -r 3507f83147d5 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 = []

It would be clearer to write these two as

if macs is None:
macs = []
elif type(macs) != list
macs = [ macs ]

same for networks

David

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 08-05-2008, 08:25 PM
Bryan Kearney
 
Default Resend of multiple nic patch

David Lutterkort wrote:

On Tue, 2008-08-05 at 08:15 -0400, bkearney@redhat.com wrote:

# HG changeset patch
# User bkearney@localhost.localdomain
# Date 1217876425 14400
# Node ID 3507f83147d566fb690dc9b87c0dbb35cd9e6f4c
# 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.


Looks good. Two small nits:


diff -r 6a207373b908 -r 3507f83147d5 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,14 @@
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
+ nnics = domain.interface
+ (macs, networks) = cli.digest_networks(macs, bridges, networks, nnics)

if nnics == 0 and len(networks) > 0:

print >> sys.stderr, _("Warning: image does not support networking, ignoring network related options")
return


This check should be 'if len(networks) > nnics' and then warn that the
last len(networks) - nnics network specs will be ignored.


Currently.. if you pass in more networks then nics then all are are
used. Would you like me to lop off the last couple of networks?



-- bk

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 08-05-2008, 09:19 PM
David Lutterkort
 
Default Resend of multiple nic patch

On Tue, 2008-08-05 at 16:25 -0400, Bryan Kearney wrote:
> > This check should be 'if len(networks) > nnics' and then warn that the
> > last len(networks) - nnics network specs will be ignored.
>
> Currently.. if you pass in more networks then nics then all are are
> used. Would you like me to lop off the last couple of networks?

Yeah, it's more logical if only the first nnics networks are considered;
that will also retain the way virt-image works right now if the image
does not need a network interface.

David


_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 

Thread Tools




All times are GMT. The time now is 06:51 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org