def __init__(self, config=None, config_dir=None): """ must either pass config as a dict or vaping.config.Config or config_dir as a path to where the config dir is located """ self.joins = [] self._logger = None self.load_config(config, config_dir) self.validate_config_data(self.config.data) # configure vaping logging if "logging" in self.config: logging.config.dictConfig(self.config.get("logging")) self.plugin_context = PluginContext(self.config) # GET VAPING PART OF CONFIG vcfg = self.config.get("vaping", None) if not vcfg: vcfg = dict() # GET HOME_DIR PART OF CONFIG # get either home_dir from config, or use config_dir self.home_dir = vcfg.get("home_dir", None) if not self.home_dir: # self.home_dir = self.config.meta["config_dir"] self.home_dir = self.config["config_dir"] self.home_dir = os.path.abspath(self.home_dir) if not os.path.exists(self.home_dir): raise ValueError( f"home directory '{self.home_dir}' does not exist") if not os.access(self.home_dir, os.W_OK): raise ValueError( f"home directory '{self.home_dir}' is not writable") # change to home for working dir os.chdir(self.home_dir) # instantiate all defined plugins # TODO remove and let them lazy init? plugins = self.config.get("plugins", None) if not plugins: raise ValueError("no plugins specified") plugin.instantiate(self.config["plugins"], self.plugin_context) # check that probes don't name clash with plugins for probe in self.config.get("probes", []): if plugin.exists(probe["name"]): raise ValueError( "probes may not share names with plugins ({})".format( probe["name"])) self.pidname = vcfg.get("pidfile", "vaping.pid")
def __init__(self, config=None, config_dir=None): """ must either pass config as a dict or vaping.config.Config or config_dir as a path to where the config dir is located """ if config: if isinstance(config, dict): self.config = vaping.Config(data=config) else: if not config.meta: raise ValueError("config was not specified or empty") self.config = config elif config_dir: self.config = vaping.Config(read=config_dir) else: raise ValueError("config was not specified or empty") self.joins = [] self._logger = None self.plugin_context = PluginContext(self.config) vcfg = self.config.get('vaping', None) if not vcfg: vcfg = dict() # get either home_dir from config, or use config_dir self.home_dir = vcfg.get('home_dir', None) if not self.home_dir: self.home_dir = self.config.meta['config_dir'] if not os.path.exists(self.home_dir): raise ValueError("home directory '{}' does not exist".format( self.home_dir)) if not os.access(self.home_dir, os.W_OK): raise ValueError("home directory '{}' is not writable".format( self.home_dir)) # change to home for working dir os.chdir(self.home_dir) # instantiate all defined plugins # TODO remove and let them lazy init? plugins = self.config.get('plugins', None) if not plugins: raise ValueError('no plugins specified') plugin.instantiate(self.config['plugins'], self.plugin_context) # check that probes don't name clash with plugins for probe in self.config.get('probes', []): if plugin.exists(probe["name"]): raise ValueError( "probes may not share names with plugins ({})".format( probe["name"])) # TODO move to daemon pidname = vcfg.get('pidfile', 'vaping.pid') self.pidfile = pidfile.PidFile(pidname=pidname, piddir=self.home_dir)
def __init__(self, config=None, config_dir=None): """ must either pass config as a dict or vaping.config.Config or config_dir as a path to where the config dir is located """ if config: if isinstance(config, dict): self.config = vaping.Config(data=config) else: if not config.meta: raise ValueError("config was not specified or empty") self.config = config elif config_dir: self.config = vaping.Config(read=config_dir) else: raise ValueError("config was not specified or empty") self.joins = [] self._logger = None self.plugin_context = PluginContext(self.config) vcfg = self.config.get('vaping', None) if not vcfg: vcfg = dict() # get either home_dir from config, or use config_dir self.home_dir = vcfg.get('home_dir', None) if not self.home_dir: self.home_dir = self.config.meta['config_dir'] if not os.path.exists(self.home_dir): raise ValueError("home directory '{}' does not exist".format(self.home_dir)) if not os.access(self.home_dir, os.W_OK): raise ValueError("home directory '{}' is not writable".format(self.home_dir)) # change to home for working dir os.chdir(self.home_dir) # instantiate all defined plugins # TODO remove and let them lazy init? plugins = self.config.get('plugins', None) if not plugins: raise ValueError('no plugins specified') plugin.instantiate(self.config['plugins'], self.plugin_context) # check that probes don't name clash with plugins for probe in self.config.get('probes', []): if plugin.exists(probe["name"]): raise ValueError("probes may not share names with plugins ({})".format(probe["name"])) # TODO move to daemon pidname = vcfg.get('pidfile', 'vaping.pid') self.pidfile = pidfile.PidFile(pidname=pidname, piddir=self.home_dir)