Exemplo n.º 1
0
def main():

    global qubes_host
    qubes_host = QubesHost()

    global app
    app = QApplication(sys.argv)
    app.setOrganizationName("The Qubes Project")
    app.setOrganizationDomain("http://qubes-os.org")
    app.setApplicationName("Qubes Restore VMs")

    sys.excepthook = handle_exception

    qvm_collection = QubesVmCollection()
    qvm_collection.lock_db_for_reading()
    qvm_collection.load()
    qvm_collection.unlock_db()

    global restore_window
    restore_window = RestoreVMsWindow()

    restore_window.show()

    app.exec_()
    app.exit()
Exemplo n.º 2
0
def set_vcpus(module, options):
    '''Sets starting vcpus if passed, and verifies the value'''
    if module.params['vcpus'] is not None:
        if module.params['vcpus'] <= 0:
            module.fail_json(msg='Vcpus cannot be negative')
        qubes_host = QubesHost()
        if module.params['vcpus'] > qubes_host.no_cpus:
            module.fail_json(msg='This host has only %s cpus' %
                             str(qubes_host.no_cpus))
        options['args']['vcpus'] = module.params['vcpus']
Exemplo n.º 3
0
def set_maxmem(module, options):
    '''Sets max memory if passed, and verifies the value'''
    if module.params['maxmem'] is not None:
        if module.params['maxmem'] <= 0:
            module.fail_json(msg='Memory cannot be negative')
        qubes_host = QubesHost()
        if module.params['maxmem'] > qubes_host.memory_total / 1024:
            module.fail_json(msg='This host has only %s MB of RAM' %
                             str(qubes_host.memory_total / 1024))
        options['args']['maxmem'] = module.params['maxmem']
Exemplo n.º 4
0
def main():

    global qubes_host
    qubes_host = QubesHost()

    global app
    app = QApplication(sys.argv)
    app.setOrganizationName("The Qubes Project")
    app.setOrganizationDomain("http://qubes-os.org")
    app.setApplicationName("Qubes VM Settings")

    sys.excepthook = handle_exception

    qvm_collection = QubesVmCollection()
    qvm_collection.lock_db_for_reading()
    qvm_collection.load()
    qvm_collection.unlock_db()

    vm = None
    tab = "basic"

    if len(sys.argv) > 1:
        vm = qvm_collection.get_vm_by_name(sys.argv[1])
        if vm is None or vm.qid not in qvm_collection:
            QMessageBox.critical(None, "Qubes VM Settings Error",
                    "A VM with the name '{0}' does not exist in the system.".format(sys.argv[1]))
            sys.exit(1)
        if len(sys.argv) > 2:
            tab_arg = sys.argv[2]
            print tab_arg
            if tab_arg in VMSettingsWindow.tabs_indices:
                tab = tab_arg
            else: QMessageBox.warning(None, "Qubes VM Settings Error",
                    "There is no such tab as '{0}'. Opening default tab instead.".format(tab_arg))

    else:
        vms_list = [vm.name for vm in qvm_collection.values() if (vm.is_appvm() or vm.is_template())]
        vmname = QInputDialog.getItem(None, "Select VM", "Select VM:", vms_list, editable = False)
        if not vmname[1]:
            sys.exit(1)
        vm = qvm_collection.get_vm_by_name(vmname[0])


    global settings_window
    settings_window = VMSettingsWindow(vm, app, qvm_collection, tab)

    settings_window.show()

    app.exec_()
    app.exit()
