Added proper error handling and Check netvm_name is not None

This commit is contained in:
donoban 2020-12-11 00:38:06 +01:00
parent f90ab86a73
commit 0cb89e611a
No known key found for this signature in database
GPG Key ID: 141310D8E3ED08A5

View File

@ -820,8 +820,20 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
QMessageBox.Yes | QMessageBox.Cancel) QMessageBox.Yes | QMessageBox.Cancel)
if reply == QMessageBox.Yes: if reply == QMessageBox.Yes:
failed = []
for info in selected_vms: for info in selected_vms:
info.vm.template = template try:
info.vm.template = template
except:
failed.append(info.name)
if failed:
info_dialog = QMessageBox(self)
info_dialog.setWindowTitle(self.tr("Warning!"))
info_dialog.setText(
self.tr("Some template change failed: {0} "
).format(", ".join(failed)))
info_dialog.show()
def change_network(self, netvm_name): def change_network(self, netvm_name):
selected_vms = self.get_selected_vms() selected_vms = self.get_selected_vms()
@ -836,25 +848,39 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
return return
try: try:
check_power = any(info.state['power'] == 'Running' for info if netvm_name is not None:
in self.get_selected_vms()) check_power = any(info.state['power'] == 'Running' for info
netvm = self.qubes_cache.get_vm(name=netvm_name) in self.get_selected_vms())
if check_power and netvm.state['power'] != 'Running': netvm = self.qubes_cache.get_vm(name=netvm_name)
reply = QMessageBox.question( if check_power and netvm.state['power'] != 'Running':
self, self.tr("Qube Start Confirmation"), reply = QMessageBox.question(
self.tr("<br>Can not change netvm to a halted Qube.<br>" self, self.tr("Qube Start Confirmation"),
"Do you want to start the Qube <b>'{0}'</b>?").format( self.tr("<br>Can not change netvm to a halted Qube.<br>"
netvm_name), "Do you want to start the Qube <b>'{0}'</b>?").format(
QMessageBox.Yes | QMessageBox.Cancel) netvm_name),
QMessageBox.Yes | QMessageBox.Cancel)
if reply == QMessageBox.Yes: if reply == QMessageBox.Yes:
with common_threads.busy_cursor(): with common_threads.busy_cursor():
netvm.vm.start() netvm.vm.start()
else: else:
return return
failed = []
for info in self.get_selected_vms(): for info in self.get_selected_vms():
info.vm.netvm = netvm_name try:
info.vm.netvm = netvm_name
except:
failed.append(info.name)
if failed:
info_dialog = QMessageBox(self)
info_dialog.setWindowTitle(self.tr("Warning!"))
info_dialog.setText(
self.tr("Some network change failed: {0} "
).format(", ".join(failed)))
info_dialog.show()
except exc.QubesValueError as ex: except exc.QubesValueError as ex:
QMessageBox.warning( QMessageBox.warning(
self, self,