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 Hugh

Hugh Brock wrote:
> Hi. I had a look at the patch. The idea is OK, but there are two
> problems: first, I'd rather you not use exceptions for flow control;
> when you're testing for the mac address, if there's a problem, go
> straight to the user check rather than going through the whole try:
> except: sequence.

Thank you for youre reviewing.
I rewrite a patch.

>                   Second problem is when I try it with a pre-existing
> mac address from the command line for an inactive, I no longer get a
> warning of a duplicate (which you set up in your last patch).

I assume User run various domains with specified time.
For this case, I just show warning messages only.
Since user intent to run the same mac address
with various domain in various time.

Thanks
Tatsuro Enokura
diff -r 8ac3199c83d1 virt-install
--- a/virt-install	Fri Mar 23 10:10:03 2007 -0400
+++ b/virt-install	Tue Mar 27 11:11:14 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,66 @@ 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:])
+            dupFlg = False
+            if n.countMACaddr(vms) > 0:
+                dupFlg = True
+            if dupFlg is not False:
+                for (dummy, dummy, dummy, dummy, host_macaddr) in hostdevs:
+                    if mac.upper() == host_macaddr.upper():
+                        dupFlg = True
+            if dupFlg is True:
+                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 +287,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 +583,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