Skip to content

Commit 07cbabc

Browse files
committed
installation working
1 parent 9b4c221 commit 07cbabc

14 files changed

+202
-103
lines changed

script.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
from utils.configurations import loadConfigurations
33
from utils.pull_secret_util import get_pull_secret
44
from utils.first_run import isFirstRun, performFirstRun
5-
from utils.prompts import welcomeMessage, mainMenuPrompt, selectClusterPrompt
5+
from utils.prompts import welcomeMessage, mainMenuPrompt, selectClusterPrompt, localClustersPrompt
66
from utils.setupCluster import setupCluster
77
from utils.ClusterInquirer import ClusterInquirer
88
from utils.dateHandler import getAvailableClusters
9-
10-
'''
11-
Tell the user that we are gonna setup a config file
12-
'''
9+
from utils.run_ocs_install import LocalClusterHandler
1310

1411
class Manager:
1512
def __init__(self):
@@ -18,29 +15,48 @@ def __init__(self):
1815
performFirstRun()
1916
self.configurations = loadConfigurations()
2017
self.clusterInquirer = ClusterInquirer(self.configurations)
18+
self.LocalClusterHandler = LocalClusterHandler(self.clusterInquirer.getManager(),
19+
self.configurations)
2120

2221

23-
def setupCluster(self,selected):
24-
self.clusterInquirer.setupKube(selected)
22+
def setupCluster(self,selected, local=False):
23+
if not local:
24+
self.clusterInquirer.setupKube(selected)
25+
else:
26+
self.clusterInquirer.setupLocalKube(selected)
2527

2628
def createCluster(self):
27-
pass
29+
self.LocalClusterHandler.startInstallation()
2830

2931
def getClustersStatus(self):
3032
return self.clusterInquirer.getStatus()
3133

3234
if __name__ == '__main__':
3335
#Declare a variable to maintain a program loop
3436
manager = Manager()
37+
showLocalClusters = False
3538
while True:
36-
choice = mainMenuPrompt()
39+
localClusters = manager.LocalClusterHandler.getLocalUsableClusters()
40+
if len(localClusters) > 0 :
41+
showLocalClusters=True
42+
choice = mainMenuPrompt(showLocalClusters)
43+
#List available clusters
3744
if choice == 0:
45+
#Get all clusters
3846
clusters = manager.getClustersStatus()
3947
healthyClusters = getAvailableClusters(clusters)
4048
selectedCluster = selectClusterPrompt( healthyClusters )
4149
manager.setupCluster(selectedCluster)
50+
print("The selected cluster has been setup")
51+
# Create new cluster
4252
if choice == 1:
43-
#Create a new cluster
4453
manager.createCluster()
54+
#Show local clusters
4555
if choice == 2:
56+
#Selected cluster is the path to cluster
57+
selectedCluster = localClustersPrompt(localClusters)
58+
manager.setupCluster(selectedCluster, local=True)
59+
print("Local cluster is setup!")
60+
# Quit
61+
if choice == 3:
4662
break

utils/ClusterInquirer.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,19 @@ def setupKube(self, status):
2424
kubeconfig = self.manager.getExternalFile(owner,"kubeconfig")
2525
kubeadm = self.manager.getExternalFile(owner,"kubeadmin-password")
2626
writeKube(kubeconfig)
27-
writeKubePass(kubeadm)
27+
writeKubePass(kubeadm)
28+
29+
def setupLocalKube(self, path):
30+
authDir = os.path.join(path, 'auth')
31+
kubeconfig = ''
32+
kubeadmin_password = ''
33+
with open( os.path.join(authDir, 'kubeconfig'), 'rb') as file:
34+
kubeconfig = file.read()
35+
with open( os.path.join(authDir, 'kubeadmin-password'), 'rb') as file:
36+
kubeadmin_password = file.read()
37+
writeKube(kubeconfig)
38+
writeKubePass(kubeadmin_password)
39+
40+
41+
def getManager(self):
42+
return self.manager
6 Bytes
Binary file not shown.
59 Bytes
Binary file not shown.
53 Bytes
Binary file not shown.
921 Bytes
Binary file not shown.
1.83 KB
Binary file not shown.

utils/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
HOME_DIR_PATH = os.getenv('HOME')
44
OCS_DIR_PATH = os.path.join(HOME_DIR_PATH, '.ocs_data')
55
OCS_CONFIG_FILE = os.path.join(OCS_DIR_PATH, 'config')
6-
OCS_INSTALL_PATH = os.path.join(HOME_DIR_PATH, 'ocs-install')
6+
OCS_INSTALL_PATH = os.path.join(HOME_DIR_PATH, 'openshift-install')
77
OCS_CLUSTERS_PATH = os.path.join(OCS_DIR_PATH, 'clusters')
88
KUBE_PATH = os.path.join(HOME_DIR_PATH, 'awskube')
99

