def load(config_path=None, config_files=None, state_path="~/.tcf", ignore_ssl=True): """Load the TCF Library configuration This is needed before you can access from your client program any other module. :param config_path: list of strings containing UNIX-style paths (DIR:DIR) to look for config files (conf_*.py) that will be loaded in alphabetical order. An empty path clears the current list. :param config_files: list of extra config files to load :param str state_path: (optional) path where to store state :param bool ignore_ssl: (optional) wether to ignore SSL verification or not (useful for self-signed certs) """ if not config_path: config_path = ["/etc/tcf:~/.tcf:.tcf"] if not config_files: config_files = [] if config_path != "": global path path = commonl.path_expand(config_path) logger.info("configuration path %s", path) commonl.config_import(path, re.compile("^conf[-_].*.py$")) for config_file in config_files: commonl.config_import_file(config_file, "__main__") if urls == []: logger.warning( "No server URLs available; please use --url or " "add to a conf_*.py in any of %s with:\n" "\n" " tcfl.config.url_add('https://URL:PORT', ssl_ignore = True)\n" "\n" % ":".join(config_path)) for _url in urls: # create target server objects url = _url[0] ssl_ignore = ignore_ssl or _url[1] if len(_url) > 2: aka = _url[2] else: aka = None ttb_client.rest_init(os.path.expanduser(state_path), url, ssl_ignore, aka)
def load(config_path = None, config_files = None, state_path = "~/.tcf", ignore_ssl = True): """Load the TCF Library configuration This is needed before you can access from your client program any other module. :param config_path: list of strings containing UNIX-style paths (DIR:DIR) to look for config files (conf_*.py) that will be loaded in alphabetical order. An empty path clears the current list. :param config_files: list of extra config files to load :param str state_path: (optional) path where to store state :param bool ignore_ssl: (optional) wether to ignore SSL verification or not (useful for self-signed certs) """ if not config_path: config_path = [ "/etc/tcf:~/.tcf:.tcf" ] if not config_files: config_files = [] if config_path != "": global path path = commonl.path_expand(config_path) logger.info("configuration path %s", path) commonl.config_import(path, re.compile("^conf[-_].*.py$")) for config_file in config_files: commonl.config_import_file(config_file, "__main__") if urls == []: logger.warning( "No broker URLs available; please use --url or " "add to a conf_*.py in any of %s with:\n" "\n" " tcfl.config.url_add('https://URL:PORT', ssl_ignore = True)\n" "\n" % ":".join(config_path)) for _url in urls: # create target broker objects url = _url[0] ssl_ignore = ignore_ssl or _url[1] if len(_url) > 2: aka = _url[2] else: aka = None ttb_client.rest_init(os.path.expanduser(state_path), url, ssl_ignore, aka)
help="only show what would it do") args = arg_parser.parse_args() logging.basicConfig(level=args.level, format="%(levelname)s: %(message)s") # # Read configuration and decide what to watch # _ttbd_hw_health_monitor_driver_rebind_path = \ commonl.ttbd_locate_helper("ttbd-hw-healthmonitor-driver-rebind.py", log = logging) logging.debug("Found helper %s", _ttbd_hw_health_monitor_driver_rebind_path) args.config_path = os.path.expanduser(args.config_path) if args.config_path != [""]: commonl.config_import([args.config_path], re.compile("^conf[-_].*.py$")) journal = systemd.journal.Reader() journal.log_level(systemd.journal.LOG_INFO) logging.debug("opened journal") systemd.daemon.notify("READY=1") journal.this_boot(args.bootid) journal.this_machine() logging.debug("journal: filtering for kernel messages") journal.add_match(_TRANSPORT="kernel") # We don't filter per-subsystem, because some of them messages (like # USB's cannot reset) are not bound to it poller = select.poll()
def load(config_path=None, config_files=None, state_dir=None, ignore_ssl=True): """ Load the TCF Library configuration :param config_path: list of strings containing UNIX-style paths (DIR:DIR), DIR;DIR on Windows, to look for config files (conf_*.py) that will be loaded in alphabetical order. An empty path clears the current list. :param config_files: list of extra config files to load :param str state_path: (optional) path where to store state :param bool ignore_ssl: (optional) wether to ignore SSL verification or not (useful for self-signed certs) """ if config_path == None: config_path = [ ".tcf", os.path.join(os.path.expanduser("~"), ".tcf"), ] + _install.sysconfig_paths global state_path if state_dir: state_path = state_dir else: state_path = os.path.join(os.path.expanduser("~"), ".tcf") if not config_files: config_files = [] global path _path = [] for i in config_path: if i == "": _path = [] else: _path.append(i) path = [i for i in reversed(_path)] global loaded_files logger.info("configuration path %s", path) commonl.config_import(path, re.compile("^conf[-_].*.py$"), imported_files=loaded_files, raise_on_fail=False) for config_file in config_files: commonl.config_import_file(config_file, "__main__") loaded_files.append(config_file) # this takes stuff in added by config files to tcfl.config.urls to # seed, stuff we saved on disk from previous runs or defaults to # hostname "ttbd" that is resovled tcfl.server_c.discover() for _, server in tcfl.server_c.servers.items( ): # create target server objects # COMPAT: old style ttb_client.rest_target_broker -> being # moved to tcfl.server_c rtb = ttb_client.rest_target_broker(os.path.expanduser(state_path), server.url, ignore_ssl=not server.ssl_verify, aka=server.aka, origin=server.origin) ttb_client.rest_target_brokers[server.parsed_url.geturl()] = rtb if not tcfl.ttb_client.rest_target_brokers: logger.warning( "No servers available; please use --url or " "add to a file called conf_ANYTHING.py in any of %s with:\n" "\n" " tcfl.config.url_add('https://URL:PORT', ssl_ignore = True)\n" "\n" % ":".join(config_path)) tcfl.msgid_c.cls_init()