[et-mgmt-tools] [PATCH] Add the option to guard maximums of the number of virtual CPU by the number of physical CPU

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

 



Hi

In virt-install, the maximum of the number of virtual CPU are not guarded
by the number of physical CPU. 
As a result , the domain slows down when the user set many virtual CPUs
by mistake. 

Therefore, I contribute the patch that adds the option to guard maximums
of the number of virtual CPU by the number of physical CPU. 


Signed-off-by: Masayuki Sunou <fj1826dm@xxxxxxxxxxxxxxxxx>

Thanks,
Masayuki Sunou

================================================================================
diff -r ecc4386895aa virt-install
--- a/virt-install	Thu Mar 15 12:09:51 2007 -0400
+++ b/virt-install	Fri Mar 16 14:23:30 2007 +0900
@@ -89,12 +89,24 @@ def get_uuid(uuid, guest):
         except ValueError, e:
             print "ERROR: ", e
 
-def get_vcpus(vcpus, guest):
-    if vcpus: 
-        try:
-            guest.vcpus = vcpus
-        except ValueError, e:
-            print "ERROR: ", e
+def get_vcpus(vcpus, check_cpu, guest, conn):
+    while 1:
+        vcpus = int(prompt_for_input("How many VCPUs should be attached?",vcpus))
+        if check_cpu is not None:
+            hostinfo = conn.getInfo()
+            cpu_num = hostinfo[4] * hostinfo[5] * hostinfo[6] * hostinfo[7]
+            if vcpus > cpu_num:
+                print "ERROR: Set less or equal the number of physical CPU (%d)." %(cpu_num)
+                print ""
+                vcpus = None
+                continue
+        if vcpus:
+            try:
+                guest.vcpus = vcpus
+            except ValueError, e:
+                print "ERROR: ", e
+        break
+
 
 def get_keymap(keymap, guest):
     if keymap:
@@ -250,6 +262,8 @@ def parse_args():
                       help="UUID for the guest; if none is given a random UUID will be generated")
     parser.add_option("", "--vcpus", type="int", dest="vcpus",
                       help="Number of vcpus to configure for your guest")
+    parser.add_option("", "--check-cpu", action="store_true", dest="check_cpu",
+                      help="the maximum of physical CPU.")
 
     # disk options
     parser.add_option("-f", "--file", type="string",
@@ -456,7 +470,7 @@ def main():
     get_name(options.name, guest)
     get_memory(options.memory, guest)
     get_uuid(options.uuid, guest)
-    get_vcpus(options.vcpus, guest)
+    get_vcpus(options.vcpus, options.check_cpu, guest, conn)
     get_keymap(options.keymap, guest)
 
     # set up disks
================================================================================


[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