From 47503bf1e16bf070a25f161565a58d84473b43bc Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 19 Feb 2007 23:11:21 -0500 Subject: [PATCH] Added ability to create QEMU/KVM/KQEMU guests in new VM wizard --- src/virt-manager.py.in | 2 +- src/virtManager/create.py | 101 +++++++-- src/vmm-create.glade | 466 +++++++++++++++++++++++--------------- 3 files changed, 369 insertions(+), 200 deletions(-) diff --git a/src/virt-manager.py.in b/src/virt-manager.py.in index a31836b22..b142508a6 100755 --- a/src/virt-manager.py.in +++ b/src/virt-manager.py.in @@ -83,7 +83,7 @@ pylib_dir = "::PYLIBDIR::" pyarchlib_dir = "::PYARCHLIBDIR::" # Hack for dev purposes -if os.path.exists(os.getcwd() + "/src/" + appname + ".glade"): +if os.path.exists(os.getcwd() + "/src/vmm-about.glade"): glade_dir = os.getcwd() + "/src" if os.path.exists(os.getcwd() + "/pixmaps/icon_run.png"): icon_dir = os.getcwd() + "/pixmaps" diff --git a/src/virtManager/create.py b/src/virtManager/create.py index 03cb0fcf5..4c09765f0 100644 --- a/src/virtManager/create.py +++ b/src/virtManager/create.py @@ -122,6 +122,8 @@ class vmmCreate(gobject.GObject): "on_pv_media_url_changed" : self.change_combo_box, "on_pv_ks_url_changed" : self.change_combo_box, "on_os_type_changed" : self.change_os_type, + "on_cpu_architecture_changed": self.change_cpu_arch, + "on_virt_method_toggled": self.change_virt_method, }) self.set_initial_state() @@ -201,6 +203,16 @@ class vmmCreate(gobject.GObject): self.window.get_widget("create-host-memory").set_text(self.pretty_memory(memory)) self.window.get_widget("create-memory-max").set_range(50, memory/1024) + if self.connection.get_type() == "QEMU": + self.window.get_widget("cpu-architecture").set_active(0) + else: + self.window.get_widget("cpu-architecture").set_active(-1) + + self.window.get_widget("cpu-architecture").set_sensitive(False) + self.window.get_widget("cpu-accelerate").set_sensitive(False) + self.change_virt_method() + + def reset_state(self): notebook = self.window.get_widget("create-pages") notebook.set_current_page(0) @@ -212,26 +224,33 @@ class vmmCreate(gobject.GObject): # If we don't have full-virt support disable the choice, and # display a message telling the user why it is not working - if virtinst.util.is_hvm_capable(): - self.window.get_widget("virt-method-fv").set_sensitive(True) + if self.connection.get_type() == "QEMU": + self.window.get_widget("virt-method-pv").set_sensitive(False) + self.window.get_widget("virt-method-fv").set_active(True) self.window.get_widget("virt-method-fv-unsupported").hide() self.window.get_widget("virt-method-fv-disabled").hide() else: - self.window.get_widget("virt-method-fv").set_sensitive(False) - flags = virtinst.util.get_cpu_flags() - if "vmx" in flags or "svm" in flags: - # Host has support, but disabled in bios + self.window.get_widget("virt-method-pv").set_sensitive(True) + self.window.get_widget("virt-method-pv").set_active(True) + if virtinst.util.is_hvm_capable(): + self.window.get_widget("virt-method-fv").set_sensitive(True) self.window.get_widget("virt-method-fv-unsupported").hide() - self.window.get_widget("virt-method-fv-disabled").show() - else: - # Host has no support - self.window.get_widget("virt-method-fv-unsupported").show() self.window.get_widget("virt-method-fv-disabled").hide() + else: + self.window.get_widget("virt-method-fv").set_sensitive(False) + flags = virtinst.util.get_cpu_flags() + if "vmx" in flags or "svm" in flags: + # Host has support, but disabled in bios + self.window.get_widget("virt-method-fv-unsupported").hide() + self.window.get_widget("virt-method-fv-disabled").show() + else: + # Host has no support + self.window.get_widget("virt-method-fv-unsupported").show() + self.window.get_widget("virt-method-fv-disabled").hide() self.change_media_type() self.change_storage_type() self.window.get_widget("create-vm-name").set_text("") - self.window.get_widget("virt-method-pv").set_active(True) self.window.get_widget("media-iso-image").set_active(True) self.window.get_widget("fv-iso-location").set_text("") self.window.get_widget("storage-partition").set_active(True) @@ -405,7 +424,9 @@ class vmmCreate(gobject.GObject): def finish(self, ignore=None): # first things first, are we trying to create a fully virt guest? if self.get_config_method() == VM_FULLY_VIRT: - guest = virtinst.FullVirtGuest() + guest = virtinst.FullVirtGuest(type=self.get_domain_type(), \ + hypervisorURI=self.connection.get_uri(), \ + arch=self.get_domain_arch()) try: guest.cdrom = self.get_config_install_source() except ValueError, e: @@ -422,7 +443,7 @@ class vmmCreate(gobject.GObject): self._validation_error_box(_("Invalid FV OS Variant"),e.args[0]) else: - guest = virtinst.ParaVirtGuest() + guest = virtinst.ParaVirtGuest(type=self.get_domain_type(), hypervisorURI=self.connection.get_uri()) try: guest.location = self.get_config_install_source() except ValueError, e: @@ -486,6 +507,8 @@ class vmmCreate(gobject.GObject): guest.graphics = "vnc" logging.debug("Creating a VM " + guest.name + \ + "\n Type: " + guest.type + \ + "\n Architecture: " + str(guest.arch) + \ "\n UUID: " + guest.uuid + \ "\n Source: " + self.get_config_install_source() + \ "\n OS: " + self.get_config_os_variant() + \ @@ -662,7 +685,7 @@ class vmmCreate(gobject.GObject): self._validation_error_box(_("Invalid System Name"), \ _("System name may contain alphanumeric and '_' characters only")) return False - + elif page_num == 2: # the virt method page if self.get_config_method() == VM_FULLY_VIRT and not virtinst.util.is_hvm_capable(): @@ -795,7 +818,7 @@ class vmmCreate(gobject.GObject): model.clear() for url in urls: model.append([url]) - + def change_combo_box(self, box): model = box.get_model() box.child.set_text(model.get_value(box.get_active_iter(), 0)) @@ -805,7 +828,7 @@ class vmmCreate(gobject.GObject): model.clear() for os in oses: model.append([os]) - + def change_os_type(self, box): model = box.get_model() os_type = model.get_value(box.get_active_iter(), 0) @@ -814,16 +837,56 @@ class vmmCreate(gobject.GObject): self.populate_os_model(variant_model, virtinst.FullVirtGuest.OS_TYPES[os_type].keys()) variant.set_active(0) + def change_virt_method(self, ignore=None): + arch = self.window.get_widget("cpu-architecture") + if self.connection.get_type() != "QEMU" or self.window.get_widget("virt-method-pv").get_active(): + arch.set_sensitive(False) + else: + arch.set_sensitive(True) + self.change_cpu_arch(arch) + + def change_cpu_arch(self, src): + model = src.get_model() + active = src.get_active() + canAccel = False + if active != -1 and src.get_property("sensitive") and \ + (virtinst.util.is_kvm_capable() or virtinst.util.is_kqemu_capable()): + if os.uname()[4] == "i686" and model[active][0] == "i686": + canAccel = True + elif os.uname()[4] == "x86_64" and model[active][0] in ("i686", "x86_64"): + canAccel = True + + self.window.get_widget("cpu-accelerate").set_sensitive(canAccel) + self.window.get_widget("cpu-accelerate").set_active(canAccel) + + def get_domain_arch(self): + if self.connection.get_type() != "QEMU": + return None + arch = self.window.get_widget("cpu-architecture") + if arch.get_active() == -1: + return None + return arch.get_model()[arch.get_active()][0] + def pretty_memory(self, mem): if mem > (1024*1024): return "%2.2f GB" % (mem/(1024.0*1024.0)) else: return "%2.2f MB" % (mem/1024.0) - + def is_sparse_file(self): if self.window.get_widget("non-sparse").get_active(): return False else: return True - - + + def get_domain_type(self): + if self.connection.get_type() == "QEMU": + if self.window.get_widget("cpu-accelerate").get_active(): + if virtinst.util.is_kvm_capable(): + return "kvm" + elif virtinst.util.is_kqemu_capable(): + return "kqemu" + return "qemu" + else: + return "xen" + diff --git a/src/vmm-create.glade b/src/vmm-create.glade index e8ab17747..893c27a7f 100644 --- a/src/vmm-create.glade +++ b/src/vmm-create.glade @@ -852,6 +852,7 @@ True False True + @@ -911,6 +912,7 @@ False True virt-method-pv + @@ -922,22 +924,292 @@ - + True - Involves hardware simulation, allowing for a greater range of operating systems (does not require OS modification). Slower than paravirtualized systems. - False - True - GTK_JUSTIFY_LEFT - True - False - 0 + 0.5 0.5 - 21 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 + 1 + 1 + 0 + 0 + 21 + 0 + + + + True + False + 0 + + + + True + Involves hardware simulation, allowing for a greater range of operating systems (does not require OS modification). Slower than paravirtualized systems. + False + True + GTK_JUSTIFY_LEFT + True + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + False + 0 + + + + True + CPU architecture: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + i686 +x86_64 +ppc +sparc +mips +mipsel + False + True + + + + 0 + False + True + + + + + 0 + True + True + + + + + + True + True + Enable kernel / hardware acceleration + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + False + 0 + + + + True + 0.5 + 0.10000000149 + 1 + 0.10000000149 + 0 + 0 + 5 + 0 + + + + True + gtk-dialog-info + 4 + 0.5 + 0.5 + 0 + 0 + + + + + 0 + False + False + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 3 + 0 + + + + True + <small><b>Note:</b> The host CPU(s) in this machine do not have support for full virtualization.</small> + False + True + GTK_JUSTIFY_LEFT + True + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + + + 0 + False + False + + + + + 0 + True + True + + + + + + True + False + 0 + + + + True + 0.5 + 0.10000000149 + 1 + 0.10000000149 + 0 + 0 + 5 + 0 + + + + True + gtk-dialog-warning + 4 + 0.5 + 0.5 + 0 + 0 + + + + + 0 + False + False + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 3 + 0 + + + + True + <small><b>Note:</b> The host CPU(s) in this machine support full virtualization, but it is not enabled by the BIOS.</small> + False + True + GTK_JUSTIFY_LEFT + True + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + + + 0 + False + False + + + + + 0 + True + True + + + + 0 @@ -945,172 +1217,6 @@ False - - - - True - False - 0 - - - - True - 0.5 - 0.10000000149 - 1 - 0.10000000149 - 0 - 0 - 5 - 0 - - - - True - gtk-dialog-info - 4 - 0.5 - 0.5 - 0 - 0 - - - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 3 - 0 - - - - True - <small><b>Note:</b> The host CPU(s) in this machine do not have support for full virtualization.</small> - False - True - GTK_JUSTIFY_LEFT - True - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - - - 0 - False - False - - - - - 4 - False - False - - - - - - True - False - 0 - - - - True - 0.5 - 0.10000000149 - 1 - 0.10000000149 - 0 - 0 - 5 - 0 - - - - True - gtk-dialog-warning - 4 - 0.5 - 0.5 - 0 - 0 - - - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 3 - 0 - - - - True - <small><b>Note:</b> The host CPU(s) in this machine support full virtualization, but it is not enabled by the BIOS.</small> - False - True - GTK_JUSTIFY_LEFT - True - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - - - 0 - False - False - - - - - 4 - True - True - -