|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8"> |
| 5 | +<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
| 6 | +<meta name="generator" content="pdoc 0.10.0" /> |
| 7 | +<title>codeflare_sdk.cluster.awload API documentation</title> |
| 8 | +<meta name="description" content="The awload sub-module contains the definition of the AWManager object, which handles |
| 9 | +submission and deletion of existing AppWrappers from a user's …" /> |
| 10 | +<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
| 11 | +<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
| 12 | +<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
| 13 | +<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
| 14 | +<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
| 15 | +<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
| 16 | +<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
| 17 | +<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
| 18 | +</head> |
| 19 | +<body> |
| 20 | +<main> |
| 21 | +<article id="content"> |
| 22 | +<header> |
| 23 | +<h1 class="title">Module <code>codeflare_sdk.cluster.awload</code></h1> |
| 24 | +</header> |
| 25 | +<section id="section-intro"> |
| 26 | +<p>The awload sub-module contains the definition of the AWManager object, which handles |
| 27 | +submission and deletion of existing AppWrappers from a user's file system.</p> |
| 28 | +<details class="source"> |
| 29 | +<summary> |
| 30 | +<span>Expand source code</span> |
| 31 | +</summary> |
| 32 | +<pre><code class="python"># Copyright 2022 IBM, Red Hat |
| 33 | +# |
| 34 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 35 | +# you may not use this file except in compliance with the License. |
| 36 | +# You may obtain a copy of the License at |
| 37 | +# |
| 38 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 39 | +# |
| 40 | +# Unless required by applicable law or agreed to in writing, software |
| 41 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 42 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 43 | +# See the License for the specific language governing permissions and |
| 44 | +# limitations under the License. |
| 45 | + |
| 46 | +""" |
| 47 | +The awload sub-module contains the definition of the AWManager object, which handles |
| 48 | +submission and deletion of existing AppWrappers from a user's file system. |
| 49 | +""" |
| 50 | + |
| 51 | +from os.path import isfile |
| 52 | +import errno |
| 53 | +import os |
| 54 | +import openshift as oc |
| 55 | +import yaml |
| 56 | + |
| 57 | + |
| 58 | +class AWManager: |
| 59 | + """ |
| 60 | + An object for submitting and removing existing AppWrapper yamls |
| 61 | + to be added to the MCAD queue. |
| 62 | + """ |
| 63 | + |
| 64 | + def __init__(self, filename: str) -> None: |
| 65 | + """ |
| 66 | + Create the AppWrapper Manager object by passing in an |
| 67 | + AppWrapper yaml file |
| 68 | + """ |
| 69 | + if not isfile(filename): |
| 70 | + raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename) |
| 71 | + self.filename = filename |
| 72 | + try: |
| 73 | + 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"] |
| 78 | + except: |
| 79 | + raise ValueError( |
| 80 | + f"{filename } is not a correctly formatted AppWrapper yaml" |
| 81 | + ) |
| 82 | + self.submitted = False |
| 83 | + |
| 84 | + def submit(self) -> None: |
| 85 | + """ |
| 86 | + Attempts to create the AppWrapper custom resource using the yaml file |
| 87 | + """ |
| 88 | + 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 |
| 102 | + |
| 103 | + self.submitted = True |
| 104 | + print(f"AppWrapper {self.filename} submitted!") |
| 105 | + |
| 106 | + def remove(self) -> None: |
| 107 | + """ |
| 108 | + Attempts to delete the AppWrapper custom resource matching the name in the yaml, |
| 109 | + if submitted by this manager. |
| 110 | + """ |
| 111 | + if not self.submitted: |
| 112 | + print("AppWrapper not submitted by this manager yet, nothing to remove") |
| 113 | + return |
| 114 | + |
| 115 | + 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 |
| 135 | + |
| 136 | + self.submitted = False |
| 137 | + print(f"AppWrapper {self.name} removed!")</code></pre> |
| 138 | +</details> |
| 139 | +</section> |
| 140 | +<section> |
| 141 | +</section> |
| 142 | +<section> |
| 143 | +</section> |
| 144 | +<section> |
| 145 | +</section> |
| 146 | +<section> |
| 147 | +<h2 class="section-title" id="header-classes">Classes</h2> |
| 148 | +<dl> |
| 149 | +<dt id="codeflare_sdk.cluster.awload.AWManager"><code class="flex name class"> |
| 150 | +<span>class <span class="ident">AWManager</span></span> |
| 151 | +<span>(</span><span>filename: str)</span> |
| 152 | +</code></dt> |
| 153 | +<dd> |
| 154 | +<div class="desc"><p>An object for submitting and removing existing AppWrapper yamls |
| 155 | +to be added to the MCAD queue.</p> |
| 156 | +<p>Create the AppWrapper Manager object by passing in an |
| 157 | +AppWrapper yaml file</p></div> |
| 158 | +<details class="source"> |
| 159 | +<summary> |
| 160 | +<span>Expand source code</span> |
| 161 | +</summary> |
| 162 | +<pre><code class="python">class AWManager: |
| 163 | + """ |
| 164 | + An object for submitting and removing existing AppWrapper yamls |
| 165 | + to be added to the MCAD queue. |
| 166 | + """ |
| 167 | + |
| 168 | + def __init__(self, filename: str) -> None: |
| 169 | + """ |
| 170 | + Create the AppWrapper Manager object by passing in an |
| 171 | + AppWrapper yaml file |
| 172 | + """ |
| 173 | + if not isfile(filename): |
| 174 | + raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename) |
| 175 | + self.filename = filename |
| 176 | + try: |
| 177 | + 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"] |
| 182 | + except: |
| 183 | + raise ValueError( |
| 184 | + f"{filename } is not a correctly formatted AppWrapper yaml" |
| 185 | + ) |
| 186 | + self.submitted = False |
| 187 | + |
| 188 | + def submit(self) -> None: |
| 189 | + """ |
| 190 | + Attempts to create the AppWrapper custom resource using the yaml file |
| 191 | + """ |
| 192 | + 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 |
| 206 | + |
| 207 | + self.submitted = True |
| 208 | + print(f"AppWrapper {self.filename} submitted!") |
| 209 | + |
| 210 | + def remove(self) -> None: |
| 211 | + """ |
| 212 | + Attempts to delete the AppWrapper custom resource matching the name in the yaml, |
| 213 | + if submitted by this manager. |
| 214 | + """ |
| 215 | + if not self.submitted: |
| 216 | + print("AppWrapper not submitted by this manager yet, nothing to remove") |
| 217 | + return |
| 218 | + |
| 219 | + 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 |
| 239 | + |
| 240 | + self.submitted = False |
| 241 | + print(f"AppWrapper {self.name} removed!")</code></pre> |
| 242 | +</details> |
| 243 | +<h3>Methods</h3> |
| 244 | +<dl> |
| 245 | +<dt id="codeflare_sdk.cluster.awload.AWManager.remove"><code class="name flex"> |
| 246 | +<span>def <span class="ident">remove</span></span>(<span>self) ‑> None</span> |
| 247 | +</code></dt> |
| 248 | +<dd> |
| 249 | +<div class="desc"><p>Attempts to delete the AppWrapper custom resource matching the name in the yaml, |
| 250 | +if submitted by this manager.</p></div> |
| 251 | +<details class="source"> |
| 252 | +<summary> |
| 253 | +<span>Expand source code</span> |
| 254 | +</summary> |
| 255 | +<pre><code class="python">def remove(self) -> None: |
| 256 | + """ |
| 257 | + Attempts to delete the AppWrapper custom resource matching the name in the yaml, |
| 258 | + if submitted by this manager. |
| 259 | + """ |
| 260 | + if not self.submitted: |
| 261 | + print("AppWrapper not submitted by this manager yet, nothing to remove") |
| 262 | + return |
| 263 | + |
| 264 | + 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 |
| 284 | + |
| 285 | + self.submitted = False |
| 286 | + print(f"AppWrapper {self.name} removed!")</code></pre> |
| 287 | +</details> |
| 288 | +</dd> |
| 289 | +<dt id="codeflare_sdk.cluster.awload.AWManager.submit"><code class="name flex"> |
| 290 | +<span>def <span class="ident">submit</span></span>(<span>self) ‑> None</span> |
| 291 | +</code></dt> |
| 292 | +<dd> |
| 293 | +<div class="desc"><p>Attempts to create the AppWrapper custom resource using the yaml file</p></div> |
| 294 | +<details class="source"> |
| 295 | +<summary> |
| 296 | +<span>Expand source code</span> |
| 297 | +</summary> |
| 298 | +<pre><code class="python">def submit(self) -> None: |
| 299 | + """ |
| 300 | + Attempts to create the AppWrapper custom resource using the yaml file |
| 301 | + """ |
| 302 | + 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 |
| 316 | + |
| 317 | + self.submitted = True |
| 318 | + print(f"AppWrapper {self.filename} submitted!")</code></pre> |
| 319 | +</details> |
| 320 | +</dd> |
| 321 | +</dl> |
| 322 | +</dd> |
| 323 | +</dl> |
| 324 | +</section> |
| 325 | +</article> |
| 326 | +<nav id="sidebar"> |
| 327 | +<h1>Index</h1> |
| 328 | +<div class="toc"> |
| 329 | +<ul></ul> |
| 330 | +</div> |
| 331 | +<ul id="index"> |
| 332 | +<li><h3>Super-module</h3> |
| 333 | +<ul> |
| 334 | +<li><code><a title="codeflare_sdk.cluster" href="index.html">codeflare_sdk.cluster</a></code></li> |
| 335 | +</ul> |
| 336 | +</li> |
| 337 | +<li><h3><a href="#header-classes">Classes</a></h3> |
| 338 | +<ul> |
| 339 | +<li> |
| 340 | +<h4><code><a title="codeflare_sdk.cluster.awload.AWManager" href="#codeflare_sdk.cluster.awload.AWManager">AWManager</a></code></h4> |
| 341 | +<ul class=""> |
| 342 | +<li><code><a title="codeflare_sdk.cluster.awload.AWManager.remove" href="#codeflare_sdk.cluster.awload.AWManager.remove">remove</a></code></li> |
| 343 | +<li><code><a title="codeflare_sdk.cluster.awload.AWManager.submit" href="#codeflare_sdk.cluster.awload.AWManager.submit">submit</a></code></li> |
| 344 | +</ul> |
| 345 | +</li> |
| 346 | +</ul> |
| 347 | +</li> |
| 348 | +</ul> |
| 349 | +</nav> |
| 350 | +</main> |
| 351 | +<footer id="footer"> |
| 352 | +<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
| 353 | +</footer> |
| 354 | +</body> |
| 355 | +</html> |
0 commit comments