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

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

 



Hi

Would you give me a comment on this patch?
If not, please apply it.

Tatsuro Enokura wrote:
> 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 8ac3199c83d1 virt-install
--- a/virt-install	Fri Mar 23 10:10:03 2007 -0400
+++ b/virt-install	Mon Mar 26 15:20:28 2007 +0900
@@ -181,7 +181,7 @@ def get_disks(disk, size, sparse, guest,
     else:
         get_disk(disk, size, sparse, guest, hvm, conn)
 
-def get_network(mac, network, guest):
+def get_network(mac, network, guest, conn):
     if mac == "RANDOM":
         mac = None
     if network == "user":
@@ -193,9 +193,65 @@ def get_network(mac, network, guest):
     else:
         print >> sys.stderr, "Unknown network type " + network
         sys.exit(1)
+
+    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)
+                if network == "user":
+                    n = virtinst.VirtualNetworkInterface(mac, type="user")
+                elif network[0:6] == "bridge":
+                    n = virtinst.VirtualNetworkInterface(mac, type="bridge", bridge=network[7:])
+                elif network[0:7] == "network":
+                    n = virtinst.VirtualNetworkInterface(mac, type="network", network=network[8:])
+            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, networks, guest):
+def get_networks(macs, bridges, networks, guest, conn):
     if type(bridges) != list and bridges != None:
         bridges = [ bridges ]
 
@@ -230,7 +286,7 @@ def get_networks(macs, bridges, networks
         else:
             macs = [ None ]
 
-    map(lambda m, n: get_network(m, n, guest), macs, networks)
+    map(lambda m, n: get_network(m, n, guest, conn), macs, networks)
 
 def get_graphics(vnc, vncport, nographics, sdl, keymap, guest):
     if vnc and nographics:
@@ -526,7 +582,7 @@ def main():
               guest, hvm, conn)
 
     # set up network information
-    get_networks(options.mac, options.bridge, options.network, guest)
+    get_networks(options.mac, options.bridge, options.network, 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