2017-12-20 22:33:39 +01:00
|
|
|
#!/usr/bin/python3
|
2014-03-31 01:17:27 +02:00
|
|
|
# -*- coding: utf8 -*-
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
2017-12-20 22:33:39 +01:00
|
|
|
# Copyright (C) 2014 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
2014-03-31 01:17:27 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
2017-11-06 21:06:30 +01:00
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
2018-05-20 21:30:50 +02:00
|
|
|
import datetime
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
from PyQt4 import QtGui # pylint: disable=import-error
|
|
|
|
from PyQt4 import QtCore # pylint: disable=import-error
|
|
|
|
# pylint: disable=too-few-public-methods
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-06-11 02:46:31 +02:00
|
|
|
from qubesadmin import exc
|
2018-05-31 00:04:46 +02:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
power_order = QtCore.Qt.DescendingOrder
|
|
|
|
update_order = QtCore.Qt.AscendingOrder
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
row_height = 30
|
|
|
|
|
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
class VmIconWidget(QtGui.QWidget):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, icon_path, enabled=True, size_multiplier=0.7,
|
2017-12-20 22:33:39 +01:00
|
|
|
tooltip=None, parent=None, icon_sz=(32, 32)):
|
2014-03-31 01:17:27 +02:00
|
|
|
super(VmIconWidget, self).__init__(parent)
|
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
self.label_icon = QtGui.QLabel()
|
2014-07-10 16:50:29 +02:00
|
|
|
if icon_path[0] in ':/':
|
2017-12-20 22:33:39 +01:00
|
|
|
icon = QtGui.QIcon(icon_path)
|
2014-07-10 16:50:29 +02:00
|
|
|
else:
|
2017-12-20 22:33:39 +01:00
|
|
|
icon = QtGui.QIcon.fromTheme(icon_path)
|
|
|
|
icon_sz = QtCore.QSize(row_height * size_multiplier,
|
|
|
|
row_height * size_multiplier)
|
|
|
|
icon_pixmap = icon.pixmap(
|
|
|
|
icon_sz,
|
|
|
|
QtGui.QIcon.Disabled if not enabled else QtGui.QIcon.Normal)
|
|
|
|
self.label_icon.setPixmap(icon_pixmap)
|
|
|
|
self.label_icon.setFixedSize(icon_sz)
|
|
|
|
if tooltip is not None:
|
2014-03-31 01:17:27 +02:00
|
|
|
self.label_icon.setToolTip(tooltip)
|
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
layout = QtGui.QHBoxLayout()
|
2014-03-31 01:17:27 +02:00
|
|
|
layout.addWidget(self.label_icon)
|
2017-12-20 22:33:39 +01:00
|
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.setLayout(layout)
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
def setToolTip(self, tooltip): # pylint: disable=invalid-name
|
2014-03-31 01:17:27 +02:00
|
|
|
if tooltip is not None:
|
|
|
|
self.label_icon.setToolTip(tooltip)
|
|
|
|
else:
|
|
|
|
self.label_icon.setToolTip('')
|
|
|
|
|
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
class VmTypeWidget(VmIconWidget):
|
|
|
|
class VmTypeItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, value, vm):
|
|
|
|
super(VmTypeWidget.VmTypeItem, self).__init__()
|
|
|
|
self.value = value
|
|
|
|
self.vm = vm
|
|
|
|
|
|
|
|
def set_value(self, value):
|
|
|
|
self.value = value
|
|
|
|
|
2018-06-11 01:56:10 +02:00
|
|
|
#pylint: disable=too-many-return-statements
|
2014-03-31 01:17:27 +02:00
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
elif self.value == other.value:
|
|
|
|
return self.vm.name < other.vm.name
|
|
|
|
return self.value < other.value
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def __init__(self, vm, parent=None):
|
|
|
|
(icon_path, tooltip) = self.get_vm_icon(vm)
|
2017-12-20 22:33:39 +01:00
|
|
|
super(VmTypeWidget, self).__init__(
|
|
|
|
icon_path, True, 0.8, tooltip, parent)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.vm = vm
|
2018-01-08 03:06:42 +01:00
|
|
|
self.table_item = self.VmTypeItem(self.value, vm)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.value = None
|
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# TODO: add "provides network" column
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def get_vm_icon(self, vm):
|
2017-12-20 22:33:39 +01:00
|
|
|
if vm.klass == 'AdminVM':
|
2014-03-31 01:17:27 +02:00
|
|
|
self.value = 0
|
2017-12-20 22:33:39 +01:00
|
|
|
icon_name = "dom0"
|
|
|
|
elif vm.klass == 'TemplateVM':
|
2014-03-31 01:17:27 +02:00
|
|
|
self.value = 3
|
2017-12-20 22:33:39 +01:00
|
|
|
icon_name = "templatevm"
|
|
|
|
elif vm.klass == 'StandaloneVM':
|
|
|
|
self.value = 4
|
|
|
|
icon_name = "standalonevm"
|
|
|
|
else:
|
2014-03-31 01:17:27 +02:00
|
|
|
self.value = 5 + vm.label.index
|
2017-12-20 22:33:39 +01:00
|
|
|
icon_name = "appvm"
|
|
|
|
|
|
|
|
return ":/" + icon_name + ".png", vm.klass
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
class VmLabelWidget(VmIconWidget):
|
2017-12-20 22:33:39 +01:00
|
|
|
class VmLabelItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, value, vm):
|
|
|
|
super(VmLabelWidget.VmLabelItem, self).__init__()
|
|
|
|
self.value = value
|
|
|
|
self.vm = vm
|
|
|
|
|
|
|
|
def set_value(self, value):
|
|
|
|
self.value = value
|
|
|
|
|
2018-06-11 01:56:10 +02:00
|
|
|
#pylint: disable=too-many-return-statements
|
2014-03-31 01:17:27 +02:00
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
elif self.value == other.value:
|
|
|
|
return self.vm.name < other.vm.name
|
|
|
|
return self.value < other.value
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def __init__(self, vm, parent=None):
|
|
|
|
icon_path = self.get_vm_icon_path(vm)
|
2017-12-20 22:33:39 +01:00
|
|
|
super(VmLabelWidget, self).__init__(icon_path, True, 0.8, None, parent)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.vm = vm
|
2018-01-08 03:06:42 +01:00
|
|
|
self.table_item = self.VmLabelItem(self.value, vm)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.value = None
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def get_vm_icon_path(self, vm):
|
2017-12-20 22:33:39 +01:00
|
|
|
self.value = vm.label.index
|
|
|
|
return vm.label.icon
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
class VmNameItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
super(VmNameItem, self).__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.setText(vm.name)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setTextAlignment(QtCore.Qt.AlignVCenter)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.qid = vm.qid
|
|
|
|
|
2018-06-11 01:56:10 +02:00
|
|
|
#pylint: disable=too-many-return-statements
|
2015-03-09 21:51:40 +01:00
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.qid == 0:
|
|
|
|
return False
|
|
|
|
return super(VmNameItem, self).__lt__(other)
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
|
|
|
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
class VmStatusIcon(QtGui.QLabel):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm, parent=None):
|
2017-12-20 22:33:39 +01:00
|
|
|
super(VmStatusIcon, self).__init__(parent)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.vm = vm
|
|
|
|
self.set_on_icon()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.previous_power_state = self.vm.get_power_state()
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def update(self):
|
2017-12-20 22:33:39 +01:00
|
|
|
if self.previous_power_state != self.vm.get_power_state():
|
2014-03-31 01:17:27 +02:00
|
|
|
self.set_on_icon()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.previous_power_state = self.vm.get_power_state()
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def set_on_icon(self):
|
2017-12-20 22:33:39 +01:00
|
|
|
if self.vm.get_power_state() == "Running":
|
|
|
|
icon = QtGui.QIcon(":/on.png")
|
|
|
|
elif self.vm.get_power_state() in ["Paused", "Suspended"]:
|
|
|
|
icon = QtGui.QIcon(":/paused.png")
|
|
|
|
elif self.vm.get_power_state() in ["Transient", "Halting", "Dying"]:
|
|
|
|
icon = QtGui.QIcon(":/transient.png")
|
2014-03-31 01:17:27 +02:00
|
|
|
else:
|
2017-12-20 22:33:39 +01:00
|
|
|
icon = QtGui.QIcon(":/off.png")
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
icon_sz = QtCore.QSize(row_height * 0.5, row_height * 0.5)
|
2014-03-31 01:17:27 +02:00
|
|
|
icon_pixmap = icon.pixmap(icon_sz)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setPixmap(icon_pixmap)
|
|
|
|
self.setFixedSize(icon_sz)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
class VmInfoWidget(QtGui.QWidget):
|
|
|
|
class VmInfoItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, upd_info_item, vm):
|
|
|
|
super(VmInfoWidget.VmInfoItem, self).__init__()
|
|
|
|
self.upd_info_item = upd_info_item
|
|
|
|
self.vm = vm
|
|
|
|
|
|
|
|
def __lt__(self, other):
|
2018-01-08 03:06:42 +01:00
|
|
|
# pylint: disable=too-many-return-statements
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
|
|
|
|
2014-03-31 01:17:27 +02:00
|
|
|
self_val = self.upd_info_item.value
|
|
|
|
other_val = other.upd_info_item.value
|
2018-01-05 17:31:15 +01:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
if self.tableWidget().\
|
|
|
|
horizontalHeader().sortIndicatorOrder() == update_order:
|
2014-03-31 01:17:27 +02:00
|
|
|
# the result will be sorted by upd, sorting order: Ascending
|
|
|
|
self_val += 1 if self.vm.is_running() else 0
|
|
|
|
other_val += 1 if other.vm.is_running() else 0
|
|
|
|
if self_val == other_val:
|
2018-01-05 17:31:15 +01:00
|
|
|
return self.vm.name < other.vm.name
|
2018-01-08 03:06:42 +01:00
|
|
|
return self_val > other_val
|
2017-12-20 22:33:39 +01:00
|
|
|
elif self.tableWidget().\
|
|
|
|
horizontalHeader().sortIndicatorOrder() == power_order:
|
|
|
|
# the result will be sorted by power state,
|
|
|
|
# sorting order: Descending
|
|
|
|
self_val = -(self_val/10 +
|
|
|
|
10*(1 if self.vm.is_running() else 0))
|
|
|
|
other_val = -(other_val/10 +
|
|
|
|
10*(1 if other.vm.is_running() else 0))
|
2014-03-31 01:17:27 +02:00
|
|
|
if self_val == other_val:
|
2018-01-05 17:31:15 +01:00
|
|
|
return self.vm.name < other.vm.name
|
2018-01-08 03:06:42 +01:00
|
|
|
return self_val > other_val
|
2014-03-31 01:17:27 +02:00
|
|
|
else:
|
2017-12-20 22:33:39 +01:00
|
|
|
# it would be strange if this happened
|
2014-03-31 01:17:27 +02:00
|
|
|
return
|
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
def __init__(self, vm, parent=None):
|
|
|
|
super(VmInfoWidget, self).__init__(parent)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.vm = vm
|
2017-12-20 22:33:39 +01:00
|
|
|
layout = QtGui.QHBoxLayout()
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
self.on_icon = VmStatusIcon(vm)
|
|
|
|
self.upd_info = VmUpdateInfoWidget(vm, show_text=False)
|
|
|
|
self.error_icon = VmIconWidget(":/warning.png")
|
|
|
|
self.blk_icon = VmIconWidget(":/mount.png")
|
|
|
|
self.rec_icon = VmIconWidget(":/mic.png")
|
|
|
|
|
|
|
|
layout.addWidget(self.on_icon)
|
|
|
|
layout.addWidget(self.upd_info)
|
|
|
|
layout.addWidget(self.error_icon)
|
2017-12-20 22:33:39 +01:00
|
|
|
layout.addItem(QtGui.QSpacerItem(0, 10,
|
|
|
|
QtGui.QSizePolicy.Expanding,
|
|
|
|
QtGui.QSizePolicy.Expanding))
|
2014-03-31 01:17:27 +02:00
|
|
|
layout.addWidget(self.blk_icon)
|
|
|
|
layout.addWidget(self.rec_icon)
|
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
layout.setContentsMargins(5, 0, 5, 0)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
self.rec_icon.setVisible(False)
|
|
|
|
self.blk_icon.setVisible(False)
|
|
|
|
self.error_icon.setVisible(False)
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
self.table_item = self.VmInfoItem(self.upd_info.table_item, vm)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-05-20 21:30:50 +02:00
|
|
|
def update_vm_state(self):
|
2014-03-31 01:17:27 +02:00
|
|
|
self.on_icon.update()
|
2018-05-07 13:17:43 +02:00
|
|
|
self.upd_info.update_outdated()
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
class VmTemplateItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
super(VmTemplateItem, self).__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.vm = vm
|
2018-05-07 13:17:43 +02:00
|
|
|
self.setTextAlignment(QtCore.Qt.AlignVCenter)
|
|
|
|
self.update()
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-05-07 13:17:43 +02:00
|
|
|
def update(self):
|
|
|
|
if getattr(self.vm, 'template', None) is not None:
|
|
|
|
self.setText(self.vm.template.name)
|
2014-03-31 01:17:27 +02:00
|
|
|
else:
|
2017-12-20 22:33:39 +01:00
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setStyle(QtGui.QFont.StyleItalic)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.setFont(font)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setTextColor(QtGui.QColor("gray"))
|
|
|
|
|
2018-05-07 13:17:43 +02:00
|
|
|
self.setText(self.vm.klass)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
elif self.text() == other.text():
|
|
|
|
return self.vm.name < other.vm.name
|
|
|
|
return super(VmTemplateItem, self).__lt__(other)
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
class VmNetvmItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
super(VmNetvmItem, self).__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.vm = vm
|
2018-05-07 13:17:43 +02:00
|
|
|
self.setTextAlignment(QtCore.Qt.AlignVCenter)
|
|
|
|
self.update()
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-05-07 13:17:43 +02:00
|
|
|
def update(self):
|
|
|
|
if getattr(self.vm, 'netvm', None) is None:
|
2014-03-31 01:17:27 +02:00
|
|
|
self.setText("n/a")
|
|
|
|
else:
|
2018-05-07 13:17:43 +02:00
|
|
|
self.setText(self.vm.netvm.name)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
elif self.text() == other.text():
|
|
|
|
return self.vm.name < other.vm.name
|
|
|
|
return super(VmNetvmItem, self).__lt__(other)
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
class VmInternalItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
super(VmInternalItem, self).__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2015-03-09 21:51:40 +01:00
|
|
|
self.vm = vm
|
2018-05-10 17:59:07 +02:00
|
|
|
self.update()
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-05-10 17:59:07 +02:00
|
|
|
def update(self):
|
|
|
|
self.internal = self.vm.features.get('internal', False)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setText("Yes" if self.internal else "")
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-05-10 17:59:07 +02:00
|
|
|
|
2015-03-09 21:51:40 +01:00
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
return super(VmInternalItem, self).__lt__(other)
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
# features man qvm-features
|
|
|
|
class VmUpdateInfoWidget(QtGui.QWidget):
|
2018-01-08 03:06:42 +01:00
|
|
|
class VmUpdateInfoItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, value, vm):
|
|
|
|
super(VmUpdateInfoWidget.VmUpdateInfoItem, self).__init__()
|
|
|
|
self.value = 0
|
|
|
|
self.vm = vm
|
|
|
|
self.set_value(value)
|
|
|
|
|
|
|
|
def set_value(self, value):
|
2015-02-09 02:21:43 +01:00
|
|
|
if value in ("outdated", "to-be-outdated"):
|
2014-03-31 01:17:27 +02:00
|
|
|
self.value = 30
|
|
|
|
elif value == "update":
|
|
|
|
self.value = 20
|
|
|
|
else:
|
|
|
|
self.value = 0
|
|
|
|
|
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
elif self.value == other.value:
|
|
|
|
return self.vm.name < other.vm.name
|
|
|
|
return self.value < other.value
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
def __init__(self, vm, show_text=True, parent=None):
|
|
|
|
super(VmUpdateInfoWidget, self).__init__(parent)
|
|
|
|
layout = QtGui.QHBoxLayout()
|
2014-03-31 01:17:27 +02:00
|
|
|
self.show_text = show_text
|
|
|
|
if self.show_text:
|
2017-12-20 22:33:39 +01:00
|
|
|
self.label = QtGui.QLabel("")
|
|
|
|
layout.addWidget(self.label, alignment=QtCore.Qt.AlignCenter)
|
2014-03-31 01:17:27 +02:00
|
|
|
else:
|
2017-12-20 22:33:39 +01:00
|
|
|
self.icon = QtGui.QLabel("")
|
|
|
|
layout.addWidget(self.icon, alignment=QtCore.Qt.AlignCenter)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.setLayout(layout)
|
|
|
|
|
2018-05-07 13:17:43 +02:00
|
|
|
self.vm = vm
|
|
|
|
|
2015-02-09 02:21:43 +01:00
|
|
|
self.previous_outdated_state = None
|
2014-03-31 01:17:27 +02:00
|
|
|
self.previous_update_recommended = None
|
|
|
|
self.value = None
|
2018-01-08 03:06:42 +01:00
|
|
|
self.table_item = VmUpdateInfoWidget.VmUpdateInfoItem(self.value, vm)
|
2018-05-07 13:17:43 +02:00
|
|
|
self.update_outdated()
|
|
|
|
|
|
|
|
def update_outdated(self):
|
2018-05-09 19:39:41 +02:00
|
|
|
outdated_state = False
|
|
|
|
|
2018-05-07 13:17:43 +02:00
|
|
|
if self.vm.is_running():
|
2018-05-09 19:39:41 +02:00
|
|
|
if hasattr(self.vm, 'template') and self.vm.template.is_running():
|
|
|
|
outdated_state = "to-be-outdated"
|
2018-05-07 13:17:43 +02:00
|
|
|
|
2018-05-09 19:39:41 +02:00
|
|
|
if not outdated_state:
|
|
|
|
for vol in self.vm.volumes.values():
|
|
|
|
if vol.is_outdated():
|
|
|
|
outdated_state = "outdated"
|
|
|
|
break
|
2018-05-07 13:17:43 +02:00
|
|
|
|
2018-05-31 00:11:30 +02:00
|
|
|
elif self.vm.klass in {'TemplateVM', 'StandaloneVM'} and \
|
2018-05-20 21:30:50 +02:00
|
|
|
self.vm.features.get('updates-available', False):
|
2018-05-10 10:04:17 +02:00
|
|
|
outdated_state = 'update'
|
|
|
|
|
2018-05-09 19:39:41 +02:00
|
|
|
self.update_status_widget(outdated_state)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def update_status_widget(self, state):
|
2018-05-09 19:39:41 +02:00
|
|
|
if state == self.previous_outdated_state:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.previous_outdated_state = state
|
2014-03-31 01:17:27 +02:00
|
|
|
self.value = state
|
2018-01-08 03:06:42 +01:00
|
|
|
self.table_item.set_value(state)
|
2014-03-31 01:17:27 +02:00
|
|
|
if state == "update":
|
|
|
|
label_text = "<font color=\"#CCCC00\">Check updates</font>"
|
|
|
|
icon_path = ":/update-recommended.png"
|
2017-01-22 05:42:38 +01:00
|
|
|
tooltip_text = self.tr("Updates pending!")
|
2014-03-31 01:17:27 +02:00
|
|
|
elif state == "outdated":
|
2018-01-28 20:26:29 +01:00
|
|
|
label_text = "<font color=\"red\">Qube outdated</font>"
|
2014-03-31 01:17:27 +02:00
|
|
|
icon_path = ":/outdated.png"
|
2017-01-22 05:42:38 +01:00
|
|
|
tooltip_text = self.tr(
|
2018-01-28 20:26:29 +01:00
|
|
|
"The qube must be restarted for its filesystem to reflect the "
|
2017-01-22 05:42:38 +01:00
|
|
|
"template's recent committed changes.")
|
2015-02-09 02:21:43 +01:00
|
|
|
elif state == "to-be-outdated":
|
2018-01-28 20:26:29 +01:00
|
|
|
label_text = "<font color=\"#800000\">Template running</font>"
|
2015-02-09 02:21:43 +01:00
|
|
|
icon_path = ":/to-be-outdated.png"
|
2017-01-22 05:42:38 +01:00
|
|
|
tooltip_text = self.tr(
|
2018-01-28 20:26:29 +01:00
|
|
|
"The Template must be stopped before changes from its "
|
|
|
|
"current session can be picked up by this qube.")
|
2017-12-20 22:33:39 +01:00
|
|
|
else:
|
2014-03-31 01:17:27 +02:00
|
|
|
icon_path = None
|
|
|
|
|
2018-05-09 19:39:41 +02:00
|
|
|
if hasattr(self, 'icon'):
|
|
|
|
self.icon.setVisible(False)
|
2014-03-31 01:17:27 +02:00
|
|
|
self.layout().removeWidget(self.icon)
|
2018-05-09 19:39:41 +02:00
|
|
|
del self.icon
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-05-20 21:30:50 +02:00
|
|
|
if self.show_text:
|
|
|
|
self.label.setText(label_text)
|
|
|
|
else:
|
|
|
|
if icon_path is not None:
|
|
|
|
self.icon = VmIconWidget(icon_path, True, 0.7)
|
|
|
|
self.icon.setToolTip(tooltip_text)
|
2018-05-20 22:00:34 +02:00
|
|
|
self.layout().addWidget(self.icon,\
|
|
|
|
alignment=QtCore.Qt.AlignCenter)
|
2018-05-20 21:30:50 +02:00
|
|
|
self.icon.setVisible(True)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
class VmSizeOnDiskItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
super(VmSizeOnDiskItem, self).__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
self.vm = vm
|
|
|
|
self.value = 0
|
|
|
|
self.update()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setTextAlignment(QtCore.Qt.AlignVCenter)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
self.setText("n/a")
|
|
|
|
else:
|
2017-12-20 22:33:39 +01:00
|
|
|
self.value = 10
|
2018-01-08 04:00:48 +01:00
|
|
|
self.value = round(self.vm.get_disk_utilization()/(1024*1024), 2)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setText(str(self.value) + " MiB")
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
elif self.value == other.value:
|
|
|
|
return self.vm.name < other.vm.name
|
|
|
|
return self.value < other.value
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
class VmIPItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
super(VmIPItem, self).__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2015-03-09 21:51:40 +01:00
|
|
|
self.vm = vm
|
2018-05-10 17:59:07 +02:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
2018-01-05 17:31:15 +01:00
|
|
|
self.ip = getattr(self.vm, 'ip', None)
|
|
|
|
self.setText(self.ip if self.ip is not None else 'n/a')
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2015-03-09 21:51:40 +01:00
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
return super(VmIPItem, self).__lt__(other)
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
class VmIncludeInBackupsItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
super(VmIncludeInBackupsItem, self).__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
self.vm = vm
|
2018-05-10 17:59:07 +02:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
2018-01-05 17:31:15 +01:00
|
|
|
if getattr(self.vm, 'include_in_backups', None):
|
2014-03-31 01:17:27 +02:00
|
|
|
self.setText("Yes")
|
|
|
|
else:
|
|
|
|
self.setText("")
|
|
|
|
|
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
elif self.vm.include_in_backups == other.vm.include_in_backups:
|
|
|
|
return self.vm.name < other.vm.name
|
|
|
|
return self.vm.include_in_backups < other.vm.include_in_backups
|
2018-06-11 03:06:35 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2015-03-09 21:51:40 +01:00
|
|
|
return False
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
class VmLastBackupItem(QtGui.QTableWidgetItem):
|
2014-03-31 01:17:27 +02:00
|
|
|
def __init__(self, vm):
|
|
|
|
super(VmLastBackupItem, self).__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
|
|
|
self.vm = vm
|
2018-05-10 17:59:07 +02:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
2018-01-23 20:28:19 +01:00
|
|
|
self.backup_timestamp = getattr(self.vm, 'backup_timestamp', None)
|
|
|
|
|
|
|
|
if self.backup_timestamp:
|
2018-01-18 23:42:34 +01:00
|
|
|
self.setText(
|
2018-01-26 23:17:02 +01:00
|
|
|
str(datetime.datetime.fromtimestamp(self.backup_timestamp)))
|
2014-03-31 01:17:27 +02:00
|
|
|
else:
|
|
|
|
self.setText("")
|
|
|
|
|
2018-06-11 01:56:10 +02:00
|
|
|
#pylint: disable=too-many-return-statements
|
2014-03-31 01:17:27 +02:00
|
|
|
def __lt__(self, other):
|
2018-05-31 00:04:46 +02:00
|
|
|
try:
|
|
|
|
if self.vm.qid == 0:
|
|
|
|
return True
|
|
|
|
elif other.vm.qid == 0:
|
|
|
|
return False
|
|
|
|
elif self.backup_timestamp == other.backup_timestamp:
|
|
|
|
return self.vm.name < other.vm.name
|
|
|
|
elif not self.backup_timestamp:
|
|
|
|
return False
|
|
|
|
elif not other.backup_timestamp:
|
|
|
|
return True
|
|
|
|
return self.backup_timestamp < other.backup_timestamp
|
2018-06-11 03:18:11 +02:00
|
|
|
except exc.QubesPropertyAccessError: # pylint: disable=no-member
|
2014-03-31 01:17:27 +02:00
|
|
|
return False
|