@@ -51,9 +51,12 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1>
51
51
from os.path import isfile
52
52
import errno
53
53
import os
54
- import openshift as oc
55
54
import yaml
56
55
56
+ from kubernetes import client, config
57
+ from ..utils.kube_api_helpers import _kube_api_error_handling
58
+ from .auth import config_check, api_config_handler
59
+
57
60
58
61
class AWManager:
59
62
"""
@@ -71,10 +74,10 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1>
71
74
self.filename = filename
72
75
try:
73
76
with open(self.filename) as f:
74
- awyaml = yaml.load(f, Loader=yaml.FullLoader)
75
- assert awyaml["kind"] == "AppWrapper"
76
- self.name = awyaml["metadata"]["name"]
77
- self.namespace = awyaml["metadata"]["namespace"]
77
+ self. awyaml = yaml.load(f, Loader=yaml.FullLoader)
78
+ assert self. awyaml["kind"] == "AppWrapper"
79
+ self.name = self. awyaml["metadata"]["name"]
80
+ self.namespace = self. awyaml["metadata"]["namespace"]
78
81
except:
79
82
raise ValueError(
80
83
f"{filename } is not a correctly formatted AppWrapper yaml"
@@ -86,19 +89,17 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1>
86
89
Attempts to create the AppWrapper custom resource using the yaml file
87
90
"""
88
91
try:
89
- with oc.project(self.namespace):
90
- oc.invoke("create", ["-f", self.filename])
91
- except oc.OpenShiftPythonException as osp: # pragma: no cover
92
- error_msg = osp.result.err()
93
- if "Unauthorized" in error_msg or "Forbidden" in error_msg:
94
- raise PermissionError(
95
- "Action not permitted, have you put in correct/up-to-date auth credentials?"
96
- )
97
- elif "AlreadyExists" in error_msg:
98
- raise FileExistsError(
99
- f"An AppWrapper of the name {self.name} already exists in namespace {self.namespace}"
100
- )
101
- raise osp
92
+ config_check()
93
+ api_instance = client.CustomObjectsApi(api_config_handler())
94
+ api_instance.create_namespaced_custom_object(
95
+ group="mcad.ibm.com",
96
+ version="v1beta1",
97
+ namespace=self.namespace,
98
+ plural="appwrappers",
99
+ body=self.awyaml,
100
+ )
101
+ except Exception as e:
102
+ return _kube_api_error_handling(e)
102
103
103
104
self.submitted = True
104
105
print(f"AppWrapper {self.filename} submitted!")
@@ -113,25 +114,17 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1>
113
114
return
114
115
115
116
try:
116
- with oc.project(self.namespace):
117
- oc.invoke("delete", ["AppWrapper", self.name])
118
- except oc.OpenShiftPythonException as osp: # pragma: no cover
119
- error_msg = osp.result.err()
120
- if (
121
- 'the server doesn\'t have a resource type "AppWrapper"' in error_msg
122
- or "forbidden" in error_msg
123
- or "Unauthorized" in error_msg
124
- or "Missing or incomplete configuration" in error_msg
125
- ):
126
- raise PermissionError(
127
- "Action not permitted, have you put in correct/up-to-date auth credentials?"
128
- )
129
- elif "not found" in error_msg:
130
- self.submitted = False
131
- print("AppWrapper not found, was deleted in another manner")
132
- return
133
- else:
134
- raise osp
117
+ config_check()
118
+ api_instance = client.CustomObjectsApi(api_config_handler())
119
+ api_instance.delete_namespaced_custom_object(
120
+ group="mcad.ibm.com",
121
+ version="v1beta1",
122
+ namespace=self.namespace,
123
+ plural="appwrappers",
124
+ name=self.name,
125
+ )
126
+ except Exception as e:
127
+ return _kube_api_error_handling(e)
135
128
136
129
self.submitted = False
137
130
print(f"AppWrapper {self.name} removed!")</ code > </ pre >
@@ -175,10 +168,10 @@ <h2 class="section-title" id="header-classes">Classes</h2>
175
168
self.filename = filename
176
169
try:
177
170
with open(self.filename) as f:
178
- awyaml = yaml.load(f, Loader=yaml.FullLoader)
179
- assert awyaml["kind"] == "AppWrapper"
180
- self.name = awyaml["metadata"]["name"]
181
- self.namespace = awyaml["metadata"]["namespace"]
171
+ self. awyaml = yaml.load(f, Loader=yaml.FullLoader)
172
+ assert self. awyaml["kind"] == "AppWrapper"
173
+ self.name = self. awyaml["metadata"]["name"]
174
+ self.namespace = self. awyaml["metadata"]["namespace"]
182
175
except:
183
176
raise ValueError(
184
177
f"{filename } is not a correctly formatted AppWrapper yaml"
@@ -190,19 +183,17 @@ <h2 class="section-title" id="header-classes">Classes</h2>
190
183
Attempts to create the AppWrapper custom resource using the yaml file
191
184
"""
192
185
try:
193
- with oc.project(self.namespace):
194
- oc.invoke("create", ["-f", self.filename])
195
- except oc.OpenShiftPythonException as osp: # pragma: no cover
196
- error_msg = osp.result.err()
197
- if "Unauthorized" in error_msg or "Forbidden" in error_msg:
198
- raise PermissionError(
199
- "Action not permitted, have you put in correct/up-to-date auth credentials?"
200
- )
201
- elif "AlreadyExists" in error_msg:
202
- raise FileExistsError(
203
- f"An AppWrapper of the name {self.name} already exists in namespace {self.namespace}"
204
- )
205
- raise osp
186
+ config_check()
187
+ api_instance = client.CustomObjectsApi(api_config_handler())
188
+ api_instance.create_namespaced_custom_object(
189
+ group="mcad.ibm.com",
190
+ version="v1beta1",
191
+ namespace=self.namespace,
192
+ plural="appwrappers",
193
+ body=self.awyaml,
194
+ )
195
+ except Exception as e:
196
+ return _kube_api_error_handling(e)
206
197
207
198
self.submitted = True
208
199
print(f"AppWrapper {self.filename} submitted!")
@@ -217,25 +208,17 @@ <h2 class="section-title" id="header-classes">Classes</h2>
217
208
return
218
209
219
210
try:
220
- with oc.project(self.namespace):
221
- oc.invoke("delete", ["AppWrapper", self.name])
222
- except oc.OpenShiftPythonException as osp: # pragma: no cover
223
- error_msg = osp.result.err()
224
- if (
225
- 'the server doesn\'t have a resource type "AppWrapper"' in error_msg
226
- or "forbidden" in error_msg
227
- or "Unauthorized" in error_msg
228
- or "Missing or incomplete configuration" in error_msg
229
- ):
230
- raise PermissionError(
231
- "Action not permitted, have you put in correct/up-to-date auth credentials?"
232
- )
233
- elif "not found" in error_msg:
234
- self.submitted = False
235
- print("AppWrapper not found, was deleted in another manner")
236
- return
237
- else:
238
- raise osp
211
+ config_check()
212
+ api_instance = client.CustomObjectsApi(api_config_handler())
213
+ api_instance.delete_namespaced_custom_object(
214
+ group="mcad.ibm.com",
215
+ version="v1beta1",
216
+ namespace=self.namespace,
217
+ plural="appwrappers",
218
+ name=self.name,
219
+ )
220
+ except Exception as e:
221
+ return _kube_api_error_handling(e)
239
222
240
223
self.submitted = False
241
224
print(f"AppWrapper {self.name} removed!")</ code > </ pre >
@@ -262,25 +245,17 @@ <h3>Methods</h3>
262
245
return
263
246
264
247
try:
265
- with oc.project(self.namespace):
266
- oc.invoke("delete", ["AppWrapper", self.name])
267
- except oc.OpenShiftPythonException as osp: # pragma: no cover
268
- error_msg = osp.result.err()
269
- if (
270
- 'the server doesn\'t have a resource type "AppWrapper"' in error_msg
271
- or "forbidden" in error_msg
272
- or "Unauthorized" in error_msg
273
- or "Missing or incomplete configuration" in error_msg
274
- ):
275
- raise PermissionError(
276
- "Action not permitted, have you put in correct/up-to-date auth credentials?"
277
- )
278
- elif "not found" in error_msg:
279
- self.submitted = False
280
- print("AppWrapper not found, was deleted in another manner")
281
- return
282
- else:
283
- raise osp
248
+ config_check()
249
+ api_instance = client.CustomObjectsApi(api_config_handler())
250
+ api_instance.delete_namespaced_custom_object(
251
+ group="mcad.ibm.com",
252
+ version="v1beta1",
253
+ namespace=self.namespace,
254
+ plural="appwrappers",
255
+ name=self.name,
256
+ )
257
+ except Exception as e:
258
+ return _kube_api_error_handling(e)
284
259
285
260
self.submitted = False
286
261
print(f"AppWrapper {self.name} removed!")</ code > </ pre >
@@ -300,19 +275,17 @@ <h3>Methods</h3>
300
275
Attempts to create the AppWrapper custom resource using the yaml file
301
276
"""
302
277
try:
303
- with oc.project(self.namespace):
304
- oc.invoke("create", ["-f", self.filename])
305
- except oc.OpenShiftPythonException as osp: # pragma: no cover
306
- error_msg = osp.result.err()
307
- if "Unauthorized" in error_msg or "Forbidden" in error_msg:
308
- raise PermissionError(
309
- "Action not permitted, have you put in correct/up-to-date auth credentials?"
310
- )
311
- elif "AlreadyExists" in error_msg:
312
- raise FileExistsError(
313
- f"An AppWrapper of the name {self.name} already exists in namespace {self.namespace}"
314
- )
315
- raise osp
278
+ config_check()
279
+ api_instance = client.CustomObjectsApi(api_config_handler())
280
+ api_instance.create_namespaced_custom_object(
281
+ group="mcad.ibm.com",
282
+ version="v1beta1",
283
+ namespace=self.namespace,
284
+ plural="appwrappers",
285
+ body=self.awyaml,
286
+ )
287
+ except Exception as e:
288
+ return _kube_api_error_handling(e)
316
289
317
290
self.submitted = True
318
291
print(f"AppWrapper {self.filename} submitted!")</ code > </ pre >
0 commit comments