-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlimits.py
More file actions
44 lines (39 loc) · 1.48 KB
/
limits.py
File metadata and controls
44 lines (39 loc) · 1.48 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
from scheduler.exceptions import KubeHTTPException
from scheduler.resources import Resource
class LimitRanges(Resource):
short_name = 'limits'
def get(self, namespace_name, name):
"""
Fetch a single LimitRanges
"""
url = '/namespaces/{}/limitranges/{}'.format(namespace_name, name)
message = 'get LimitRanges {} for namespace {}'.format(name, namespace_name)
url = self.api(url)
response = self.http_get(url)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, message)
return response
def create(self, namespace_name, name, **kwargs):
"""
Create resource LimitRanges for namespace
"""
url = self.api("/namespaces/{}/limitranges".format(namespace_name))
manifest = {
"apiVersion": "v1",
"kind": "LimitRange",
"metadata": {
"namespace": namespace_name,
"name": name,
'labels': {
'app': namespace_name,
'heritage': 'drycc'
},
},
'spec': kwargs.get('spec', {})
}
response = self.http_post(url, json=manifest)
if not response.status_code == 201:
raise KubeHTTPException(response,
"create LimitRanges {} for namespace {}".format(
name, namespace_name))
return response