-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathingress.py
More file actions
63 lines (52 loc) · 2.06 KB
/
ingress.py
File metadata and controls
63 lines (52 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from scheduler.exceptions import KubeHTTPException
from scheduler.resources import Resource
class Ingress(Resource):
short_name = 'ingress'
def get(self, name=None, **kwargs):
"""
Fetch a single Ingress or a list of Ingresses
"""
if name is not None:
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses/%s" % (name, name)
message = 'get Ingress ' + name
else:
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses" % name
message = 'get Ingresses'
response = self.http_get(url, params=self.query_params(**kwargs))
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, message)
return response
def create(self, ingress, namespace, hostname):
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses" % namespace
data = {
"kind": "Ingress",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": ingress
},
"spec": {
"rules": [
{"host": ingress + "." + hostname,
"http": {
"paths": [
{"path": "/",
"backend": {
"serviceName": ingress,
"servicePort": 80
}}
]
}
}
]
}
}
response = self.http_post(url, json=data)
if not response.status_code == 201:
raise KubeHTTPException(response, "create Ingress {}".format(namespace))
return response
def delete(self, namespace, ingress):
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses/%s" % (namespace, ingress)
response = self.http_delete(url)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, 'delete Ingress "{}"', namespace)
return response