def _register_watches(self, libvirt_domain): if libvirt_domain: name = libvirt_domain.name() if name in self._qdb: return if not libvirt_domain.isActive(): return # open separate connection to Qubes DB: # 1. to not confuse pull() with responses to real commands sent from # other threads (like read, write etc) with watch events # 2. to not think whether QubesDB is thread-safe (it isn't) try: self._qdb[name] = QubesDB(name) except Error as e: if e.args[0] != 2: raise libvirt.virEventAddTimeout(500, self._retry_register_watches, libvirt_domain) return else: name = "dom0" self._qdb[name] = QubesDB(name) try: self._qdb[name].watch('/qubes-block-devices') except Error as e: if e.args[0] == 102: # Connection reset by peer # QubesDB daemon not running - most likely we've connected to # stale daemon which just exited; retry later libvirt.virEventAddTimeout(500, self._retry_register_watches, libvirt_domain) return self._qdb_events[name] = libvirt.virEventAddHandle( self._qdb[name].watch_fd(), libvirt.VIR_EVENT_HANDLE_READABLE, self._qdb_handler, name)
def add_handle(self, fd, events, cb, opaque): try: return libvirt.virEventAddHandle(fd, events, cb, opaque) except libvirt.libvirtError, e: message = e.get_error_message() code = e.get_error_code() raise exception.LibvirtAPI(message, code)
def _register_watches(self, libvirt_domain): if libvirt_domain: name = libvirt_domain.name() if name in self._qdb: return # open separate connection to Qubes DB: # 1. to not confuse pull() with responses to real commands sent from # other threads (like read, write etc) with watch events # 2. to not think whether QubesDB is thread-safe (it isn't) while libvirt_domain.isActive() and name not in self._qdb: try: self._qdb[name] = QubesDB(name) except Error as e: if e.args[0] != 2: raise time.sleep(0.5) if name not in self._qdb: # domain no longer active return else: name = "dom0" self._qdb[name] = QubesDB(name) self._qdb[name].watch('/qubes-block-devices') self._qdb_events[name] = libvirt.virEventAddHandle( self._qdb[name].watch_fd(), libvirt.VIR_EVENT_HANDLE_READABLE, self._qdb_handler, name)
def start(self): libvirt.virEventRegisterDefaultImpl() libvirt.registerErrorHandler(error_handler, None) atexit.register(self.reset_term) self.attrs = termios.tcgetattr(0) tty.setraw(0) self.connection = LibvirtConnect.get_connection() self.domain = self.connection.lookupByName(self.domain_name) self.state = self.domain.state(0) self.connection.domainEventRegister(self.lifecycle_callback, self) sys.stdout.write('Press Control+] to quit.\n\r') sys.stdout.flush() libvirt.virEventAddHandle( 0, libvirt.VIR_EVENT_HANDLE_READABLE, self.stdin_callback, None) while self.check_console(): libvirt.virEventRunDefaultImpl() sys.stdout.write('\n\rExited.\n\r') sys.stdout.flush()
console.state = console.domain.state(0) logging.info("%s transitioned to state %d, reason %d", console.uuid, console.state[0], console.state[1]) # main if len(sys.argv) != 3: print("Usage:", sys.argv[0], "URI UUID") print("for example:", sys.argv[0], "'qemu:///system' '32ad945f-7e78-c33a-e96d-39f25e025d81'") sys.exit(1) uri = sys.argv[1] uuid = sys.argv[2] print("Escape character is ^]") logging.basicConfig(filename='msg.log', level=logging.DEBUG) logging.info("URI: %s", uri) logging.info("UUID: %s", uuid) libvirt.virEventRegisterDefaultImpl() libvirt.registerErrorHandler(error_handler, None) atexit.register(reset_term) attrs = termios.tcgetattr(0) tty.setraw(0) console = Console(uri, uuid) console.stdin_watch = libvirt.virEventAddHandle(0, libvirt.VIR_EVENT_HANDLE_READABLE, stdin_callback, console) while check_console(console): libvirt.virEventRunDefaultImpl()
logging.info("%s transitioned to state %d, reason %d", console.uuid, console.state[0], console.state[1]) # main if len(sys.argv) != 3: print("Usage:", sys.argv[0], "URI UUID") print("for example:", sys.argv[0], "'qemu:///system' '32ad945f-7e78-c33a-e96d-39f25e025d81'") sys.exit(1) uri = sys.argv[1] uuid = sys.argv[2] print("Escape character is ^]") logging.basicConfig(filename='msg.log', level=logging.DEBUG) logging.info("URI: %s", uri) logging.info("UUID: %s", uuid) libvirt.virEventRegisterDefaultImpl() libvirt.registerErrorHandler(error_handler, None) atexit.register(reset_term) attrs = termios.tcgetattr(0) tty.setraw(0) console = Console(uri, uuid) console.stdin_watch = libvirt.virEventAddHandle(0, libvirt.VIR_EVENT_HANDLE_READABLE, stdin_callback, console) while check_console(console): libvirt.virEventRunDefaultImpl()