⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xenddomain.py

📁 xen虚拟机源代码安装包
💻 PY
📖 第 1 页 / 共 5 页
字号:
                raise VMBadState("Domain is already running",                                 POWER_STATE_NAMES[DOM_STATE_HALTED],                                 POWER_STATE_NAMES[dominfo._stateGet()])                        dominfo.start(is_managed = True)        finally:            self.domains_lock.release()        try:            dominfo.waitForDevices()        except Exception, ex:            log.warn("Failed to setup devices for " + str(dominfo) + ": " + str(ex))            dominfo.destroy()            raise        if not start_paused:            dominfo.unpause()    def domain_delete(self, domid):        """Remove a managed domain from database        @require: Domain must not be running.        @param domid: Domain name or domain ID.        @type domid: string or int        @rtype: None        @raise XendError: If domain is still running        """        self.domains_lock.acquire()        try:            try:                dominfo = self.domain_lookup_nr(domid)                if not dominfo:                    raise XendInvalidDomain(str(domid))                if dominfo._stateGet() != XEN_API_VM_POWER_STATE_HALTED:                    raise VMBadState("Domain is not halted.",                                     POWER_STATE_NAMES[DOM_STATE_HALTED],                                     POWER_STATE_NAMES[dominfo._stateGet()])                                self._domain_delete_by_info(dominfo)            except Exception, ex:                raise XendError(str(ex))        finally:            self.domains_lock.release()    def domain_delete_by_dominfo(self, dominfo):        """Only for use by XendDomainInfo.        """        self.domains_lock.acquire()        try:            self._domain_delete_by_info(dominfo)        finally:            self.domains_lock.release()    def _domain_delete_by_info(self, dominfo):        """Expects to be protected by domains_lock.        """        log.info("Domain %s (%s) deleted." %                 (dominfo.getName(), dominfo.info.get('uuid')))                        dominfo.metrics.destroy()        self._managed_domain_unregister(dominfo)        self._remove_domain(dominfo)        XendDevices.destroy_device_state(dominfo)        dominfo.destroy_xapi_device_instances()    def domain_configure(self, config):        """Configure an existing domain.        @param vmconfig: vm configuration        @type vmconfig: SXP Object (list of lists)        @todo: Not implemented        """        # !!!        raise XendError("Unsupported")    def domain_restore(self, src, paused=False):        """Restore a domain from file.        @param src: filename of checkpoint file to restore from        @type src: string        @return: Restored domain        @rtype: XendDomainInfo        @raise XendError: Failure to restore domain        """        try:            oflags = os.O_RDONLY            if hasattr(os, "O_LARGEFILE"):                oflags |= os.O_LARGEFILE            fd = os.open(src, oflags)            try:                return self.domain_restore_fd(fd, paused=paused)            finally:                os.close(fd)        except OSError, ex:            raise XendError("can't read guest state file %s: %s" %                            (src, ex[1]))    def domain_restore_fd(self, fd, paused=False, relocating=False):        """Restore a domain from the given file descriptor.        @param fd: file descriptor of the checkpoint file        @type fd: File object        @rtype: XendDomainInfo        @raise XendError: if failed to restore        """        try:            return XendCheckpoint.restore(self, fd, paused=paused, relocating=relocating)        except XendError, e:            log.exception("Restore failed")            raise        except:            # I don't really want to log this exception here, but the error            # handling in the relocation-socket handling code (relocate.py) is            # poor, so we need to log this for debugging.            log.exception("Restore failed")            raise XendError("Restore failed")     def domain_unpause(self, domid):        """Unpause domain execution.        @param domid: Domain ID or Name        @type domid: int or string.        @rtype: None        @raise XendError: Failed to unpause        @raise XendInvalidDomain: Domain is not valid                """        try:            dominfo = self.domain_lookup_nr(domid)            if not dominfo:                raise XendInvalidDomain(str(domid))            if dominfo.getDomid() == DOM0_ID:                raise XendError("Cannot unpause privileged domain %s" % domid)            if dominfo._stateGet() not in (DOM_STATE_PAUSED, DOM_STATE_RUNNING):                raise VMBadState("Domain '%s' is not started" % domid,                                 POWER_STATE_NAMES[DOM_STATE_PAUSED],                                 POWER_STATE_NAMES[dominfo._stateGet()])            log.info("Domain %s (%d) unpaused.", dominfo.getName(),                     int(dominfo.getDomid()))            dominfo.unpause()        except XendInvalidDomain:            log.exception("domain_unpause")            raise        except Exception, ex:            log.exception("domain_unpause")            raise XendError(str(ex))    def domain_pause(self, domid, state=False):        """Pause domain execution.        @param domid: Domain ID or Name        @type domid: int or string.        @keyword state: If True, will return the domain state before pause        @type state: bool        @rtype: int if state is True        @return: Domain state (DOM_STATE_*)        @rtype: None if state is False        @raise XendError: Failed to pause        @raise XendInvalidDomain: Domain is not valid        """                try:            dominfo = self.domain_lookup_nr(domid)            if not dominfo:                raise XendInvalidDomain(str(domid))            if dominfo.getDomid() == DOM0_ID:                raise XendError("Cannot pause privileged domain %s" % domid)            ds = dominfo._stateGet()            if ds not in (DOM_STATE_RUNNING, DOM_STATE_PAUSED, DOM_STATE_CRASHED):                raise VMBadState("Domain '%s' is not started" % domid,                                 POWER_STATE_NAMES[DOM_STATE_RUNNING],                                 POWER_STATE_NAMES[ds])            log.info("Domain %s (%d) paused.", dominfo.getName(),                     int(dominfo.getDomid()))            if ds == DOM_STATE_RUNNING:                dominfo.pause()            if state:                return ds        except XendInvalidDomain:            log.exception("domain_pause")            raise        except Exception, ex:            log.exception("domain_pause")            raise XendError(str(ex))    def domain_dump(self, domid, filename, live, crash):        """Dump domain core."""        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        if dominfo.getDomid() == DOM0_ID:            raise XendError("Cannot dump core for privileged domain %s" % domid)        if dominfo._stateGet() not in (DOM_STATE_PAUSED, DOM_STATE_RUNNING, DOM_STATE_CRASHED):            raise VMBadState("Domain '%s' is not started" % domid,                             POWER_STATE_NAMES[DOM_STATE_PAUSED],                             POWER_STATE_NAMES[dominfo._stateGet()])        try:            log.info("Domain core dump requested for domain %s (%d) "                     "live=%d crash=%d.",                     dominfo.getName(), dominfo.getDomid(), live, crash)            return dominfo.dumpCore(filename)        except Exception, ex:            raise XendError(str(ex))    def domain_destroy(self, domid):        """Terminate domain immediately.        @param domid: Domain ID or Name        @type domid: int or string.        @rtype: None        @raise XendError: Failed to destroy        @raise XendInvalidDomain: Domain is not valid                """        dominfo = self.domain_lookup_nr(domid)        if dominfo and dominfo.getDomid() == DOM0_ID:            raise XendError("Cannot destroy privileged domain %s" % domid)        if dominfo:            val = dominfo.destroy()        else:            try:                val = xc.domain_destroy(int(domid))            except ValueError:                raise XendInvalidDomain(domid)            except Exception, e:                raise XendError(str(e))        return val           def domain_migrate(self, domid, dst, live=False, port=0, node=-1, ssl=None):        """Start domain migration.                @param domid: Domain ID or Name        @type domid: int or string.        @param dst: Destination IP address        @type dst: string        @keyword live: Live migration        @type live: bool        @keyword port: relocation port on destination        @type port: int        @keyword node: use node number for target        @type node: int        @keyword ssl: use ssl connection        @type ssl: bool        @rtype: None        @raise XendError: Failed to migrate        @raise XendInvalidDomain: Domain is not valid        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        if dominfo.getDomid() == DOM0_ID:            raise XendError("Cannot migrate privileged domain %s" % domid)        if dominfo._stateGet() != DOM_STATE_RUNNING:            raise VMBadState("Domain is not running",                             POWER_STATE_NAMES[DOM_STATE_RUNNING],                             POWER_STATE_NAMES[dominfo._stateGet()])        """ The following call may raise a XendError exception """        dominfo.testMigrateDevices(True, dst)        if live:            """ Make sure there's memory free for enabling shadow mode """            dominfo.checkLiveMigrateMemory()        if ssl is None:            ssl = xoptions.get_xend_relocation_ssl()        if ssl:            from OpenSSL import SSL            from xen.web import connection            if port == 0:                port = xoptions.get_xend_relocation_ssl_port()            try:                ctx = SSL.Context(SSL.SSLv23_METHOD)                sock = SSL.Connection(ctx,                           socket.socket(socket.AF_INET, socket.SOCK_STREAM))                sock.set_connect_state()                sock.connect((dst, port))                sock.send("sslreceive\n")                sock.recv(80)            except SSL.Error, err:                raise XendError("SSL error: %s" % err)            except socket.error, err:                raise XendError("can't connect: %s" % err)            p2cread, p2cwrite = os.pipe()            threading.Thread(target=connection.SSLSocketServerConnection.fd2send,                             args=(sock, p2cread)).start()            try:                XendCheckpoint.save(p2cwrite, dominfo, True, live, dst,                                    node=node)            finally:                sock.shutdown()                sock.close()            os.close(p2cread)            os.close(p2cwrite)        else:            if port == 0:                port = xoptions.get_xend_relocation_port()            try:                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)                # When connecting to our ssl enabled relocation server using a                # plain socket, send will success but recv will block. Add a                # 30 seconds timeout to raise a socket.timeout exception to                # inform the client.                sock.settimeout(30.0)                sock.connect((dst, port))                sock.send("receive\n")                sock.recv(80)                sock.settimeout(None)            except socket.error, err:                raise XendError("can't connect: %s" % err)            try:                XendCheckpoint.save(sock.fileno(), dominfo, True, live,                                    dst, node=node)            finally:                sock.close()    def domain_save(self, domid, dst, checkpoint=False):        """Start saving a domain to file.        @param domid: Domain ID or Name        @type domid: int or string.        @param dst: Destination filename        @type dst: string        @rtype: None        @raise XendError: Failed to save domain        @raise XendInvalidDomain: Domain is not valid                """        try:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -