File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
src/codeflare_sdk/cluster Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright 2022 IBM, Red Hat
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import abc
16
+ import openshift as oc
17
+
18
+
19
+ class Authentication (metaclass = abc .ABCMeta ):
20
+ def login (self ):
21
+ pass
22
+
23
+ def logout (self ):
24
+ pass
25
+
26
+
27
+ class TokenAuthentication (Authentication ):
28
+ def __init__ (
29
+ self ,
30
+ token : str = None ,
31
+ server : str = None ,
32
+ ):
33
+
34
+ self .token = token
35
+ self .server = server
36
+
37
+ def login (self ):
38
+ token = self .token
39
+ server = self .server
40
+ response = oc .invoke ("login" , [f"--token={ token } " , f"--server={ server } :6443" ])
41
+ return response .out ()
42
+
43
+ def logout (self ):
44
+ response = oc .invoke ("logout" )
45
+ return response .out ()
46
+
47
+
48
+ class PasswordUserAuthentication (Authentication ):
49
+ def __init__ (
50
+ self ,
51
+ username : str = None ,
52
+ password : str = None ,
53
+ ):
54
+
55
+ self .username = username
56
+ self .password = password
57
+
58
+ def login (self ):
59
+ response = oc .login (self .username , self .password )
60
+ return response .out ()
61
+
62
+ def logout (self ):
63
+ response = oc .invoke ("logout" )
64
+ return response .out ()
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ def up(self):
94
94
Applies the AppWrapper yaml, pushing the resource request onto
95
95
the MCAD queue.
96
96
"""
97
+ self .config .auth .login ()
97
98
namespace = self .config .namespace
98
99
with oc .project (namespace ):
99
100
oc .invoke ("apply" , ["-f" , self .app_wrapper_yaml ])
@@ -106,6 +107,7 @@ def down(self):
106
107
namespace = self .config .namespace
107
108
with oc .project (namespace ):
108
109
oc .invoke ("delete" , ["AppWrapper" , self .app_wrapper_name ])
110
+ self .config .auth .logout ()
109
111
110
112
def status (self , print_to_console : bool = True ):
111
113
"""
Original file line number Diff line number Diff line change 19
19
"""
20
20
21
21
from dataclasses import dataclass , field
22
+ from .auth import Authentication
22
23
import pathlib
23
24
24
25
dir = pathlib .Path (__file__ ).parent .parent .resolve ()
@@ -46,3 +47,4 @@ class ClusterConfiguration:
46
47
instascale : bool = False
47
48
envs : dict = field (default_factory = dict )
48
49
image : str = "ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124"
50
+ auth : Authentication = Authentication ()
You can’t perform that action at this time.
0 commit comments