-
Notifications
You must be signed in to change notification settings - Fork 0
/
eksctl_eks.py
123 lines (95 loc) · 3.55 KB
/
eksctl_eks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
import subprocess
import time
import json
#python 3.6
#aws cli
#aws authentication ~/.aws
#eksctl
#need to check other options for command to run with streaming output
def subprocess_cmd(command):
print("cmd to be executed = " + str(command))
output = subprocess.check_output(command, shell=True)
#print(output)
return output
def getClusters():
return json.loads(subprocess_cmd("eksctl get cluster -o json"))
def print_clusters(clusters):
for i in clusters:
print("Cluster name == {name} and region == {region}".format(name=i['name'], region=i['region']))
def createListOfClusterName():
clusterNameList = []
clusters = getClusters()
for i in clusters:
clusterNameList.append(i['name'])
return clusterNameList
def checkCluster(name, region):
clusters = getClusters()
#print(clusters)
f = True
for i in clusters:
if name == i['name'] and region == i['region']:
#print("Cluster is there change name or region to proceed forward")
#return False
f = False
else:
#return True
f = True
return f
#act = json.loads(subprocess_cmd("eksctl get cluster -o json"))
#print(act)
#for i in act:
# print("Cluster name == {name} and region == {region}".format(name=i['name'], region=i['region']))
def createCluster():
clusterName = input("Enter cluster name : ")
clusterRegion = input("Enter cluster region : ")
if checkCluster(clusterName, clusterRegion) == False:
print("Cluster is there change name or region to proceed forward")
else:
nodes = input("Enter number of nodes : ")
minNodes = input("Enter minimum number of nodes in cluster : ")
maxNodes = input("Enter maximum number of nodes in cluster : ")
path = input("enter path for kubeconfig file : ")
command = "eksctl create cluster --name {clusterName} --version 1.13 --nodegroup-name standard-workers --node-type t3.medium --nodes {nodes} --nodes-min {minNodes} --nodes-max {maxNodes} --node-ami auto --kubeconfig {path}/kubeconfig".format(clusterName=clusterName, nodes=nodes, minNodes=minNodes, maxNodes=maxNodes, path=path)
print(command)
output = subprocess_cmd(command)
print(output)
def deleteCluster():
f = True
while f == True:
clusters = getClusters()
#for i in clusters:
# print("Cluster name == {name} and region == {region}".format(name=i['name'], region=i['region']))
print_clusters(clusters)
del_cluster = input("Enter name of cluster to delete (case sensitive) : ")
if del_cluster in createListOfClusterName():
command = "eksctl delete cluster {name}".format(name=del_cluster)
output = subprocess_cmd(command)
print(json.loads(output))
f = False
else:
print("wrong cluster name, please enter correct name ")
#createCluster()
#deleteCluster()
print("1) for list of clusters ")
print("2) for create cluster ")
print("3) for delete cluster ")
user_input= int(input("select operation "))
print(type(user_input))
if user_input == 1:
clusters = getClusters()
print_clusters(clusters)
elif user_input == 2:
createCluster()
else:
deleteCluster()
'''
clusterName = input("Enter cluster name : ")
clusterRegion = input("Enter cluster region : ")
out = checkCluster(clusterName, clusterRegion)
print(out)
'''
#create cluster need to find way to add kubeconfig file to location
#sclae up cluster
#scale down cluster
#need BOTO3 to get information related to cluster