diff --git a/src/gnome-virt-manager.py.in b/src/gnome-virt-manager.py.in index ab06d155..10c0ad10 100755 --- a/src/gnome-virt-manager.py.in +++ b/src/gnome-virt-manager.py.in @@ -70,16 +70,17 @@ class vmmAbout: return 1 class vmmConsole: - def __init__(self, config, connection, vmuuid, name): + def __init__(self, config, connection, vm, vmuuid): self.window = gtk.glade.XML(glade_dir + "/" + appname + ".glade", "vmm-console") self.config = config self.connection = connection + self.vm = vm self.vmuuid = vmuuid self.lastStatus = None topwin = self.window.get_widget("vmm-console") topwin.hide() - topwin.set_title(name + " " + topwin.get_title()) + topwin.set_title(vm.name() + " " + topwin.get_title()) self.window.get_widget("control-run").set_icon_widget(gtk.Image()) self.window.get_widget("control-run").get_icon_widget().set_from_file(icon_dir + "/icon_run.png") @@ -109,8 +110,8 @@ class vmmConsole: "on_control_details_clicked": self.control_vm_details, }) - self.connection.connect_to_signal("vm_updated", self.refresh_status) - self.refresh_status(vmuuid) + self.connection.connect_to_signal("vm_updated", self.vm_updated) + self.refresh_status() def show(self): dialog = self.window.get_widget("vmm-console") @@ -125,23 +126,25 @@ class vmmConsole: return 0 def control_vm_shutdown(self, src): - if not(self.connection.get_stats().run_status(self.vmuuid) in [ "shutdown", "shutoff" ]): - self.vmm.shutdown() + info = self.vm.info() + if not(info[0] in [ libvirt.VIR_DOMAIN_SHUTDOWN, libvirt.VIR_DOMAIN_SHUTOFF ]): + self.vm.shutdown() else: print "Shutdown requested, but machine is already shutting down / shutoff" def control_vm_pause(self, src): - if self.connection.get_stats().run_status(self.vmuuid) in [ "shutdown", "shutoff" ]: + info = self.vm.info() + if info[0] in [ libvirt.VIR_DOMAIN_SHUTDOWN, libvirt.VIR_DOMAIN_SHUTOFF, libvirt.VIR_DOMAIN_CRASHED ]: print "Pause/resume requested, but machine is shutdown / shutoff" else: - if self.connection.get_stats().run_status(self.vmuuid) in [ "paused" ]: + if info[0] in [ libvirt.VIR_DOMAIN_PAUSED ]: if not src.get_active(): - self.vmm.resume() + self.vm.resume() else: print "Pause requested, but machine is already paused" else: if src.get_active(): - self.vmm.suspend() + self.vm.suspend() else: print "Resume requested, but machine is already running" @@ -155,21 +158,23 @@ class vmmConsole: def control_vm_details(self, src): self.connection.show_details(self.vmuuid) - def refresh_status(self, vmuuid): - if not(vmuuid == self.vmuuid): - return + def vm_updated(self, uuid): + if uuid == self.vmuuid: + self.refresh_status() - status = self.connection.get_stats().run_status(vmuuid) + def refresh_status(self): + info = self.vm.info() + status = info[0] if self.lastStatus == status: return - if status == "shutoff": + if status == libvirt.VIR_DOMAIN_SHUTOFF: self.window.get_widget("control-run").set_sensitive(True) else: self.window.get_widget("control-run").set_sensitive(False) - if status in [ "shutoff", "shutdown" ]: + if status in [ libvirt.VIR_DOMAIN_SHUTDOWN, libvirt.VIR_DOMAIN_SHUTOFF ]: self.window.get_widget("control-pause").set_sensitive(False) self.window.get_widget("control-shutdown").set_sensitive(False) self.window.get_widget("control-terminal").set_sensitive(False) @@ -179,7 +184,7 @@ class vmmConsole: self.window.get_widget("control-shutdown").set_sensitive(True) self.window.get_widget("control-terminal").set_sensitive(True) self.window.get_widget("control-snapshot").set_sensitive(True) - if status == "paused": + if status == libvirt.VIR_DOMAIN_PAUSED: self.window.get_widget("control-pause").set_active(True) else: self.window.get_widget("control-pause").set_active(False) @@ -188,18 +193,19 @@ class vmmConsole: class vmmDetails: - def __init__(self, config, connection, vmuuid, name): + def __init__(self, config, connection, vm, vmuuid): self.window = gtk.glade.XML(glade_dir + "/" + appname + ".glade", "vmm-details") self.config = config self.connection = connection + self.vm = vm self.vmuuid = vmuuid self.lastStatus = None topwin = self.window.get_widget("vmm-details") topwin.hide() - topwin.set_title(name + " " + topwin.get_title()) + topwin.set_title(vm.name() + " " + topwin.get_title()) - self.window.get_widget("overview-name").set_text(name) + self.window.get_widget("overview-name").set_text(vm.name()) self.window.get_widget("overview-uuid").set_text(vmuuid) self.window.get_widget("control-run").set_icon_widget(gtk.Image()) @@ -311,7 +317,7 @@ class vmmDetails: def control_vm_shutdown(self, src): if not(self.connection.get_stats().run_status(self.vmuuid) in [ "shutdown", "shutoff" ]): - self.vmm.shutdown() + self.vm.shutdown() else: print "Shutdown requested, but machine is already shutting down / shutoff" @@ -321,12 +327,12 @@ class vmmDetails: else: if self.connection.get_stats().run_status(self.vmuuid) in [ "paused" ]: if not src.get_active(): - self.vmm.resume() + self.vm.resume() else: print "Pause requested, but machine is already paused" else: if src.get_active(): - self.vmm.suspend() + self.vm.suspend() else: print "Resume requested, but machine is already running" @@ -1228,13 +1234,13 @@ class vmmConnection: def show_details(self, vmuuid): if not(self.windowDetails.has_key(vmuuid)): - self.windowDetails[vmuuid] = vmmDetails(self.config, self, vmuuid, self.vms[vmuuid].name()) + self.windowDetails[vmuuid] = vmmDetails(self.config, self, self.vms[vmuuid], vmuuid) self.windowDetails[vmuuid].show() def show_console(self, vmuuid): if not(self.windowConsole.has_key(vmuuid)): - self.windowConsole[vmuuid] = vmmConsole(self.config, self, vmuuid, self.vms[vmuuid].name()) + self.windowConsole[vmuuid] = vmmConsole(self.config, self, self.vms[vmuuid], vmuuid) self.windowConsole[vmuuid].show()