How to use hostname_from_url method in localstack

Best Python code snippet using localstack_python

sls.py

Source:sls.py Github

copy

Full Screen

...32 logging.error(33 "'%s' returned status code %d" % (url, rsp.status_code))34 all_responses[url] = []35 return all_responses36# def hostname_from_url(url):37# m = re.match("http.://(\[.*\]).*", url)38# if m is not None:39# return m.group(1)40# m = re.match(".*//([^:/]+).*", url)41# if m is not None:42# return m.group(1)43# return "???"44def update_cached_mps(bootstrap_url, cache_filename):45 with open(cache_filename, "w") as f:46 f.write(json.dumps(load_services(bootstrap_url)))47def hostname_from_url(url):48 m = re.match(r'^(?P<scheme>http|https|tcp)://(?P<hostname>[^/]+).*', url)49 if m is None:50 return url51 m1 = re.match(r'^(.*):[^\[\]:]+$', m.group("hostname"))52 if m1:53 return m1.group(1)54 return m.group("hostname")55def load_mps(tool, cache_filename):56 _tool_name_equivalencies = {57 "owping": {"owping", "owamp"},58 "owamp": {"owping", "owamp"},59 }60 def _has_tool(tool_name, service):61 eqtools = _tool_name_equivalencies.get(tool_name, {tool_name})62 service_type = service.get("service-type", [])63 if "pscheduler" in service_type:64 pscheduler_tools = service.get("pscheduler-tools", [])65 if eqtools & set(pscheduler_tools):66 return True67 return False68 if eqtools & set(service_type):69 return True70 return False71 with open(cache_filename) as f:72 sls_cache = json.loads(f.read())73 for url in sls_cache.keys():74 for s in sls_cache[url]:75 if _has_tool(tool, s):76 service_locators = s.get("service-locator", [])77 service_names = s.get("service-name", [])78 if len(service_names) == 0:79 service_name = "???"80 else:81 service_name = service_names[0]82 communities = s.get("group-communities", [])83 for l in service_locators:84 yield {85 "name": service_name,86 "hostname": hostname_from_url(l),87 "communities": communities88 }89if __name__ == "__main__":90 from perfsonar_data_helper import default_settings91 logging.basicConfig(level=logging.DEBUG)92 update_cached_mps(93 default_settings.SLS_BOOTSTRAP_URL,94 default_settings.SLS_CACHE_FILENAME)95 mps = load_mps(96 "owping",97 default_settings.SLS_CACHE_FILENAME)...

Full Screen

Full Screen

nagios.py

Source:nagios.py Github

copy

Full Screen

1import socket2import json3from urllib.parse import urlparse4def generate_nagios_configuration(file: str, host: str):5 """read a json file6 Args:7 file (str): path of t8 """9 nagions_file = f'{host}.cfg'10 hostname_from_url = []11 with open(nagions_file, 'w', encoding='utf8') as nagios_f:12 nagios_f.write(add_host_definition(host))13 with open(file, 'r', encoding='utf8') as file_d:14 data = json.load(file_d)15 for entry in data:16 url = data[entry]['url']17 # extract the hostname from the url avoid duplicates in the nagios configuration18 hostname_url = url.split('/')[0]19 if hostname_url not in hostname_from_url:20 hostname_from_url.append(url)21 line = add_check_cert(hostname_url, host)22 nagios_f.write(line)23 line = add_http_service(host, entry, f'''https://{url}''')24 nagios_f.write(line)25def add_host_definition(hostname: str):26 return f"""27define host{{28 use linux-server29 host_name {hostname}30 alias {hostname}31 address {socket.gethostbyname(hostname)}32}}33"""34def add_http_service(server: str, domain: str, url: str):35 """create nagios service check36 Returns:37 str: the nagios service check38 """39 url = url.replace(' ', '')40 url = url.replace('\n', '')41 description = f'''Checking {url} running on {server}'''"".replace(42 '\n', ' ')43 check_command = f"check_http!{url}!{domain}".replace('\n', ' ')44 return f"""45define service {{46 use local-service,graphed-service47 host_name {server}48 service_description {description}49 check_command {check_command}50}}51 """52def add_check_cert(hostname, host):53 return f"""54define service {{55 use local-service,graphed-service ; Name of service template to use56 host_name {host} ; Host name57 service_description check {hostname} certificate58 check_command check_ssl_cert!{hostname}59}}...

Full Screen

Full Screen

esg_config.py

Source:esg_config.py Github

copy

Full Screen

...26 while dirpath.endswith("/"):27 dirpath = dirpath[:-1]28 roots.append((key, dirpath + "/"))29 return roots30 def hostname_from_url(self, url):31 return urlparse.urlparse(url).hostname32 def get_data_node(self):33 return self.hostname_from_url(self.get_thredds_url_root())34 def get_index_node(self):35 return self.hostname_from_url(self.cp.get("DEFAULT", 36 "hessian_service_url"))37 def get_thredds_root(self):38 return self.cp.get("DEFAULT", "thredds_root")39 def get_thredds_url_root(self):40 return self.cp.get("DEFAULT", "thredds_url")41 42 def get_db_url(self):43 return self.cp.get("DEFAULT", "dburl")44if __name__ == '__main__':45 conf = Config()46 print conf.get_dataset_roots()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful