Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to force off a misbehaving vm. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added imgs/force_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lang/en/LC_MESSAGES/en.mo
Binary file not shown.
21 changes: 21 additions & 0 deletions lang/en/LC_MESSAGES/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Binary file modified lang/es/LC_MESSAGES/es.mo
Binary file not shown.
18 changes: 18 additions & 0 deletions lang/es/LC_MESSAGES/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
52 changes: 50 additions & 2 deletions ovirtclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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()
Expand Down