def __init__(self, **kwargs): """ Create a configuration object TODO: Provide a full list of settable values and thier defaults :param kwargs: (dict) configuration parameters """ # A few defaults self.name = 'SDNdbg.{}'.format(str(get_uuid())) self.seed_file = None self.logging_level = 'info' self.cache_client = False self.sites = [] self.type = 'Global' self.config = self self.config_parent = None # TODO: Support a global list of username/passwords... # Continue with loading of the configuration file. If not present, try to load from # environment variables config_file = kwargs.get('config_file') if config_file is not None: self._config_data = self._load_file(config_file) if 'sites' not in self._config_data: raise KeyError( "Unable to locate required key 'sites' in configuration file '{}'" .format(kwargs['config_file'])) else: self._config_data = Config._load_env_vars() self.sites = self._load_site(self._config_data['sites'])
def __init__(self, **kwargs): """ Create a configuration object TODO: Provide a full list of settable values and thier defaults :param kwargs: (dict) configuration parameters """ # A few defaults self.name = 'SDNdbg.{}'.format(str(get_uuid())) self.seed_file = None self.logging_level = 'info' self.cache_client = False self.sites = [] self.type = 'Global' self.config = self self.config_parent = None # TODO: Support a global list of username/passwords... # Continue with loading of the configuration file. If not present, try to load from # environment variables if 'config_file' in kwargs: self._config_data = self._load_file(kwargs['config_file']) if 'sites' not in self._config_data: raise KeyError("Unable to locate required key 'sites' in configuration file '{}'". format(kwargs['config_file'])) else: self._config_data = Config._load_env_vars() self.sites = self._load_site(self._config_data['sites'])
def _unzipfile(self, file, random=False): '''解压文件 解压格式:/a/b/filename-20160803.gz 解压为 /a/b/filename-20160803.log ''' g = gzip.GzipFile(mode='rb', fileobj=open(file, 'rb')) _pre = os.path.splitext(file)[0] if random: uuid = utils.get_uuid() tf = '{0}____{1}.log'.format(_pre, uuid) else: tf = '{0}.log'.format(_pre) #utils.delete_files(os.path.split(tf)[0]) #删除当前目录下所有的*.log文件 if os.path.isfile(tf): os.remove(tf) open(tf, "wb").write(g.read())
def __init__(self, config_data, parent): self.type = 'ONOS' self.config = self self.config_parent = parent self.name = config_data.get('name', '{}.ONOS.{}'.format(parent.name, str(get_uuid()))) self.seed_file = config_data.get('seed-file', parent.seed_file) self.logging_level = config_data.get('logging-level', parent.logging_level) self.cache_client = config_data.get('cache-client', parent.cache_client) base_module_name = __name__[:-len(path.splitext(path.basename(__file__))[0]) - 1] logging.getLogger(base_module_name).setLevel(levelname_to_level(self.logging_level)) self.address = config_data.get('address') self.username = config_data.get('username', 'onos') self.password = config_data.get('password', 'rocks') self.port = config_data.get('port')
def __init__(self, config_data, parent): self.type = 'OpenStack' self.config = self self.config_parent = parent self.name = config_data.get('name', '{}OpenStack.{}'.format(parent.name, str(get_uuid()))) self.seed_file = config_data.get('seed-file', parent.seed_file) self.logging_level = config_data.get('logging-level', parent.logging_level) self.cache_client = config_data.get('cache-client', parent.cache_client) base_module_name = __name__[:-len(path.splitext(path.basename(__file__))[0]) - 1] logging.getLogger(base_module_name).setLevel(levelname_to_level(self.logging_level)) self.auth_url = config_data.get('OS_AUTH_URL') self.username = config_data.get('OS_USERNAME') self.password = config_data.get('OS_PASSWORD') self.project = config_data.get('OS_PROJECT_NAME') self.region_name = config_data.get('OS_REGION_NAME') self.user_domain_name = config_data.get('OS_USER_DOMAIN_NAME') self.project_domain_name = config_data.get('OS_PROJECT_DOMAIN_NAME') self.certificate_path = config_data.get('OS_CA_PATH')