def health_check_response1(self, request, full_url, headers): self.setup_class(request, full_url, headers) parsed_url = urlparse(full_url) method = request.method if method == "POST": json_body = xmltodict.parse(self.body)["CreateHealthCheckRequest"] caller_reference = json_body["CallerReference"] config = json_body["HealthCheckConfig"] health_check_args = { "ip_address": config.get("IPAddress"), "port": config.get("Port"), "type": config["Type"], "resource_path": config.get("ResourcePath"), "fqdn": config.get("FullyQualifiedDomainName"), "search_string": config.get("SearchString"), "request_interval": config.get("RequestInterval"), "failure_threshold": config.get("FailureThreshold"), "health_threshold": config.get("HealthThreshold"), "measure_latency": config.get("MeasureLatency"), "inverted": config.get("Inverted"), "disabled": config.get("Disabled"), "enable_sni": config.get("EnableSNI"), "children": config.get("ChildHealthChecks", {}).get("ChildHealthCheck"), "regions": config.get("Regions", {}).get("Region"), } health_check = route53_backend.create_health_check( caller_reference, health_check_args) template = Template(CREATE_HEALTH_CHECK_RESPONSE) return 201, headers, template.render(health_check=health_check, xmlns=XMLNS) elif method == "DELETE": health_check_id = parsed_url.path.split("/")[-1] route53_backend.delete_health_check(health_check_id) template = Template(DELETE_HEALTH_CHECK_RESPONSE) return 200, headers, template.render(xmlns=XMLNS) elif method == "GET": template = Template(LIST_HEALTH_CHECKS_RESPONSE) health_checks = route53_backend.list_health_checks() return ( 200, headers, template.render(health_checks=health_checks, xmlns=XMLNS), )
def get_or_delete_health_check(self, request, full_url, headers): parsed_url = urlparse(full_url) parts = parsed_url.path.strip("/").split("/") health_check_id = parts[-1] if request.method == "GET": health_check = route53_backend.health_checks.get(health_check_id) if not health_check: return 404, {}, "" result = """<GetHealthCheckResponse xmlns="{}">{}</GetHealthCheckResponse>""" result = result.format(XMLNS_ROUTE53, health_check.to_xml()).strip() return result if request.method == "DELETE": route53_backend.delete_health_check(health_check_id) return 200, headers, DELETE_HEALTH_CHECK_RESPONSE
def get_or_delete_health_check_response(self, request, full_url, headers): self.setup_class(request, full_url, headers) parsed_url = urlparse(full_url) method = request.method if method == "GET": health_check_id = parsed_url.path.split("/")[-1] health_check = route53_backend.get_health_check(health_check_id) template = Template(GET_HEALTH_CHECK_RESPONSE) return 200, headers, template.render(health_check=health_check) elif method == "DELETE": health_check_id = parsed_url.path.split("/")[-1] route53_backend.delete_health_check(health_check_id) template = Template(DELETE_HEALTH_CHECK_RESPONSE) return 200, headers, template.render(xmlns=XMLNS)
def health_check_response2(self, request, full_url, headers): self.setup_class(request, full_url, headers) parsed_url = urlparse(full_url) method = request.method health_check_id = parsed_url.path.split("/")[-1] if method == "GET": health_check = route53_backend.get_health_check(health_check_id) template = Template(GET_HEALTH_CHECK_RESPONSE) return 200, headers, template.render(health_check=health_check) elif method == "DELETE": route53_backend.delete_health_check(health_check_id) template = Template(DELETE_HEALTH_CHECK_RESPONSE) return 200, headers, template.render(xmlns=XMLNS) elif method == "POST": config = xmltodict.parse(self.body)["UpdateHealthCheckRequest"] health_check_args = { "ip_address": config.get("IPAddress"), "port": config.get("Port"), "resource_path": config.get("ResourcePath"), "fqdn": config.get("FullyQualifiedDomainName"), "search_string": config.get("SearchString"), "failure_threshold": config.get("FailureThreshold"), "health_threshold": config.get("HealthThreshold"), "inverted": config.get("Inverted"), "disabled": config.get("Disabled"), "enable_sni": config.get("EnableSNI"), "children": config.get("ChildHealthChecks", {}).get("ChildHealthCheck"), "regions": config.get("Regions", {}).get("Region"), } health_check = route53_backend.update_health_check( health_check_id, health_check_args) template = Template(UPDATE_HEALTH_CHECK_RESPONSE) return 200, headers, template.render(health_check=health_check)
def delete_health_check( self, context: RequestContext, health_check_id: HealthCheckId) -> DeleteHealthCheckResponse: health_check = route53_backend.delete_health_check(health_check_id) if not health_check: raise NoSuchHealthCheck( f"No health check exists with the specified ID {health_check_id}" ) return {}