Merge remote-tracking branch 'origin/pr/278'
* origin/pr/278: fixed trailing spaces Added TemplateVM and disposableVM to Create New Qube
This commit is contained in:
		
						commit
						81c0872f2b
					
				@ -52,7 +52,16 @@ class CreateVMThread(QtCore.QThread):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def run(self):
 | 
					    def run(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            if self.vmclass == 'StandaloneVM' and self.template is not None:
 | 
					            if self.vmclass == 'TemplateVM' and self.template is not None:
 | 
				
			||||||
 | 
					                args = {}
 | 
				
			||||||
 | 
					                if self.pool:
 | 
				
			||||||
 | 
					                    args['pool'] = self.pool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                vm = self.app.clone_vm(self.template, self.name,
 | 
				
			||||||
 | 
					                                       self.vmclass, **args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                vm.label = self.label
 | 
				
			||||||
 | 
					            elif self.vmclass == 'StandaloneVM' and self.template is not None:
 | 
				
			||||||
                args = {
 | 
					                args = {
 | 
				
			||||||
                    'ignore_volumes': ['private']
 | 
					                    'ignore_volumes': ['private']
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -63,8 +72,6 @@ class CreateVMThread(QtCore.QThread):
 | 
				
			|||||||
                                       self.vmclass, **args)
 | 
					                                       self.vmclass, **args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                vm.label = self.label
 | 
					                vm.label = self.label
 | 
				
			||||||
                for k, v in self.properties.items():
 | 
					 | 
				
			||||||
                    setattr(vm, k, v)
 | 
					 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                args = {
 | 
					                args = {
 | 
				
			||||||
                    "name": self.name,
 | 
					                    "name": self.name,
 | 
				
			||||||
@ -76,8 +83,8 @@ class CreateVMThread(QtCore.QThread):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                vm = self.app.add_new_vm(self.vmclass, **args)
 | 
					                vm = self.app.add_new_vm(self.vmclass, **args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                for k, v in self.properties.items():
 | 
					            for k, v in self.properties.items():
 | 
				
			||||||
                    setattr(vm, k, v)
 | 
					                setattr(vm, k, v)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except qubesadmin.exc.QubesException as qex:
 | 
					        except qubesadmin.exc.QubesException as qex:
 | 
				
			||||||
            self.msg = str(qex)
 | 
					            self.msg = str(qex)
 | 
				
			||||||
@ -104,7 +111,8 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
 | 
				
			|||||||
            widget=self.template_vm,
 | 
					            widget=self.template_vm,
 | 
				
			||||||
            qubes_app=self.app,
 | 
					            qubes_app=self.app,
 | 
				
			||||||
            filter_function=(lambda vm: not utils.is_internal(vm) and
 | 
					            filter_function=(lambda vm: not utils.is_internal(vm) and
 | 
				
			||||||
                             vm.klass == 'TemplateVM'))
 | 
					                             vm.klass == 'TemplateVM'),
 | 
				
			||||||
 | 
					                             allow_none=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        default_template = self.app.default_template
 | 
					        default_template = self.app.default_template
 | 
				
			||||||
        for i in range(self.template_vm.count()):
 | 
					        for i in range(self.template_vm.count()):
 | 
				
			||||||
@ -113,6 +121,8 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
 | 
				
			|||||||
                self.template_vm.setItemText(
 | 
					                self.template_vm.setItemText(
 | 
				
			||||||
                    i, str(default_template) + " (default)")
 | 
					                    i, str(default_template) + " (default)")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.template_type = "template"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        utils.initialize_widget_with_default(
 | 
					        utils.initialize_widget_with_default(
 | 
				
			||||||
            widget=self.netvm,
 | 
					            widget=self.netvm,
 | 
				
			||||||
            choices=[(vm.name, vm) for vm in self.app.domains
 | 
					            choices=[(vm.name, vm) for vm in self.app.domains
 | 
				
			||||||
@ -145,11 +155,12 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
 | 
				
			|||||||
                self.tr('Cannot create a qube when no template exists.'))
 | 
					                self.tr('Cannot create a qube when no template exists.'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        type_list = [
 | 
					        type_list = [
 | 
				
			||||||
            (self.tr("Qube based on a template (AppVM)"), 'AppVM'),
 | 
					            (self.tr("AppVM (persistent home, volatile root)"), 'AppVM'),
 | 
				
			||||||
            (self.tr("Standalone qube copied from a template"),
 | 
					            (self.tr("TemplateVM (template home, persistent root)"),
 | 
				
			||||||
             'StandaloneVM-copy'),
 | 
					                'TemplateVM'),
 | 
				
			||||||
            (self.tr("Empty standalone qube (install your own OS)"),
 | 
					            (self.tr("StandaloneVM (fully persistent)"), 'StandaloneVM'),
 | 
				
			||||||
             'StandaloneVM-empty')]
 | 
					            (self.tr("DisposableVM (fully volatile)"), 'DispVM')]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        utils.initialize_widget(widget=self.vm_type,
 | 
					        utils.initialize_widget(widget=self.vm_type,
 | 
				
			||||||
                                choices=type_list,
 | 
					                                choices=type_list,
 | 
				
			||||||
                                selected_value='AppVM',
 | 
					                                selected_value='AppVM',
 | 
				
			||||||
@ -164,8 +175,7 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
 | 
				
			|||||||
        self.done(0)
 | 
					        self.done(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def accept(self):
 | 
					    def accept(self):
 | 
				
			||||||
        selected_type = self.vm_type.currentData()
 | 
					        vmclass = self.vm_type.currentData()
 | 
				
			||||||
        vmclass = selected_type.split('-')[0]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        name = str(self.name.text())
 | 
					        name = str(self.name.text())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -181,12 +191,19 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        template = self.template_vm.currentData()
 | 
					        template = self.template_vm.currentData()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if vmclass in ['AppVM', 'DispVM'] and template is None:
 | 
				
			||||||
 | 
					            QtWidgets.QMessageBox.warning(
 | 
				
			||||||
 | 
					                self,
 | 
				
			||||||
 | 
					                self.tr('Unspecified template'),
 | 
				
			||||||
 | 
					                self.tr('{}s must be based on a template!'.format(vmclass)))
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        properties = {'provides_network': self.provides_network.isChecked()}
 | 
					        properties = {'provides_network': self.provides_network.isChecked()}
 | 
				
			||||||
        if self.netvm.currentIndex() != 0:
 | 
					        if self.netvm.currentIndex() != 0:
 | 
				
			||||||
            properties['netvm'] = self.netvm.currentData()
 | 
					            properties['netvm'] = self.netvm.currentData()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Standalone - not based on a template
 | 
					        # Standalone - not based on a template
 | 
				
			||||||
        if selected_type == 'StandaloneVM-empty':
 | 
					        if vmclass == 'StandaloneVM' and template is None:
 | 
				
			||||||
            properties['virt_mode'] = 'hvm'
 | 
					            properties['virt_mode'] = 'hvm'
 | 
				
			||||||
            properties['kernel'] = None
 | 
					            properties['kernel'] = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -229,25 +246,46 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
 | 
				
			|||||||
                    ['qubes-vm-boot-from-device', str(self.name.text())])
 | 
					                    ['qubes-vm-boot-from-device', str(self.name.text())])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def type_change(self):
 | 
					    def type_change(self):
 | 
				
			||||||
        if self.vm_type.currentData() == 'AppVM':
 | 
					        template = self.template_vm.currentData()
 | 
				
			||||||
            self.template_vm.setEnabled(True)
 | 
					        klass = self.vm_type.currentData()
 | 
				
			||||||
            if self.template_vm.currentIndex() == -1:
 | 
					 | 
				
			||||||
                self.template_vm.setCurrentIndex(0)
 | 
					 | 
				
			||||||
            self.install_system.setEnabled(False)
 | 
					 | 
				
			||||||
            self.install_system.setChecked(False)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if self.vm_type.currentData() == 'StandaloneVM-copy':
 | 
					        if klass in ['TemplateVM', 'StandaloneVM'] and template is None:
 | 
				
			||||||
            self.template_vm.setEnabled(True)
 | 
					 | 
				
			||||||
            if self.template_vm.currentIndex() == -1:
 | 
					 | 
				
			||||||
                self.template_vm.setCurrentIndex(0)
 | 
					 | 
				
			||||||
            self.install_system.setEnabled(False)
 | 
					 | 
				
			||||||
            self.install_system.setChecked(False)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if self.vm_type.currentData() == 'StandaloneVM-empty':
 | 
					 | 
				
			||||||
            self.template_vm.setEnabled(False)
 | 
					 | 
				
			||||||
            self.template_vm.setCurrentIndex(-1)
 | 
					 | 
				
			||||||
            self.install_system.setEnabled(True)
 | 
					            self.install_system.setEnabled(True)
 | 
				
			||||||
            self.install_system.setChecked(True)
 | 
					            self.install_system.setChecked(True)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            self.install_system.setEnabled(False)
 | 
				
			||||||
 | 
					            self.install_system.setChecked(False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if klass == 'DispVM':
 | 
				
			||||||
 | 
					            self.template_vm.clear()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for vm in self.app.domains:
 | 
				
			||||||
 | 
					                if utils.is_internal(vm):
 | 
				
			||||||
 | 
					                    continue
 | 
				
			||||||
 | 
					                if vm.klass != 'AppVM':
 | 
				
			||||||
 | 
					                    continue
 | 
				
			||||||
 | 
					                if getattr(vm, 'template_for_dispvms', True):
 | 
				
			||||||
 | 
					                    self.template_vm.addItem(vm.name, userData=vm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            self.template_vm.insertItem(self.template_vm.count(),
 | 
				
			||||||
 | 
					                                        utils.translate("(none)"), None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            self.template_vm.setCurrentIndex(0)
 | 
				
			||||||
 | 
					            self.template_type = "dispvm"
 | 
				
			||||||
 | 
					        elif self.template_type == "dispvm":
 | 
				
			||||||
 | 
					            self.template_vm.clear()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for vm in self.app.domains:
 | 
				
			||||||
 | 
					                if utils.is_internal(vm):
 | 
				
			||||||
 | 
					                    continue
 | 
				
			||||||
 | 
					                if vm.klass == 'TemplateVM':
 | 
				
			||||||
 | 
					                    self.template_vm.addItem(vm.name, userData=vm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            self.template_vm.insertItem(self.template_vm.count(),
 | 
				
			||||||
 | 
					                                        utils.translate("(none)"), None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            self.template_vm.setCurrentIndex(0)
 | 
				
			||||||
 | 
					            self.template_type = "template"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def install_change(self):
 | 
					    def install_change(self):
 | 
				
			||||||
        if self.install_system.isChecked():
 | 
					        if self.install_system.isChecked():
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user