Skip to content

Commit 2339376

Browse files
add login and out of oc
1 parent 9b2acf1 commit 2339376

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/codeflare_sdk/cluster/auth.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 openshift as oc
16+
17+
18+
class Authentication:
19+
20+
def login(self):
21+
pass
22+
23+
def logout(self):
24+
response = oc.invoke("logout")
25+
return response.out()
26+
27+
28+
class TokenAuthentication(Authentication):
29+
30+
def __init__(
31+
self,
32+
token: str= None,
33+
server: str = None,):
34+
35+
self.token = token
36+
self.server = server
37+
38+
39+
def login(self):
40+
token = self.token
41+
server = self.server
42+
response = oc.invoke("login",[f'--token={token}', f'--server={server}:6443'])
43+
return response.out()
44+
45+
46+
class PasswordUserAuthentication(Authentication):
47+
48+
def __init__(
49+
self,
50+
username: str= None,
51+
password: str = None,):
52+
53+
self.username = username
54+
self.password = password
55+
56+
def login(self):
57+
response = oc.login(self.username,
58+
self.password)
59+
return response.out()

src/codeflare_sdk/cluster/cluster.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def create_app_wrapper(self):
5050

5151
# creates a new cluster with the provided or default spec
5252
def up(self):
53+
self.config.auth.login()
5354
namespace = self.config.namespace
5455
with oc.project(namespace):
5556
oc.invoke("apply", ["-f", self.app_wrapper_yaml])
@@ -58,6 +59,7 @@ def down(self):
5859
namespace = self.config.namespace
5960
with oc.project(namespace):
6061
oc.invoke("delete", ["AppWrapper", self.app_wrapper_name])
62+
self.config.auth.logout()
6163

6264
def status(self, print_to_console=True):
6365
cluster = _ray_cluster_status(self.config.name, self.config.namespace)

src/codeflare_sdk/cluster/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
from dataclasses import dataclass, field
16+
from .auth import Authentication
1617
import pathlib
1718

1819
dir = pathlib.Path(__file__).parent.parent.resolve()
@@ -34,3 +35,5 @@ class ClusterConfiguration:
3435
instascale: bool = False
3536
envs: dict = field(default_factory=dict)
3637
image: str = "ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124"
38+
auth: Authentication = Authentication()
39+

0 commit comments

Comments
 (0)