def __init__(self, sys_cfg, distro, paths): super(DataSourceOpenStack, self).__init__(sys_cfg, distro, paths) self.metadata_address = None self.ssl_details = util.fetch_ssl_details(self.paths) self.version = None self.files = {} self.ec2_metadata = None
def __init__( self, endpoint, consumer_key=None, token_key=None, token_secret=None, consumer_secret=None, timeout=None, retries=None, ): super(WebHookHandler, self).__init__() if any([consumer_key, token_key, token_secret, consumer_secret]): oauth_helper = url_helper.OauthUrlHelper( consumer_key=consumer_key, token_key=token_key, token_secret=token_secret, consumer_secret=consumer_secret, ) self.readurl = oauth_helper.readurl else: self.readurl = url_helper.readurl self.endpoint = endpoint self.timeout = timeout self.retries = retries self.ssl_details = util.fetch_ssl_details() self.flush_requested = Event() self.queue = queue.Queue() self.event_processor = threading.Thread(target=self.process_requests) self.event_processor.daemon = True self.event_processor.start()
def __init__( self, endpoint, consumer_key=None, token_key=None, token_secret=None, consumer_secret=None, timeout=None, retries=None, ): super(WebHookHandler, self).__init__() if any([consumer_key, token_key, token_secret, consumer_secret]): self.oauth_helper = url_helper.OauthUrlHelper( consumer_key=consumer_key, token_key=token_key, token_secret=token_secret, consumer_secret=consumer_secret, ) else: self.oauth_helper = None self.endpoint = endpoint self.timeout = timeout self.retries = retries self.ssl_details = util.fetch_ssl_details()
def read_maas_seed_url(seed_url, header_cb=None, timeout=None, version=MD_VERSION, paths=None): """ Read the maas datasource at seed_url. - header_cb is a method that should return a headers dictionary for a given url Expected format of seed_url is are the following files: * <seed_url>/<version>/meta-data/instance-id * <seed_url>/<version>/meta-data/local-hostname * <seed_url>/<version>/user-data """ base_url = "%s/%s" % (seed_url, version) file_order = [ 'local-hostname', 'instance-id', 'public-keys', 'user-data', ] files = { 'local-hostname': "%s/%s" % (base_url, 'meta-data/local-hostname'), 'instance-id': "%s/%s" % (base_url, 'meta-data/instance-id'), 'public-keys': "%s/%s" % (base_url, 'meta-data/public-keys'), 'user-data': "%s/%s" % (base_url, 'user-data'), } md = {} for name in file_order: url = files.get(name) if not header_cb: def _cb(url): return {} header_cb = _cb if name == 'user-data': retries = 0 else: retries = None try: ssl_details = util.fetch_ssl_details(paths) resp = util.read_file_or_url(url, retries=retries, headers_cb=header_cb, timeout=timeout, ssl_details=ssl_details) if resp.ok(): md[name] = str(resp) else: LOG.warn(("Fetching from %s resulted in" " an invalid http code %s"), url, resp.code) except url_helper.UrlError as e: if e.code != 404: raise return check_seed_contents(md, seed_url)
def read_maas_seed_url(seed_url, read_file_or_url=None, timeout=None, version=MD_VERSION, paths=None, retries=None): """ Read the maas datasource at seed_url. read_file_or_url is a method that should provide an interface like util.read_file_or_url Expected format of seed_url is are the following files: * <seed_url>/<version>/meta-data/instance-id * <seed_url>/<version>/meta-data/local-hostname * <seed_url>/<version>/user-data """ base_url = "%s/%s" % (seed_url, version) file_order = [ 'local-hostname', 'instance-id', 'public-keys', 'user-data', ] files = { 'local-hostname': "%s/%s" % (base_url, 'meta-data/local-hostname'), 'instance-id': "%s/%s" % (base_url, 'meta-data/instance-id'), 'public-keys': "%s/%s" % (base_url, 'meta-data/public-keys'), 'user-data': "%s/%s" % (base_url, 'user-data'), } if read_file_or_url is None: read_file_or_url = util.read_file_or_url md = {} for name in file_order: url = files.get(name) if name == 'user-data': item_retries = 0 else: item_retries = retries try: ssl_details = util.fetch_ssl_details(paths) resp = read_file_or_url(url, retries=item_retries, timeout=timeout, ssl_details=ssl_details) if resp.ok(): if name in BINARY_FIELDS: md[name] = resp.contents else: md[name] = util.decode_binary(resp.contents) else: LOG.warn(("Fetching from %s resulted in" " an invalid http code %s"), url, resp.code) except url_helper.UrlError as e: if e.code != 404: raise return check_seed_contents(md, seed_url)
def read_maas_seed_url(seed_url, header_cb=None, timeout=None, version=MD_VERSION, paths=None): """ Read the maas datasource at seed_url. - header_cb is a method that should return a headers dictionary for a given url Expected format of seed_url is are the following files: * <seed_url>/<version>/meta-data/instance-id * <seed_url>/<version>/meta-data/local-hostname * <seed_url>/<version>/user-data """ base_url = "%s/%s" % (seed_url, version) file_order = [ 'local-hostname', 'instance-id', 'public-keys', 'user-data', ] files = { 'local-hostname': "%s/%s" % (base_url, 'meta-data/local-hostname'), 'instance-id': "%s/%s" % (base_url, 'meta-data/instance-id'), 'public-keys': "%s/%s" % (base_url, 'meta-data/public-keys'), 'user-data': "%s/%s" % (base_url, 'user-data'), } md = {} for name in file_order: url = files.get(name) if not header_cb: def _cb(url): return {} header_cb = _cb if name == 'user-data': retries = 0 else: retries = None try: ssl_details = util.fetch_ssl_details(paths) resp = util.read_file_or_url(url, retries=retries, headers_cb=header_cb, timeout=timeout, ssl_details=ssl_details) if resp.ok(): if name in BINARY_FIELDS: md[name] = resp.contents else: md[name] = util.decode_binary(resp.contents) else: LOG.warn(("Fetching from %s resulted in" " an invalid http code %s"), url, resp.code) except url_helper.UrlError as e: if e.code != 404: raise return check_seed_contents(md, seed_url)
def read_maas_seed_url( seed_url, read_file_or_url=None, timeout=None, version=MD_VERSION, paths=None, retries=None, ): """ Read the maas datasource at seed_url. read_file_or_url is a method that should provide an interface like util.read_file_or_url Expected format of seed_url is are the following files: * <seed_url>/<version>/meta-data/instance-id * <seed_url>/<version>/meta-data/local-hostname * <seed_url>/<version>/user-data If version is None, then <version>/ will not be used. """ if read_file_or_url is None: read_file_or_url = url_helper.read_file_or_url if seed_url.endswith("/"): seed_url = seed_url[:-1] md = {} for path, _dictname, binary, optional in DS_FIELDS: if version is None: url = "%s/%s" % (seed_url, path) else: url = "%s/%s/%s" % (seed_url, version, path) try: ssl_details = util.fetch_ssl_details(paths) resp = read_file_or_url(url, retries=retries, timeout=timeout, ssl_details=ssl_details) if resp.ok(): if binary: md[path] = resp.contents else: md[path] = util.decode_binary(resp.contents) else: LOG.warning( "Fetching from %s resulted in an invalid http code %s", url, resp.code, ) except url_helper.UrlError as e: if e.code == 404 and not optional: raise MAASSeedDirMalformed("Missing required %s: %s" % (path, e)) from e elif e.code != 404: raise e return check_seed_contents(md, seed_url)
def __init__(self, endpoint, consumer_key=None, token_key=None, token_secret=None, consumer_secret=None, timeout=None, retries=None): super(WebHookHandler, self).__init__() if any([consumer_key, token_key, token_secret, consumer_secret]): self.oauth_helper = url_helper.OauthUrlHelper( consumer_key=consumer_key, token_key=token_key, token_secret=token_secret, consumer_secret=consumer_secret) else: self.oauth_helper = None self.endpoint = endpoint self.timeout = timeout self.retries = retries self.ssl_details = util.fetch_ssl_details()
def read_maas_seed_url(seed_url, read_file_or_url=None, timeout=None, version=MD_VERSION, paths=None, retries=None): """ Read the maas datasource at seed_url. read_file_or_url is a method that should provide an interface like util.read_file_or_url Expected format of seed_url is are the following files: * <seed_url>/<version>/meta-data/instance-id * <seed_url>/<version>/meta-data/local-hostname * <seed_url>/<version>/user-data If version is None, then <version>/ will not be used. """ if read_file_or_url is None: read_file_or_url = url_helper.read_file_or_url if seed_url.endswith("/"): seed_url = seed_url[:-1] md = {} for path, _dictname, binary, optional in DS_FIELDS: if version is None: url = "%s/%s" % (seed_url, path) else: url = "%s/%s/%s" % (seed_url, version, path) try: ssl_details = util.fetch_ssl_details(paths) resp = read_file_or_url(url, retries=retries, timeout=timeout, ssl_details=ssl_details) if resp.ok(): if binary: md[path] = resp.contents else: md[path] = util.decode_binary(resp.contents) else: LOG.warning(("Fetching from %s resulted in" " an invalid http code %s"), url, resp.code) except url_helper.UrlError as e: if e.code == 404 and not optional: raise MAASSeedDirMalformed( "Missing required %s: %s" % (path, e)) elif e.code != 404: raise e return check_seed_contents(md, seed_url)
def __init__(self, paths): self.paths = paths self.ssl_details = util.fetch_ssl_details(paths)
def handle(name, cfg, cloud, log, args): if len(args) != 0: ph_cfg = util.read_conf(args[0]) else: if "phone_home" not in cfg: log.debug( "Skipping module named %s, " "no 'phone_home' configuration found", name, ) return ph_cfg = cfg["phone_home"] if "url" not in ph_cfg: log.warning( "Skipping module named %s, " "no 'url' found in 'phone_home' configuration", name, ) return url = ph_cfg["url"] post_list = ph_cfg.get("post", "all") tries = ph_cfg.get("tries") try: tries = int(tries) # type: ignore except ValueError: tries = 10 util.logexc( log, "Configuration entry 'tries' is not an integer, using %s instead", tries, ) if post_list == "all": post_list = POST_LIST_ALL all_keys = {} all_keys["instance_id"] = cloud.get_instance_id() all_keys["hostname"] = cloud.get_hostname() all_keys["fqdn"] = cloud.get_hostname(fqdn=True) pubkeys = { "pub_key_dsa": "/etc/ssh/ssh_host_dsa_key.pub", "pub_key_rsa": "/etc/ssh/ssh_host_rsa_key.pub", "pub_key_ecdsa": "/etc/ssh/ssh_host_ecdsa_key.pub", "pub_key_ed25519": "/etc/ssh/ssh_host_ed25519_key.pub", } for (n, path) in pubkeys.items(): try: all_keys[n] = util.load_file(path) except Exception: util.logexc(log, "%s: failed to open, can not phone home that data!", path) submit_keys = {} for k in post_list: if k in all_keys: submit_keys[k] = all_keys[k] else: submit_keys[k] = None log.warning( "Requested key %s from 'post'" " configuration list not available", k, ) # Get them read to be posted real_submit_keys = {} for (k, v) in submit_keys.items(): if v is None: real_submit_keys[k] = "N/A" else: real_submit_keys[k] = str(v) # Incase the url is parameterized url_params = { "INSTANCE_ID": all_keys["instance_id"], } url = templater.render_string(url, url_params) try: url_helper.read_file_or_url( url, data=real_submit_keys, retries=tries, sec_between=3, ssl_details=util.fetch_ssl_details(cloud.paths), ) except Exception: util.logexc(log, "Failed to post phone home data to %s in %s tries", url, tries)
def handle(name, cfg, cloud, log, args): if len(args) != 0: ph_cfg = util.read_conf(args[0]) else: if 'phone_home' not in cfg: log.debug(("Skipping module named %s, " "no 'phone_home' configuration found"), name) return ph_cfg = cfg['phone_home'] if 'url' not in ph_cfg: log.warn(("Skipping module named %s, " "no 'url' found in 'phone_home' configuration"), name) return url = ph_cfg['url'] post_list = ph_cfg.get('post', 'all') tries = ph_cfg.get('tries') try: tries = int(tries) except Exception: tries = 10 util.logexc( log, "Configuration entry 'tries' is not an integer, " "using %s instead", tries) if post_list == "all": post_list = POST_LIST_ALL all_keys = {} all_keys['instance_id'] = cloud.get_instance_id() all_keys['hostname'] = cloud.get_hostname() all_keys['fqdn'] = cloud.get_hostname(fqdn=True) pubkeys = { 'pub_key_dsa': '/etc/ssh/ssh_host_dsa_key.pub', 'pub_key_rsa': '/etc/ssh/ssh_host_rsa_key.pub', 'pub_key_ecdsa': '/etc/ssh/ssh_host_ecdsa_key.pub', } for (n, path) in pubkeys.items(): try: all_keys[n] = util.load_file(path) except Exception: util.logexc(log, "%s: failed to open, can not phone home that " "data!", path) submit_keys = {} for k in post_list: if k in all_keys: submit_keys[k] = all_keys[k] else: submit_keys[k] = None log.warn(("Requested key %s from 'post'" " configuration list not available"), k) # Get them read to be posted real_submit_keys = {} for (k, v) in submit_keys.items(): if v is None: real_submit_keys[k] = 'N/A' else: real_submit_keys[k] = str(v) # Incase the url is parameterized url_params = { 'INSTANCE_ID': all_keys['instance_id'], } url = templater.render_string(url, url_params) try: util.read_file_or_url(url, data=real_submit_keys, retries=tries, sec_between=3, ssl_details=util.fetch_ssl_details(cloud.paths)) except Exception: util.logexc(log, "Failed to post phone home data to %s in %s tries", url, tries)
def handle(name, cfg, cloud, log, args): if len(args) != 0: ph_cfg = util.read_conf(args[0]) else: if not 'phone_home' in cfg: log.debug(("Skipping module named %s, " "no 'phone_home' configuration found"), name) return ph_cfg = cfg['phone_home'] if 'url' not in ph_cfg: log.warn(("Skipping module named %s, " "no 'url' found in 'phone_home' configuration"), name) return url = ph_cfg['url'] post_list = ph_cfg.get('post', 'all') tries = ph_cfg.get('tries') try: tries = int(tries) except: tries = 10 util.logexc(log, "Configuration entry 'tries' is not an integer, " "using %s instead", tries) if post_list == "all": post_list = POST_LIST_ALL all_keys = {} all_keys['instance_id'] = cloud.get_instance_id() all_keys['hostname'] = cloud.get_hostname() pubkeys = { 'pub_key_dsa': '/etc/ssh/ssh_host_dsa_key.pub', 'pub_key_rsa': '/etc/ssh/ssh_host_rsa_key.pub', 'pub_key_ecdsa': '/etc/ssh/ssh_host_ecdsa_key.pub', } for (n, path) in pubkeys.iteritems(): try: all_keys[n] = util.load_file(path) except: util.logexc(log, "%s: failed to open, can not phone home that " "data!", path) submit_keys = {} for k in post_list: if k in all_keys: submit_keys[k] = all_keys[k] else: submit_keys[k] = None log.warn(("Requested key %s from 'post'" " configuration list not available"), k) # Get them read to be posted real_submit_keys = {} for (k, v) in submit_keys.iteritems(): if v is None: real_submit_keys[k] = 'N/A' else: real_submit_keys[k] = str(v) # Incase the url is parameterized url_params = { 'INSTANCE_ID': all_keys['instance_id'], } url = templater.render_string(url, url_params) try: util.read_file_or_url(url, data=real_submit_keys, retries=tries, sec_between=3, ssl_details=util.fetch_ssl_details(cloud.paths)) except: util.logexc(log, "Failed to post phone home data to %s in %s tries", url, tries)