comparison env/lib/python3.7/site-packages/boto/route53/healthcheck.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 # Copyright (c) 2014 Tellybug, Matt Millar
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21 #
22
23
24 """
25 From http://docs.aws.amazon.com/Route53/latest/APIReference/API_CreateHealthCheck.html
26
27 POST /2013-04-01/healthcheck HTTP/1.1
28
29 <?xml version="1.0" encoding="UTF-8"?>
30 <CreateHealthCheckRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
31 <CallerReference>unique description</CallerReference>
32 <HealthCheckConfig>
33 <IPAddress>IP address of the endpoint to check</IPAddress>
34 <Port>port on the endpoint to check</Port>
35 <Type>HTTP | HTTPS | HTTP_STR_MATCH | HTTPS_STR_MATCH | TCP</Type>
36 <ResourcePath>path of the file that
37 you want Amazon Route 53 to request</ResourcePath>
38 <FullyQualifiedDomainName>domain name of the
39 endpoint to check</FullyQualifiedDomainName>
40 <SearchString>if Type is HTTP_STR_MATCH or HTTPS_STR_MATCH,
41 the string to search for in the response body
42 from the specified resource</SearchString>
43 <RequestInterval>10 | 30</RequestInterval>
44 <FailureThreshold>integer between 1 and 10</FailureThreshold>
45 </HealthCheckConfig>
46 </CreateHealthCheckRequest>
47 """
48
49
50 class HealthCheck(object):
51
52 """An individual health check"""
53
54 POSTXMLBody = """
55 <HealthCheckConfig>
56 %(ip_addr_part)s
57 <Port>%(port)s</Port>
58 <Type>%(type)s</Type>
59 <ResourcePath>%(resource_path)s</ResourcePath>
60 %(fqdn_part)s
61 %(string_match_part)s
62 %(request_interval)s
63 <FailureThreshold>%(failure_threshold)s</FailureThreshold>
64 </HealthCheckConfig>
65 """
66
67 XMLIpAddrPart = """<IPAddress>%(ip_addr)s</IPAddress>"""
68
69 XMLFQDNPart = """<FullyQualifiedDomainName>%(fqdn)s</FullyQualifiedDomainName>"""
70
71 XMLStringMatchPart = """<SearchString>%(string_match)s</SearchString>"""
72
73 XMLRequestIntervalPart = """<RequestInterval>%(request_interval)d</RequestInterval>"""
74
75 valid_request_intervals = (10, 30)
76
77 def __init__(self, ip_addr, port, hc_type, resource_path, fqdn=None, string_match=None, request_interval=30, failure_threshold=3):
78 """
79 HealthCheck object
80
81 :type ip_addr: str
82 :param ip_addr: Optional IP Address
83
84 :type port: int
85 :param port: Port to check
86
87 :type hc_type: str
88 :param hc_type: One of HTTP | HTTPS | HTTP_STR_MATCH | HTTPS_STR_MATCH | TCP
89
90 :type resource_path: str
91 :param resource_path: Path to check
92
93 :type fqdn: str
94 :param fqdn: domain name of the endpoint to check
95
96 :type string_match: str
97 :param string_match: if hc_type is HTTP_STR_MATCH or HTTPS_STR_MATCH, the string to search for in the response body from the specified resource
98
99 :type request_interval: int
100 :param request_interval: The number of seconds between the time that Amazon Route 53 gets a response from your endpoint and the time that it sends the next health-check request.
101
102 :type failure_threshold: int
103 :param failure_threshold: The number of consecutive health checks that an endpoint must pass or fail for Amazon Route 53 to change the current status of the endpoint from unhealthy to healthy or vice versa.
104
105 """
106 self.ip_addr = ip_addr
107 self.port = port
108 self.hc_type = hc_type
109 self.resource_path = resource_path
110 self.fqdn = fqdn
111 self.string_match = string_match
112 self.failure_threshold = failure_threshold
113
114 if request_interval in self.valid_request_intervals:
115 self.request_interval = request_interval
116 else:
117 raise AttributeError(
118 "Valid values for request_interval are: %s" %
119 ",".join(str(i) for i in self.valid_request_intervals))
120
121 if failure_threshold < 1 or failure_threshold > 10:
122 raise AttributeError(
123 'Valid values for failure_threshold are 1 - 10.')
124
125 def to_xml(self):
126 params = {
127 'ip_addr_part': '',
128 'port': self.port,
129 'type': self.hc_type,
130 'resource_path': self.resource_path,
131 'fqdn_part': "",
132 'string_match_part': "",
133 'request_interval': (self.XMLRequestIntervalPart %
134 {'request_interval': self.request_interval}),
135 'failure_threshold': self.failure_threshold,
136 }
137 if self.fqdn is not None:
138 params['fqdn_part'] = self.XMLFQDNPart % {'fqdn': self.fqdn}
139
140 if self.ip_addr:
141 params['ip_addr_part'] = self.XMLIpAddrPart % {'ip_addr': self.ip_addr}
142
143 if self.string_match is not None:
144 params['string_match_part'] = self.XMLStringMatchPart % {'string_match': self.string_match}
145
146 return self.POSTXMLBody % params