diff --git a/imgs/force_off.png b/imgs/force_off.png new file mode 100644 index 0000000..d04ab46 Binary files /dev/null and b/imgs/force_off.png differ diff --git a/lang/en/LC_MESSAGES/en.mo b/lang/en/LC_MESSAGES/en.mo index f1e572f..b3a3cf3 100644 Binary files a/lang/en/LC_MESSAGES/en.mo and b/lang/en/LC_MESSAGES/en.mo differ diff --git a/lang/en/LC_MESSAGES/en.po b/lang/en/LC_MESSAGES/en.po index f798db8..662f394 100644 --- a/lang/en/LC_MESSAGES/en.po +++ b/lang/en/LC_MESSAGES/en.po @@ -200,6 +200,11 @@ msgstr "shut down" msgid "power_on" msgstr "power on" +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:253 +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:272 +msgid "force_off" +msgstr "force off" + #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:244 #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:271 msgid "current_vm_status" @@ -230,6 +235,10 @@ msgstr "" msgid "confirm_vm_status_change" msgstr "Please, confirm virtual machine status change to" +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:293 +msgid "confirm_vm_force_off" +msgstr "Please, confirm you want to forcibly power off the virtual machine" + #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:277 #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:446 #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:630 @@ -249,9 +258,18 @@ msgid "shutting_down_vm" msgstr "Shutting down machine..." #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:289 +msgid "vm_not_powered_up" +msgstr "VM is powered off" + +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:347 msgid "powering_up_vm" msgstr "Powering up machine..." +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:305 +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:355 +msgid "force_off_vm" +msgstr "Forcing off machine..." + #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:359 msgid "unexpected_request_error" msgstr "An unexpected error was received when trying to request a console" @@ -322,6 +340,9 @@ msgstr "Connect to the virtual machine" msgid "viewer_already_opened" msgstr "Viewer for this machine is open now" +msgid "force_off_tooltip" +msgstr "Force off the virtual machine" + #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:647 msgid "total_machines" msgstr "Number of machines" diff --git a/lang/es/LC_MESSAGES/es.mo b/lang/es/LC_MESSAGES/es.mo index 6141222..72b3a53 100644 Binary files a/lang/es/LC_MESSAGES/es.mo and b/lang/es/LC_MESSAGES/es.mo differ diff --git a/lang/es/LC_MESSAGES/es.po b/lang/es/LC_MESSAGES/es.po index db65ad1..4fa8541 100644 --- a/lang/es/LC_MESSAGES/es.po +++ b/lang/es/LC_MESSAGES/es.po @@ -201,6 +201,11 @@ msgstr "apagar" msgid "power_on" msgstr "encender" +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:253 +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:272 +msgid "force_off" +msgstr "forzar fuera" + #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:244 #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:271 msgid "current_vm_status" @@ -231,6 +236,10 @@ msgstr "" msgid "confirm_vm_status_change" msgstr "Por favor, confirme el cambio del estado de la máquina virtual a" +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:293 +msgid "confirm_vm_force_off" +msgstr "Por favor, confirme que desea apagar por la fuerza la máquina virtual" + #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:277 #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:446 #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:630 @@ -250,9 +259,18 @@ msgid "shutting_down_vm" msgstr "Apagando máquina..." #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:289 +msgid "vm_not_powered_up" +msgstr "Máquina está apagado" + +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:347 msgid "powering_up_vm" msgstr "Encendiendo máquina..." +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:305 +#: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:355 +msgid "force_off_vm" +msgstr "Forzando la máquina ..." + #: /home/nico/ovirt_client/ovirt_client/ovirtclient.py:359 msgid "unexpected_request_error" msgstr "Error inesperado al realizar una petición de consola a oVirt" diff --git a/ovirtclient.py b/ovirtclient.py index 131c1b1..ef8f726 100755 --- a/ovirtclient.py +++ b/ovirtclient.py @@ -249,6 +249,8 @@ def toggle_vm_action(self, vmstatus): vmaction = _('shut_down') if vmstatus == 'down': vmaction = _('power_on') + if vmstatus == 'powering_down': + vmaction = _('force_off') return vmaction def toggle_action_text(self, vmstatus): @@ -266,9 +268,43 @@ def toggle_action_text(self, vmstatus): rettxt += ' %s %s' % (_('click_to_action'), _('shut_down')) if vmstatus == 'down': rettxt += ' %s %s' % (_('click_to_action'), _('power_on')) - + if vmstatus == 'powering_down': + rettxt += ' %s %s' % (_('click_to_action'), _('force_off')) return rettxt + def force_off_vm(self, rowid): + """ + Description: If the user clicks on the force off button, we force the vm to power off. + This method shows a confirmation dialog and if accepted, it will be notified to oVirt. + Arguments: The row id that has been clicked. This relationship is stored using the VmData class. + Returns: Nothing + """ + + global conf + + self.lastclick = int(time()) # Last click timestamp update + + curvmstatus = self.vmdata[rowid].vmstatus + if curvmstatus == 'down': + QMessageBox.warning(None, _('apptitle') + ': ' + _('warning'), _('vm_not_powered_up')) + return + + reply = QMessageBox.question(None, _('apptitle') + ': ' + _('confirm'), _('confirm_vm_force_off'), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) + if reply == QMessageBox.Yes: + try: + vms_service = conf.OVIRTCONN.vms_service() + vm = vms_service.list(search='id=%s' % (self.vmdata[rowid].vmid))[0] + except Error: + QMessageBox.critical(None, _('apptitle') + ': ' + _('error'), _('unexpected_connection_drop')) + quit() + + try: + vm_service = vms_service.vm_service(id=self.vmdata[rowid].vmid) + vm_service.stop() + QMessageBox.information(None, _('apptitle') + ': ' + _('success'), _('force_off_vm')) + except Error: + QMessageBox.warning(None, _('apptitle') + ': ' + _('warning'), _('vm_in_unchangeable_status')) + def change_status(self, rowid): """ Description: If the user clicks on the column which determines VM's status, we'll allow them @@ -283,7 +319,7 @@ def change_status(self, rowid): self.lastclick = int(time()) # Last click timestamp update curvmstatus = self.vmdata[rowid].vmstatus - if curvmstatus != 'up' and curvmstatus != 'down': + if curvmstatus != 'up' and curvmstatus != 'down' and curvmstatus != 'powering_down': QMessageBox.warning(None, _('apptitle') + ': ' + _('warning'), _('vm_in_unchangeable_status')) return @@ -311,6 +347,13 @@ def change_status(self, rowid): QMessageBox.information(None, _('apptitle') + ': ' + _('success'), _('powering_up_vm')) except Error: QMessageBox.warning(None, _('apptitle') + ': ' + _('warning'), _('vm_in_unchangeable_status')) + if curvmstatus == 'powering_down': + try: + vm_service = vms_service.vm_service(id=self.vmdata[rowid].vmid) + vm_service.stop() + QMessageBox.information(None, _('apptitle') + ': ' + _('success'), _('force_off_vm')) + except Error: + QMessageBox.warning(None, _('apptitle') + ': ' + _('warning'), _('vm_in_unchangeable_status')) def get_viewer_ticket(self, vmid): """ @@ -593,11 +636,16 @@ def list_vms(self, row, delta, step, vms): imageSticon = self.make_button(vmstatus, self.toggle_action_text(vmstatus)) imageSticon.mousePressEvent = lambda x, r=row: self.change_status(r) + # Force off button. + imageOficon = self.make_button('force_off', _('force_off_tooltip')) + imageOficon.mousePressEvent = lambda x, r=row: self.force_off_vm(r) + # Fill row with known info self.grid.addWidget(imageOsicon, row, 0) self.grid.addWidget(gridvmname, row, 1) self.grid.addWidget(imageSticon, row, 2) self.grid.addWidget(connect, row, 3) + self.grid.addWidget(imageOficon, row, 4) # Store the correspondence between row number <-> VM data vmd = VmData()