[et-mgmt-tools] [PATCH] Check the making domain's mac address(part 2)

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

 



Hi,

I made the patch the running domain's mac address check(changeset 125),
I make the patch in this time that the virt-install comand adds the
confirming message.

The attached patch the following way:

  1) Count that the making domian's MAC address is already use
     the exists domain's MAC address.
  2) Check the hots's  NIC MAC address.
  2) if count > 0 or , print confirmation message.
  3) if type yes then leave disk source as it is,
     else ask disk source again.

Signed-off-by: Tatsuro Enokura <fj7716hz@xxxxxxxxxxxxxxxxx>

Thanks,
Tatsuro Enokura

--------------------------------------------------------------------------
diff -r 73d38353c139 virt-install
--- a/virt-install      Fri Mar 16 14:32:06 2007 -0400
+++ b/virt-install      Mon Mar 19 16:23:03 2007 +0900
@@ -170,13 +170,64 @@ def get_disks(disk, size, sparse, guest,
     else:
         get_disk(disk, size, sparse, guest, hvm, conn)

-def get_network(mac, bridge, guest):
+def get_network(mac, bridge, gues, conn):
     if mac == "RANDOM":
         mac = None
     n = virtinst.VirtualNetworkInterface(mac, bridge)
+    if mac is not None:
+        # get all Domains
+        ids = conn.listDomainsID();
+        vms = []
+        for id in ids:
+            if id == 0:
+                continue
+            vm = conn.lookupByID(id)
+            vms.append(vm)
+        # get defined domain
+        names = conn.listDefinedDomains()
+        for name in names:
+            vm = conn.lookupByName(name)
+            vms.append(vm)
+        # get the Host's NIC MACaddress
+        hostdevs = virtinst.util.get_host_network_devices()
+
+        while 1:
+            if mac is None:
+                msg = "What is the MAC address of your virtual machine?"
+                mac = prompt_for_input(msg, mac)
+                n = virtinst.VirtualNetworkInterface(mac, bridge)
+
+            try:
+                if n.countMACaddr(vms) > 0:
+                    raise ValueError
+                for (dummy, dummy, dummy, dummy, host_macaddr) in hostdevs:
+                    if mac.upper() == host_macaddr.upper():
+                        raise ValueError
+            except ValueError:
+                while 1:
+                    retryFlg = False
+                    warnmsg  = "The MAC address you entered already in
use by another guest. "
+                    warnmsg += "The MAC address should be unique in the
system. \n"
+                    res = prompt_for_input(warnmsg + "  Do you really
want to use the MAC address (yes or no)? ")
+                    try:
+                        if yes_or_no(res) is True:
+                            break
+                        else:
+                            retryFlg = True
+                            break
+                    except ValueError, e:
+                        print "ERROR: ", e
+                        continue
+                if retryFlg is True:
+                    mac = None
+                    continue
+                else:
+                    break
+            except:
+                raise
     guest.nics.append(n)

-def get_networks(macs, bridges, guest):
+def get_networks(macs, bridges, guest, conn):
     # ensure we have equal length lists
     if (type(macs) == type(bridges) == list):
         if len(macs) != len(bridges):
@@ -188,9 +239,9 @@ def get_networks(macs, bridges, guest):
         macs = [ None ] * len(bridges)

     if (type(macs) == list):
-        map(lambda m, b: get_network(m, b, guest), macs, bridges)
-    else:
-        get_network(macs, bridges, guest)
+        map(lambda m, b: get_network(m, b, guest, conn), macs, bridges)
+    else:
+        get_network(macs, bridges, guest, conn)

 def get_graphics(vnc, vncport, nographics, sdl, keymap, guest):
     if vnc and nographics:
@@ -481,7 +532,7 @@ def main():
               guest, hvm, conn)

     # set up network information
-    get_networks(options.mac, options.bridge, guest)
+    get_networks(options.mac, options.bridge, guest, conn)

     # set up graphics information
     get_graphics(options.vnc, options.vncport, options.nographics,
options.sdl, options.keymap, guest)
--------------------------------------------------------------------------


[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