utils/first_run.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from utils.consts import OCS_DIR_PATH, KUBE_PATH, HOME_DIR_PATH
2+
from utils.consts import OCS_DIR_PATH, KUBE_PATH, HOME_DIR_PATH, OCS_CLUSTERS_PATH
33
from utils.configurations import DEFAULT_CONFIG, writeConfigurations
44
from utils.prompts import getGitInformation, teamGitIdPrompt
55

@@ -12,22 +12,25 @@ def isFirstRun():
1212
def performFirstRun():
1313
setupDirectories()
1414
setupKubeconfig()
15-
username, password = getGitInformation()
15+
username, password, enc_key = getGitInformation()
1616
userList = teamGitIdPrompt()
17-
setupConfigurations( username, password, userList)
17+
setupConfigurations( username, password, userList, enc_key)
1818

19-
def setupConfigurations(gitUsername, gitPassword, userList):
19+
def setupConfigurations(gitUsername, gitPassword, userList, enc_key):
2020
config = DEFAULT_CONFIG
2121
config['username'] = gitUsername
2222
config['password'] = gitPassword
2323
config['friends_git_id'] = userList
24+
config['team_enc_key'] = enc_key
2425
writeConfigurations(config)
2526

2627
def setupDirectories():
2728
if not os.path.exists(OCS_DIR_PATH):
2829
os.mkdir(OCS_DIR_PATH)
2930
if not os.path.exists(KUBE_PATH):
3031
os.mkdir(KUBE_PATH)
32+
if not os.path.exists(OCS_CLUSTERS_PATH):
33+
os.mkdir(OCS_CLUSTERS_PATH)
3134

3235
def setupKubeconfig():
3336
line = "export KUBECONFIG=" + KUBE_PATH + "/kubeconfig"

utils/gitHelper.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from git import Repo, GitCommandError
21
from utils.consts import REPO_NAME
3-
from datetime import date
4-
import os
5-
from utils.utils import repo_name_from_url
6-
from shutil import copyfile
72
from github import Github
3+
import json
4+
from utils.security import decryptByte
85

96

107

@@ -15,28 +12,27 @@ def __init__( self, username, password):
1512

1613

1714
class ExternRepository(Repository):
18-
19-
def __init__(self, username, password, externalUser):
15+
def __init__(self, username, password, externalUser, teamEncKey):
2016
super(ExternRepository,self).__init__(username, password)
2117
repo_name = externalUser + "/" + REPO_NAME
2218
self.repo = self.gitUser.get_repo(repo_name)
19+
self.teamEncKey = teamEncKey
2320

2421
def getStatus(self):
2522
status = self.repo.get_contents("status.json")
2623
return status.decoded_content
2724

2825
def getFile(self, fileName):
2926
contents = self.repo.get_contents(fileName)
30-
return contents.decoded_content
27+
return decryptByte(self.teamEncKey, contents.decoded_content)
3128

3229
def getOwner(self):
3330
return (self.repo.owner).login
3431

3532
class InternalRepository(Repository):
36-
3733
def __init__(self,username,password):
3834
super(InternalRepository,self).__init__(username, password)
39-
repo_name = username + "/" + 'badhikar_ocs'
35+
repo_name = username + "/" + REPO_NAME
4036
self.repo = self.gitUser.get_repo(repo_name)
4137

4238
def addFile(self, filename, data):
@@ -53,12 +49,22 @@ def addFile(self, filename, data):
5349
self.createFile(filename, data)
5450

5551
def updateFile(self, filename, data):
56-
filePath = "/{}".format(filename)
52+
filePath = "{}".format(filename)
5753
contents = self.repo.get_contents(filePath)
5854
commit_msg = "Updated file {}".format(filename)
5955
self.repo.update_file(contents.path, commit_msg, data, contents.sha)
6056

6157
def createFile(self, filename, data):
62-
filePath = "/{}".format(filename)
58+
filePath = "{}".format(filename)
6359
commit_msg = "Created file {}".format(filename)
64-
self.repo.create_file(filePath, commit_msg, data)
60+
self.repo.create_file(filePath, commit_msg, data)
61+
62+
def getStatus(self):
63+
file = {}
64+
try:
65+
file = self.repo.get_contents("status.json")
66+
file = file.decoded_content
67+
file = json.loads(file)
68+
except Exception:
69+
pass
70+
return file

0 commit comments

Comments
 (0)