-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnamespace.py
More file actions
62 lines (50 loc) · 1.9 KB
/
namespace.py
File metadata and controls
62 lines (50 loc) · 1.9 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
from scheduler.exceptions import KubeHTTPException
from scheduler.resources import Resource
class Namespace(Resource):
short_name = 'ns'
def get(self, name=None, **kwargs):
"""
Fetch a single Namespace or a list
"""
url = '/namespaces'
args = []
if name is not None:
args.append(name)
url += '/{}'
message = 'get Namespace "{}"'
else:
message = 'get Namespaces'
url = self.api(url, *args)
response = self.http_get(url, params=self.query_params(**kwargs))
if self.unhealthy(response.status_code):
args.reverse() # error msg is in reverse order
raise KubeHTTPException(response, message, *args)
return response
def create(self, namespace):
url = self.api("/namespaces")
data = {
"kind": "Namespace",
"apiVersion": self.api_version,
"metadata": {
"name": namespace,
"labels": {
'heritage': 'drycc'
}
}
}
response = self.http_post(url, json=data)
if not response.status_code == 201:
raise KubeHTTPException(response, "create Namespace {}".format(namespace))
return response
def delete(self, namespace):
url = self.api("/namespaces/{}", namespace)
response = self.http_delete(url)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, 'delete Namespace "{}"', namespace)
return response
def events(self, namespace, **kwargs):
url = self.api("/namespaces/{}/events", namespace)
response = self.http_get(url, params=self.query_params(**kwargs))
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, "get Events in Namespace {}", namespace)
return response