Exemplo n.º 5
0
    def __init_advanced_tab__(self):

        #mem/cpu
        qubes_memory = QubesHost().memory_total / 1024

        self.init_mem.setValue(int(self.vm.memory))
        self.init_mem.setMaximum(qubes_memory)

        self.max_mem_size.setValue(int(self.vm.maxmem))
        self.max_mem_size.setMaximum(qubes_memory)

        self.vcpus.setMinimum(1)
        self.vcpus.setMaximum(QubesHost().no_cpus)
        self.vcpus.setValue(int(self.vm.vcpus))

        self.include_in_balancing.setEnabled(True)
        self.include_in_balancing.setChecked(
            self.vm.services['meminfo-writer'] == True)
        if self.vm.type == "HVM":
            self.include_in_balancing.setChecked(False)
            self.include_in_balancing.setEnabled(False)
        self.max_mem_size.setEnabled(self.include_in_balancing.isChecked())

        #paths
        self.dir_path.setText(self.vm.dir_path)
        self.config_path.setText(self.vm.conf_file)
        if self.vm.template is not None:
            self.root_img_path.setText(self.vm.template.root_img)
        elif self.vm.root_img is not None:
            self.root_img_path.setText(self.vm.root_img)
        else:
            self.root_img_path.setText("n/a")
        if self.vm.volatile_img is not None:
            self.volatile_img_path.setText(self.vm.volatile_img)
        else:
            self.volatile_img_path.setText('n/a')
        self.private_img_path.setText(self.vm.private_img)

        #kernel

        #in case VM is HVM
        if not hasattr(self.vm, "kernel"):
            self.kernel_groupbox.setVisible(False)
        else:
            self.kernel_groupbox.setVisible(True)
            # construct available kernels list
            text = "default (" + self.qvm_collection.get_default_kernel() + ")"
            kernel_list = [text]
            for k in os.listdir(system_path["qubes_kernels_base_dir"]):
                kernel_list.append(k)
            kernel_list.append("none")

            self.kernel_idx = 0

            # put available kernels to a combobox
            for (i, k) in enumerate(kernel_list):
                text = k
                # and mark the current choice
                if (text.startswith("default") and self.vm.uses_default_kernel
                    ) or (self.vm.kernel == k
                          and not self.vm.uses_default_kernel) or (
                              k == "none" and self.vm.kernel == None):
                    text += " (current)"
                    self.kernel_idx = i
                self.kernel.insertItem(i, text)
            self.kernel.setCurrentIndex(self.kernel_idx)

            #kernel opts
            if self.vm.uses_default_kernelopts:
                self.kernel_opts.setText(self.vm.kernelopts + " (default)")
            else:
                self.kernel_opts.setText(self.vm.kernelopts)

        if not hasattr(self.vm, "drive"):
            self.drive_groupbox.setVisible(False)
        else:
            self.drive_groupbox.setVisible(True)
            self.drive_groupbox.setChecked(self.vm.drive is not None)
            self.drive_running_warning.setVisible(self.vm.is_running())
            self.drive_type.addItems(["hd", "cdrom"])
            self.drive_type.setCurrentIndex(0)
            vm_list = [
                vm for vm in self.qvm_collection.values()
                if not vm.internal and vm.qid != self.vm.qid
            ]
            # default to dom0 (in case of nonexisting vm already set...)
            self.drive_domain_idx = 0
            for (i, vm) in enumerate(sorted(vm_list, key=lambda v: v.name)):
                if vm.qid == 0:
                    self.drive_domain_idx = i
                self.drive_domain.insertItem(i, vm.name)

            if self.vm.drive is not None:
                (drv_type, drv_domain, drv_path) = self.vm.drive.split(":")
                if drv_type == "cdrom":
                    self.drive_type.setCurrentIndex(1)
                else:
                    self.drive_type.setCurrentIndex(0)

                for i in xrange(self.drive_domain.count()):
                    if drv_domain == self.drive_domain.itemText(i):
                        self.drive_domain_idx = i

                self.drive_path.setText(drv_path)
            self.drive_domain.setCurrentIndex(self.drive_domain_idx)

        if not hasattr(self.vm, "dispvm_netvm"):
            self.other_groupbox.setVisible(False)
        else:
            self.other_groupbox.setVisible(True)
            netvm_list = [
                vm for vm in self.qvm_collection.values()
                if not vm.internal and vm.is_netvm() and vm.qid != 0
            ]
            self.dispvm_netvm_idx = -1

            text = "default (same as VM own NetVM)"
            if self.vm.uses_default_dispvm_netvm:
                text += " (current)"
                self.dispvm_netvm_idx = 0
            self.dispvm_netvm.insertItem(0, text)

            for (i, vm) in enumerate(netvm_list):
                text = vm.name
                if self.vm.dispvm_netvm is not None and vm.qid == \
                        self.vm.dispvm_netvm.qid and not \
                        self.vm.uses_default_dispvm_netvm:
                    self.dispvm_netvm_idx = i + 1
                    text += " (current)"
                self.dispvm_netvm.insertItem(i + 1, text)

            none_text = "none"
            if self.vm.dispvm_netvm is None:
                none_text += " (current)"
                self.dispvm_netvm_idx = len(netvm_list) + 1
            self.dispvm_netvm.insertItem(len(netvm_list) + 1, none_text)

            self.dispvm_netvm.setCurrentIndex(self.dispvm_netvm_idx)