def do_create_vm(vmclass, vmname, label, template_vm, netvm, standalone, allow_networking, thread_monitor): vm = None qc = QubesVmCollection() qc.lock_db_for_writing() qc.load() try: if not standalone: vm = qc.add_new_vm(vmclass, name=vmname, template=template_vm, label=label) else: vm = qc.add_new_vm(vmclass, name=vmname, template=None, label=label) vm.create_on_disk(verbose=False, source_template=template_vm) if not allow_networking: vm.uses_default_netvm = False vm.netvm = None else: vm.netvm = netvm if vm.netvm.qid == qc.get_default_netvm().qid: vm.uses_default_netvm = True else: vm.uses_default_netvm = False qc.save() except Exception as ex: thread_monitor.set_error_msg(str(ex)) if vm: vm.remove_from_disk() qc.pop(vm.qid) finally: qc.unlock_db() thread_monitor.set_finished()
def notify_vm_by_name(vmname): monitor_layout = get_monitor_layout() if len(monitor_layout) == 0: return qc = QubesVmCollection() qc.lock_db_for_reading() qc.load() qc.unlock_db() vm = qc.get_vm_by_name(vmname) if not vm: print >> sys.stderr, "No such VM!" return 1 if not vm.is_running(): print >> sys.stderr, "VM not running!" return 1 pipe = notify_vm(vm, monitor_layout) pipe.wait() return 0
def __init__(self, **kwargs): super(QubesTemplateHVm, self).__init__(**kwargs) self.appvms = QubesVmCollection()
frontend=sys.argv[3].split('-') if len(frontend)!=2: print 'Error: frontendvm-device must be in <controller>-<port> format' sys.exit(1) (controller, port)=frontend if len(sys.argv)>4: backendvm_xid=int(sys.argv[4]) backendvm_name=xen.lowlevel.xl.ctx().domid_to_name(backendvm_xid) else: backendvm_xid=0 cmd = "/usr/lib/qubes/vusb-ctl.py unbind '%s'" % backendvm_device if backendvm_xid == 0: os.system("sudo %s" % cmd) else: from qubes.qubes import QubesVmCollection qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_reading() qvm_collection.load() qvm_collection.unlock_db() # launch qvm_collection.get_vm_by_name(backendvm_name).run(cmd, user="******") # FIXME: command injection os.system("xenstore-write /local/domain/%s/backend/vusb/%s/%s/port/%s ''" % (backendvm_xid, frontendvm_xid, controller, port))
def main(): module = AnsibleModule(argument_spec=dict( name=dict(required=True, type='str'), state=dict(default='present', choices=['present', 'absent']), type=dict(default='appvm', choices=['appvm', 'netvm', 'proxyvm', 'hvm', 'templatehvm']), template=dict(type='str'), standalone=dict(default=False, type='bool'), label=dict(choices=[ 'red', 'orange', 'yellow', 'green', 'gray', 'blue', 'purple', 'black' ]), pool_name=dict(default='default', type='str'), memory=dict(type='int'), maxmem=dict(type='int'), mac=dict(type='str'), pci_strictreset=dict(type='bool'), pci_e820_host=dict(default=False, type='bool'), netvm=dict(type='str'), dispvm_netvm=dict(type='str'), kernel=dict(type='str'), vcpus=dict(type='int'), kernelopts=dict(type='str'), drive=dict(type='str'), debug=dict(type='bool'), default_user=dict(type='str'), include_in_backups=dict(type='bool'), qrexec_installed=dict(type='bool'), internal=dict(type='bool'), guiagent_installed=dict(type='bool'), seamless_gui_mode=dict(type='bool'), autostart=dict(type='bool'), qrexec_timeout=dict(type='int'), timezone=dict(), )) if not QUBES_DOM0: module.fail_json(msg='This module must be run from QubeOS dom0') qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_writing() qvm_collection.load() # Set parameters changed = True options = set_options(module, qvm_collection) if options['state'] == 'present': if qvm_collection.get_vm_by_name(options['args']['name']) is not None: changed = False qube = qvm_collection.get_vm_by_name(options['args']['name']) for key in options['args']: if key == 'pool_name': if qube.pool_name != options['args']['pool_name']: module.fail_json( msg='Existing VM storage pool cannot be changed') elif getattr(qube, key) != options['args'][key]: setattr(qube, key, options['args'][key]) changed = True if not isinstance(qube, QubesVmClasses[options['type']]): module.fail_json(msg='Existing VM type cannot be changed') else: try: qube = qvm_collection.add_new_vm(options['type'], **options['args']) except QubesException as e: module.fail_json(msg='Unable to create VM: %s' % e) qube.create_on_disk(source_template=options['base_template']) elif options['state'] == 'absent': if qvm_collection.get_vm_by_name(options['args']['name']) is None: changed = False else: qube = qvm_collection.get_vm_by_name(options['args']['name']) if qube.is_running(): try: qube.force_shutdown() except (IOError, OSError, QubesException) as e: module.fail_json(msg='Unable to shutdown VM: %s' % e) if qube.is_template(): # Report what VMs use this template dependent_qubes = qube.qvm_collection.get_vms_based_on( qube.qid) if len(dependent_qubes) > 0: module.fail_json( msg='Please remove VMs dependent on this template first' ) if qvm_collection.default_template_qid == qube.qid: qvm_collection.default_template_qid = None if qube.is_netvm(): if qvm_collection.default_netvm_qid == qube.qid: qvm_collection.default_netvm_qid = None if qube.installed_by_rpm: module.fail_json(msg='Qube managed by RPM/DNF') qube.remove_from_disk() qvm_collection.pop(qube.qid) qvm_collection.save() qvm_collection.unlock_db() module.exit_json(changed=changed)
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()