Skip to content

Commit f38e8f5

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

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/codeflare_sdk/cluster/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ class ClusterConfiguration:
3434
instascale: bool = False
3535
envs: dict = field(default_factory=dict)
3636
image: str = "ghcr.io/ibm-ai-foundation/base:ray1.13.0-py38-gpu-pytorch1.12.0cu116-20220826-202124"
37+
38+
@dataclass
39+
class OpenShiftConfiguration:
40+
token: str = "your OpenShift API token"
41+
server: str = "your OpenShift server"
42+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
from .config import OpenShiftConfiguration
17+
18+
19+
class OpenShiftCluster:
20+
def __init__(self, config: OpenShiftConfiguration):
21+
self.config = config
22+
23+
def login(self):
24+
token = self.config.token
25+
server = self.config.server
26+
response = oc.invoke("login",[f'--token={token}', f'--server={server}:6443'])
27+
return response.out()
28+
29+
def select_project(self, project_name: str):
30+
response = oc.invoke("project", [f"{project_name}"])
31+
return response.out()
32+
33+
def logout(self):
34+
response = oc.invoke("logout")
35+
return response.out()

0 commit comments

Comments
 (0)