xendoptions.py

来自「xen虚拟机源代码安装包」· Python 代码 · 共 485 行 · 第 1/2 页

PY
485
字号
        """Get the address xend listens at for its HTTP port.        This defaults to the empty string which allows all hosts to connect.        If this is set to 'localhost' only the localhost will be able to connect        to the HTTP port.        """        return self.get_config_string('xend-address', self.xend_address_default)    def get_xend_relocation_address(self):        """Get the address xend listens at for its relocation server port.        This defaults to the empty string which allows all hosts to connect.        If this is set to 'localhost' only the localhost will be able to connect        to the relocation port.        """        return self.get_config_string('xend-relocation-address', self.xend_relocation_address_default)    def get_xend_unix_server(self):        """Get the flag indicating whether xend should run a unix-domain server.        """        return self.get_config_bool("xend-unix-server", self.xend_unix_server_default)    def get_xend_unix_path(self):        """Get the path the xend unix-domain server listens at.        """        return self.get_config_string("xend-unix-path", self.xend_unix_path_default)    def get_xend_domains_path(self):        """ Get the path for persistent domain configuration storage        """        return self.get_config_string("xend-domains-path", self.xend_domains_path_default)    def get_xend_state_path(self):        """ Get the path for persistent domain configuration storage        """        return self.get_config_string("xend-state-path", self.xend_state_path_default)    def get_xend_storage_path(self):        """ Get the path for persistent domain configuration storage        """        return self.get_config_string("xend-storage-path", self.xend_storage_path_default)            def get_xend_security_path(self):        """ Get the path for security state        """        return self.get_config_string("xend-security-path", self.xend_security_path_default)    def get_network_script(self):        """@return the script used to alter the network configuration when        Xend starts and stops, or None if no such script is specified."""                s = self.get_config_string('network-script')        if s:            result = s.split(" ")            result[0] = os.path.join(self.network_script_dir, result[0])            return result        else:            return None    def get_external_migration_tool(self):        """@return the name of the tool to handle virtual TPM migration."""        return self.get_config_string('external-migration-tool', self.external_migration_tool_default)    def get_enable_dump(self):        return self.get_config_bool('enable-dump', 'no')    def get_vif_script(self):        return self.get_config_string('vif-script', self.vif_script)    def get_dom0_min_mem(self):        return self.get_config_int('dom0-min-mem', self.dom0_min_mem_default)    def get_enable_dom0_ballooning(self):        enable_dom0_ballooning_default = 'yes'        if self.get_dom0_min_mem() == 0:            enable_dom0_ballooning_default = 'no'        return self.get_config_bool('enable-dom0-ballooning',                                    enable_dom0_ballooning_default)    def get_dom0_vcpus(self):        return self.get_config_int('dom0-cpus', self.dom0_vcpus_default)    def get_console_limit(self):        return self.get_config_int('console-limit', 1024)    def get_vnclisten_address(self):        return self.get_config_string('vnc-listen', self.xend_vnc_listen_default)    def get_vncpasswd_default(self):        return self.get_config_string('vncpasswd',                                     self.vncpasswd_default)    def get_keymap(self):        return self.get_config_string('keymap', None)    def get_resource_label_change_script(self):        s = self.get_config_string('resource-label-change-script')        if s:            result = s.split(" ")            result[0] = os.path.join(osdep.scripts_dir, result[0])            return result        else:            return None    def get_vnc_tls(self):        return self.get_config_string('vnc-tls', self.xend_vnc_tls)    def get_vnc_x509_cert_dir(self):        return self.get_config_string('vnc-x509-cert-dir', self.xend_vnc_x509_cert_dir)    def get_vnc_x509_verify(self):        return self.get_config_string('vnc-x509-verify', self.xend_vnc_x509_verify)    def get_qemu_dm_logrotate_count(self):        return self.get_config_int("qemu-dm-logrotate-count",                                   self.qemu_dm_logrotate_count)class XendOptionsFile(XendOptions):    """Default path to the config file."""    config_default = "/etc/xen/xend-config.sxp"    """Environment variable used to override config_default."""    config_var     = "XEND_CONFIG"    def set_config(self):        """If the config file exists, read it. If not, ignore it.        The config file is a sequence of sxp forms.        """        self.config_path = os.getenv(self.config_var, self.config_default)        if os.path.exists(self.config_path):            try:                fin = file(self.config_path, 'rb')                try:                    config = sxp.parse(fin)                finally:                    fin.close()                if config is None:                    config = ['xend-config']                else:                    config.insert(0, 'xend-config')                self.config = config            except Exception, ex:                self._logError('Reading config file %s: %s',                               self.config_path, str(ex))                raise        else:            self._logError('Config file does not exist: %s',                           self.config_path)            self.config = ['xend-config']    def get_config_value(self, name, val=None):        """Get the value of an atomic configuration element.        @param name: element name        @param val:  default value (optional, defaults to None)        @return: value        """        return sxp.child_value(self.config, name, val=val)    def get_config_bool(self, name, val=None):        v = string.lower(str(self.get_config_value(name, val)))        if v in ['yes', 'y', '1', 'on',  'true',  't']:            return True        if v in ['no',  'n', '0', 'off', 'false', 'f']:            return False        raise XendError("invalid xend config %s: expected bool: %s" % (name, v))    def get_config_int(self, name, val=None):        v = self.get_config_value(name, val)        try:            return int(v)        except Exception:            raise XendError("invalid xend config %s: expected int: %s" % (name, v))    def get_config_string(self, name, val=None):        return self.get_config_value(name, val)    def get_xen_api_server(self):        """Get the Xen-API server configuration.        """        return self.get_config_value('xen-api-server',                                     self.xen_api_server_default)if os.uname()[0] == 'SunOS':    class XendOptionsSMF(XendOptions):        def set_config(self):            pass        def get_config_bool(self, name, val=None):            try:                return scf.get_bool(name)            except scf.error, e:                if e[0] == scf.SCF_ERROR_NOT_FOUND:                    if val in ['yes', 'y', '1', 'on',  'true',  't']:                        return True                    if val in ['no',  'n', '0', 'off', 'false', 'f']:                        return False                    return val                else:                    raise XendError("option %s: %s:%s" % (name, e[1], e[2]))        def get_config_int(self, name, val=None):            try:                return scf.get_int(name)            except scf.error, e:                if e[0] == scf.SCF_ERROR_NOT_FOUND:                    return val                else:                    raise XendError("option %s: %s:%s" % (name, e[1], e[2]))        def get_config_string(self, name, val=None):            try:                return scf.get_string(name)            except scf.error, e:                if e[0] == scf.SCF_ERROR_NOT_FOUND:                    return val                else:                    raise XendError("option %s: %s:%s" % (name, e[1], e[2]))        def get_xen_api_server(self):            # When the new server is a supported configuration, we should            # expand this.            return [["unix"]]def instance():    """Get an instance of XendOptions.    Use this instead of the constructor.    """    global inst    try:        inst    except:        if os.uname()[0] == 'SunOS':            inst = XendOptionsSMF()        else:            inst = XendOptionsFile()    return inst

⌨️ 快捷键说明

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