[PATCH] virt-install: allow to set nic model

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

 



Hi,
attached patch allows to set the nic model when running virt-install
via:

 --network=network:default,model=virtio

The argument parsing in get_network_opts is a bit overkill at the moment
but this way we can add mac=... more easily later.
Cheers,
 -- Guido
# HG changeset patch
# User Guido Günther <agx@xxxxxxxxxxx>
# Date 1241776224 -7200
# Node ID 6b611a388de5c02745f8f686d1d873c5c35e2583
# Parent  2450a9dcaa03514d16daf73a05b58cd5020994cb
Allow to specify nic model with --network

diff -r 2450a9dcaa03 -r 6b611a388de5 man/en/virt-install.pod.in
--- a/man/en/virt-install.pod.in	Thu May 07 17:09:09 2009 -0400
+++ b/man/en/virt-install.pod.in	Fri May 08 11:50:24 2009 +0200
@@ -388,7 +388,7 @@
 
 =over 2
 
-=item -w NETWORK, --network=NETWORK
+=item -w NETWORK, --network=NETWORK,opt1=val1,opt2=val2
 
 Connect the guest to the host network. The value for C<NETWORK> can take
 one of 3 formats:
@@ -424,6 +424,17 @@
 called C<default> will be used. This option can be specified multiple
 times to setup more than one NIC.
 
+Available options are:
+
+=over 4
+
+=item model
+
+Network device model as seen by the guest. Value can be any nic model supported
+by the hypervisor, e.g.: 'e1000', 'rtl8139' or 'virtio'.
+
+=back
+
 =item -b BRIDGE, --bridge=BRIDGE
 
 Bridge device to connect the guest NIC to. This parameter is deprecated in
diff -r 2450a9dcaa03 -r 6b611a388de5 tests/clitest.py
--- a/tests/clitest.py	Thu May 07 17:09:09 2009 -0400
+++ b/tests/clitest.py	Fri May 08 11:50:24 2009 +0200
@@ -172,6 +172,23 @@
       "invalid": [],
      }, # category "misc"
 
+     "network": {
+      "network_args": "--pxe --nographics --noautoconsole --nodisks",
+
+      "valid": [
+        # user networking
+        "--network=user",
+        # with NIC model
+        "--network=user,model=e1000",
+        # several networks
+        "--network=network:default,model=e1000 --network=user,model=virtio",
+      ],
+      "invalid": [
+        "--network=FOO",
+      ],
+
+     }, # category "network"
+
 
     "prompt" : [ " --connect test:///default --debug --prompt" ]
   },
diff -r 2450a9dcaa03 -r 6b611a388de5 virt-image
--- a/virt-image	Thu May 07 17:09:09 2009 -0400
+++ b/virt-image	Fri May 08 11:50:24 2009 +0200
@@ -57,8 +57,8 @@
 
 def get_networks(domain, macs, bridges, networks, guest):
     nnics = domain.interface
-    (macs, networks) = cli.digest_networks(guest.conn, macs, bridges,
-                                           networks, nnics)
+    (macs, networks, models) = cli.digest_networks(guest.conn, macs, bridges,
+                                                   networks, nnics)
 
     if len(networks) > nnics:
         print >> sys.stderr, (_("Warning: more networks were provided [%i] then nics required [%i]. All extras are ignored") % (len(networks),  nnics))
diff -r 2450a9dcaa03 -r 6b611a388de5 virt-install
--- a/virt-install	Thu May 07 17:09:09 2009 -0400
+++ b/virt-install	Fri May 08 11:50:24 2009 +0200
@@ -254,9 +254,9 @@
         if networks:
             fail(_("Cannot use --network with --nonetworks"))
         return
-    (macs, networks) = cli.digest_networks(guest.conn, macs, bridges,
-                                           networks, nics=1)
-    map(lambda m, n: cli.get_network(m, n, guest), macs, networks)
+    (macs, networks, models) = cli.digest_networks(guest.conn, macs, bridges,
+                                                   networks, nics=1)
+    map(lambda m, n, o: cli.get_network(m, n, guest, o), macs, networks, models)
 
 def prompt_virt(caps, arch, req_virt_type, req_accel):
 
diff -r 2450a9dcaa03 -r 6b611a388de5 virtinst/cli.py
--- a/virtinst/cli.py	Thu May 07 17:09:09 2009 -0400
+++ b/virtinst/cli.py	Fri May 08 11:50:24 2009 +0200
@@ -388,21 +388,46 @@
         guest.cpuset = cpustr
     return
 
-def get_network(mac, network, guest):
+def get_network(mac, network, guest, model=None):
     if mac == "RANDOM":
         mac = None
     if network == "user":
-        n = VirtualNetworkInterface(mac, type="user", conn=guest.conn)
+        n = VirtualNetworkInterface(mac, type="user", 
+                                    conn=guest.conn, model=model)
     elif network[0:6] == "bridge":
         n = VirtualNetworkInterface(mac, type="bridge", bridge=network[7:],
-                                    conn=guest.conn)
+                                    conn=guest.conn, model=model)
     elif network[0:7] == "network":
         n = VirtualNetworkInterface(mac, type="network", network=network[8:],
-                                    conn=guest.conn)
+                                    conn=guest.conn, model=model)
     else:
         fail(_("Unknown network type ") + network)
     guest.nics.append(n)
 
+def parse_network_opts(networks):
+    nets = []
+    models = []
+
+    for network in networks:
+        opts = { 'model': None }
+        args = network.split(",")
+        nets.append(args[0])
+
+        for opt in args[1:]:
+            opt_type = None
+            opt_val = None
+            if opt.count("="):
+                opt_type, opt_val = opt.split("=", 1)
+                opts[opt_type.lower()] = opt_val.lower()
+
+        for opt_type in opts:
+            if opt_type == "model":
+                models.append(opts[opt_type])
+            else:
+                fail(_("Unknown '%s' value '%s'") % (opt_type, opt_val))
+
+    return (nets, models)
+
 def digest_networks(conn, macs, bridges, networks, nics = 0):
     def listify(l):
         if l is None:
@@ -422,6 +447,8 @@
     if bridges:
         networks = map(lambda b: "bridge:" + b, bridges)
 
+    (networks, models) = parse_network_opts(networks)
+
     # With just one mac, create a default network if one is not
     # specified.
     if len(macs) == 1 and len(networks) == 0:
@@ -450,7 +477,7 @@
                 networks.append("user")
             macs.append(None)
 
-    return (macs, networks)
+    return (macs, networks, models)
 
 def get_graphics(vnc, vncport, vnclisten, nographics, sdl, keymap, guest):
     if (vnc and nographics) or \
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux