Allow setting default NetVM to None in Global Settings

Replaced old, manual vm list with a nicer, less disgusting
utils.prepare_vm_choice approach.
This commit is contained in:
Marta Marczykowska-Górecka 2018-01-25 22:49:01 +01:00
parent 29a56d9c88
commit 84d7e8bf9c
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B

View File

@ -64,31 +64,25 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
if (not vm.features.get('internal', False)) and vm.qid != 0] if (not vm.features.get('internal', False)) and vm.qid != 0]
# set up updatevm choice # set up updatevm choice
self.update_vm_vmlist, self.update_vm_vmidx = utils.prepare_vm_choice( self.update_vm_vmlist, self.update_vm_idx = utils.prepare_vm_choice(
self.update_vm_combo, self.qvm_collection, 'updatevm', self.update_vm_combo, self.qvm_collection, 'updatevm',
None, allow_none=True None, allow_none=True
) )
# set up clockvm choice # set up clockvm choice
self.clock_vm_vmlist, self.clock_vm_vmidx = utils.prepare_vm_choice( self.clock_vm_vmlist, self.clock_vm_idx = utils.prepare_vm_choice(
self.clock_vm_combo, self.qvm_collection, 'clockvm', self.clock_vm_combo, self.qvm_collection, 'clockvm',
None, allow_none=True None, allow_none=True
) )
# default netvm # set up default netvm
netvms = [vm for vm in all_vms self.default_netvm_vmlist, self.default_netvm_idx = \
if getattr(vm, 'provides_network', False)] utils.prepare_vm_choice(
self.netvm_idx = -1 self.default_netvm_combo,
self.qvm_collection, 'default_netvm',
current_netvm = self.qvm_collection.default_netvm None,
for (i, vm) in enumerate(netvms): filter_function=(lambda vm: vm.provides_network),
text = vm.name allow_none=True)
if vm is current_netvm:
self.netvm_idx = i
text += self.tr(" (current)")
self.default_netvm_combo.insertItem(i, text)
if current_netvm is not None:
self.default_netvm_combo.setCurrentIndex(self.netvm_idx)
#default template #default template
templates = [vm for vm in all_vms if vm.klass == 'TemplateVM'] templates = [vm for vm in all_vms if vm.klass == 'TemplateVM']
@ -113,13 +107,9 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
self.qvm_collection.clockvm = \ self.qvm_collection.clockvm = \
self.clock_vm_vmlist[self.clock_vm_combo.currentIndex()] self.clock_vm_vmlist[self.clock_vm_combo.currentIndex()]
#default netvm # default netvm
if self.default_netvm_combo.currentIndex() != self.netvm_idx: self.qvm_collection.default_netvm = \
name = str(self.default_netvm_combo.currentText()) self.default_netvm_vmlist[self.default_netvm_combo.currentIndex()]
name = name.split(' ')[0]
vm = self.qvm_collection.domains[name]
self.qvm_collection.default_netvm = vm
#default template #default template
if self.default_template_combo.currentIndex() != self.template_idx: if self.default_template_combo.currentIndex() != self.template_idx: