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

📄 xenddomain.py

📁 xen虚拟机源代码安装包
💻 PY
📖 第 1 页 / 共 5 页
字号:
            dominfo = self.domain_lookup_nr(domid)            if not dominfo:                raise XendInvalidDomain(str(domid))            if dominfo.getDomid() == DOM0_ID:                raise XendError("Cannot save privileged domain %s" % str(domid))            if dominfo._stateGet() != DOM_STATE_RUNNING:                raise VMBadState("Domain is not running",                                 POWER_STATE_NAMES[DOM_STATE_RUNNING],                                 POWER_STATE_NAMES[dominfo._stateGet()])            oflags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC            if hasattr(os, "O_LARGEFILE"):                oflags |= os.O_LARGEFILE            fd = os.open(dst, oflags)            try:                XendCheckpoint.save(fd, dominfo, False, False, dst,                                    checkpoint=checkpoint)            except Exception, e:                os.close(fd)                raise e            os.close(fd)        except OSError, ex:            raise XendError("can't write guest state file %s: %s" %                            (dst, ex[1]))    def domain_pincpu(self, domid, vcpu, cpumap):        """Set which cpus vcpu can use        @param domid: Domain ID or Name        @type domid: int or string.        @param vcpu: vcpu to pin to        @type vcpu: int        @param cpumap:  string repr of usable cpus        @type cpumap: string        @rtype: 0        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        # if vcpu is keyword 'all', apply the cpumap to all vcpus        if str(vcpu).lower() == "all":            vcpus = range(0, int(dominfo.getVCpuCount()))        else:            vcpus = [ int(vcpu) ]               # set the same cpumask for all vcpus        rc = 0        cpus = dominfo.getCpus()        for v in vcpus:            try:                if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):                    rc = xc.vcpu_setaffinity(dominfo.getDomid(), v, cpumap)                cpus[v] = cpumap            except Exception, ex:                log.exception(ex)                raise XendError("Cannot pin vcpu: %d to cpu: %s - %s" % \                                (v, cpumap, str(ex)))        dominfo.setCpus(cpus)        self.managed_config_save(dominfo)        return rc    def domain_cpu_sedf_set(self, domid, period, slice_, latency, extratime,                            weight):        """Set Simple EDF scheduler parameters for a domain.        @param domid: Domain ID or Name        @type domid: int or string.        @rtype: 0        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        try:            return xc.sedf_domain_set(dominfo.getDomid(), period, slice_,                                      latency, extratime, weight)        except Exception, ex:            raise XendError(str(ex))    def domain_cpu_sedf_get(self, domid):        """Get Simple EDF scheduler parameters for a domain.        @param domid: Domain ID or Name        @type domid: int or string.        @rtype: SXP object        @return: The parameters for Simple EDF schedule for a domain.        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        try:            sedf_info = xc.sedf_domain_get(dominfo.getDomid())            # return sxpr            return ['sedf',                    ['domid',    sedf_info['domid']],                    ['period',    sedf_info['period']],                    ['slice',     sedf_info['slice']],                    ['latency',   sedf_info['latency']],                    ['extratime', sedf_info['extratime']],                    ['weight',    sedf_info['weight']]]        except Exception, ex:            raise XendError(str(ex))    def domain_shadow_control(self, domid, op):        """Shadow page control.                @param domid: Domain ID or Name        @type domid: int or string.        @param op: operation        @type op: int        @rtype: 0        """        dominfo = self.domain_lookup(domid)        try:            return xc.shadow_control(dominfo.getDomid(), op)        except Exception, ex:            raise XendError(str(ex))    def domain_shadow_mem_get(self, domid):        """Get shadow pagetable memory allocation.                @param domid: Domain ID or Name        @type domid: int or string.        @rtype: int        @return: shadow memory in MB        """        dominfo = self.domain_lookup(domid)        try:            return xc.shadow_mem_control(dominfo.getDomid())        except Exception, ex:            raise XendError(str(ex))    def domain_shadow_mem_set(self, domid, mb):        """Set shadow pagetable memory allocation.                @param domid: Domain ID or Name        @type domid: int or string.        @param mb: shadow memory to set in MB        @type: mb: int        @rtype: int        @return: shadow memory in MB        """        dominfo = self.domain_lookup(domid)        try:            return xc.shadow_mem_control(dominfo.getDomid(), mb=mb)        except Exception, ex:            raise XendError(str(ex))    def domain_sched_credit_get(self, domid):        """Get credit scheduler parameters for a domain.        @param domid: Domain ID or Name        @type domid: int or string.        @rtype: dict with keys 'weight' and 'cap'        @return: credit scheduler parameters        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))                if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):            try:                return xc.sched_credit_domain_get(dominfo.getDomid())            except Exception, ex:                raise XendError(str(ex))        else:            return {'weight' : dominfo.getWeight(),                    'cap'    : dominfo.getCap()}         def domain_sched_credit_set(self, domid, weight = None, cap = None):        """Set credit scheduler parameters for a domain.        @param domid: Domain ID or Name        @type domid: int or string.        @type weight: int        @type cap: int        @rtype: 0        """        set_weight = False        set_cap = False        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        try:            if weight is None:                weight = int(0)            elif weight < 1 or weight > 65535:                raise XendError("weight is out of range")            else:                set_weight = True            if cap is None:                cap = int(~0)            elif cap < 0 or cap > dominfo.getVCpuCount() * 100:                raise XendError("cap is out of range")            else:                set_cap = True            assert type(weight) == int            assert type(cap) == int            rc = 0            if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):                rc = xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap)            if rc == 0:                if set_weight:                    dominfo.setWeight(weight)                if set_cap:                    dominfo.setCap(cap)                self.managed_config_save(dominfo)            return rc        except Exception, ex:            log.exception(ex)            raise XendError(str(ex))    def domain_maxmem_set(self, domid, mem):        """Set the memory limit for a domain.        @param domid: Domain ID or Name        @type domid: int or string.        @param mem: memory limit (in MiB)        @type mem: int        @raise XendError: fail to set memory        @rtype: 0        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        dominfo.setMemoryMaximum(mem)    def domain_ioport_range_enable(self, domid, first, last):        """Enable access to a range of IO ports for a domain        @param first: first IO port        @param last: last IO port        @raise XendError: failed to set range        @rtype: 0        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        nr_ports = last - first + 1        try:            return xc.domain_ioport_permission(dominfo.getDomid(),                                               first_port = first,                                               nr_ports = nr_ports,                                               allow_access = 1)        except Exception, ex:            raise XendError(str(ex))    def domain_ioport_range_disable(self, domid, first, last):        """Disable access to a range of IO ports for a domain        @param first: first IO port        @param last: last IO port        @raise XendError: failed to set range        @rtype: 0        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        nr_ports = last - first + 1        try:            return xc.domain_ioport_permission(dominfo.getDomid(),                                               first_port = first,                                               nr_ports = nr_ports,                                               allow_access = 0)        except Exception, ex:            raise XendError(str(ex))    def domain_send_trigger(self, domid, trigger_name, vcpu = 0):        """Send trigger to a domain.        @param domid: Domain ID or Name        @type domid: int or string.        @param trigger_name: trigger type name        @type trigger_name: string        @param vcpu: VCPU to send trigger (default is 0)         @type vcpu: int        @raise XendError: failed to send trigger        @raise XendInvalidDomain: Domain is not valid                @rtype: 0        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        if dominfo._stateGet() not in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):            raise VMBadState("Domain '%s' is not started" % domid,                             POWER_STATE_NAMES[DOM_STATE_RUNNING],                             POWER_STATE_NAMES[dominfo._stateGet()])        if trigger_name.lower() in TRIGGER_TYPE.keys():             trigger = TRIGGER_TYPE[trigger_name.lower()]        else:            raise XendError("Invalid trigger: %s" % trigger_name)        if trigger == TRIGGER_S3RESUME:            xc.hvm_set_param(dominfo.getDomid(), HVM_PARAM_ACPI_S_STATE, 0)            return None        try:            return xc.domain_send_trigger(dominfo.getDomid(),                                          trigger,                                          vcpu)        except Exception, ex:            raise XendError(str(ex))    def domain_reset(self, domid):        """Terminate domain immediately, and then create domain.        @param domid: Domain ID or Name        @type domid: int or string.        @rtype: None        @raise XendError: Failed to destroy or create        @raise XendInvalidDomain: Domain is not valid        """        dominfo = self.domain_lookup_nr(domid)        if not dominfo:            raise XendInvalidDomain(str(domid))        if dominfo and dominfo.getDomid() == DOM0_ID:            raise XendError("Cannot reset privileged domain %s" % domid)        if dominfo._stateGet() not in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):            raise VMBadState("Domain '%s' is not started" % domid,                             POWER_STATE_NAMES[DOM_STATE_RUNNING],                             POWER_STATE_NAMES[dominfo._stateGet()])        try:            dominfo.resetDomain()        except Exception, ex:            raise XendError(str(ex))def instance():    """Singleton constructor. Use this instead of the class constructor.    """    global inst    try:        inst    except:        inst = XendDomain()        inst.init()    return inst

⌨️ 快捷键说明

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