@@ -51,9 +51,12 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1>
5151from os.path import isfile
5252import errno
5353import os
54- import openshift as oc
5554import yaml
5655
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+
5760
5861class AWManager:
5962 """
@@ -71,10 +74,10 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1>
7174 self.filename = filename
7275 try:
7376 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"]
7881 except:
7982 raise ValueError(
8083 f"{filename } is not a correctly formatted AppWrapper yaml"
@@ -86,19 +89,17 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1>
8689 Attempts to create the AppWrapper custom resource using the yaml file
8790 """
8891 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)
102103
103104 self.submitted = True
104105 print(f"AppWrapper {self.filename} submitted!")
@@ -113,25 +114,17 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1>
113114 return
114115
115116 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)
135128
136129 self.submitted = False
137130 print(f"AppWrapper {self.name} removed!")</ code > </ pre >
@@ -175,10 +168,10 @@ <h2 class="section-title" id="header-classes">Classes</h2>
175168 self.filename = filename
176169 try:
177170 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"]
182175 except:
183176 raise ValueError(
184177 f"{filename } is not a correctly formatted AppWrapper yaml"
@@ -190,19 +183,17 @@ <h2 class="section-title" id="header-classes">Classes</h2>
190183 Attempts to create the AppWrapper custom resource using the yaml file
191184 """
192185 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)
206197
207198 self.submitted = True
208199 print(f"AppWrapper {self.filename} submitted!")
@@ -217,25 +208,17 @@ <h2 class="section-title" id="header-classes">Classes</h2>
217208 return
218209
219210 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)
239222
240223 self.submitted = False
241224 print(f"AppWrapper {self.name} removed!")</ code > </ pre >
@@ -262,25 +245,17 @@ <h3>Methods</h3>
262245 return
263246
264247 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)
284259
285260 self.submitted = False
286261 print(f"AppWrapper {self.name} removed!")</ code > </ pre >
@@ -300,19 +275,17 @@ <h3>Methods</h3>
300275 Attempts to create the AppWrapper custom resource using the yaml file
301276 """
302277 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)
316289
317290 self.submitted = True
318291 print(f"AppWrapper {self.filename} submitted!")</ code > </ pre >
0 commit comments