-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpvc.py
More file actions
88 lines (81 loc) · 3.16 KB
/
pvc.py
File metadata and controls
88 lines (81 loc) · 3.16 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
from scheduler.resources import Resource
from scheduler.exceptions import KubeHTTPException
class PersistentVolumeClaim(Resource):
short_name = 'pvc'
@staticmethod
def manifest(namespace, name, version=None, **kwargs):
labels = {
'heritage': 'drycc',
}
data = {
"apiVersion": "v1",
"kind": "PersistentVolumeClaim",
"metadata": {
"name": name,
"namespace": namespace,
'labels': labels
},
"spec": {
"accessModes": [
"ReadWriteMany"
],
"resources": {
"requests": {
"storage": kwargs.get('size')
},
},
"storageClassName": kwargs.get("storage_class"),
"volumeMode": "Filesystem",
}
}
if version:
data["metadata"]["resourceVersion"] = version
return data
def get(self, namespace, name=None):
"""
Fetch a single persistentvolumeclaim or a list of persistentvolumeclaim
"""
if name is not None:
url = self.api('/namespaces/{}/persistentvolumeclaims/{}',
namespace, name)
message = 'get persistentvolumeclaim ' + name
else:
url = self.api('/namespaces/{}/persistentvolumeclaims', namespace)
message = 'get persistentvolumeclaims'
response = self.http_get(url)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response, message)
return response
def create(self, namespace, name, **kwargs):
"""
Create persistentvolumeclaim
"""
url = self.api('/namespaces/{}/persistentvolumeclaims', namespace)
data = self.manifest(namespace, name, **kwargs)
response = self.http_post(url, json=data)
if not response.status_code == 201:
raise KubeHTTPException(
response,
"create persistentvolumeclaim {}".format(namespace))
return response
def patch(self, namespace, name, **kwargs):
url = self.api('/namespaces/{}/persistentvolumeclaims/{}', namespace,
name)
data = self.manifest(namespace, name, **kwargs)
response = self.http_patch(url, json=data, headers={"Content-Type": "application/merge-patch+json"}) # noqa
if self.unhealthy(response.status_code):
self.log(namespace, 'template used: {}'.format(json.dumps(data, indent=4)), 'DEBUG') # noqa
raise KubeHTTPException(response, 'update persistentvolumeclaims "{}"', name)
return response
def delete(self, namespace, name):
"""
Delete persistentvolumeclaim
"""
url = self.api('/namespaces/{}/persistentvolumeclaims/{}', namespace,
name)
response = self.http_delete(url)
if self.unhealthy(response.status_code):
raise KubeHTTPException(response,
'delete persistentvolumeclaim ' + name)
return response