-
Notifications
You must be signed in to change notification settings - Fork 34
/
create_cluster_roubaix.py
62 lines (60 loc) · 2.78 KB
/
create_cluster_roubaix.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
#!/usr/bin/env python
from lndynamic import LNDynamic
import natsort
import time
# find lunanode credentials
with open(r"../../system-dev.txt") as hpass:
lines = hpass.readlines()
api = LNDynamic(lines[0].rstrip('\n'), lines[1].rstrip('\n'))
def create_master_cluster(name):
api.request("vm", "create",
#{'hostname': name, 'plan_id': 4, 'region': 'roubaix', 'image_id': 148540, 'storage': 70})
#{'hostname': name, 'plan_id': 88, 'region': 'toronto', 'image_id': 240279, 'storage': 35})
{'hostname': name, 'plan_id': 88, 'region': 'toronto', 'image_id': 240277, 'storage': 35})
#list_of_color=['test']
#list_of_color= ['black']
#list_of_color= ['black','red','blue','yellow','white','green','brown','cyan']
#list_of_color= ['magenta','purple','orange','pink','silver','grey', 'amber']
list_of_color= ['yellow','purple','cyan','brown']
#list_of_color= ['amber','carmine']
#list_of_color=['black']
#list_of_color= ['green','black','blue']
for x in list_of_color:
cluster_name = 'k8s-' + x
create_master_cluster(cluster_name + "-master")
for j in range(1, 3):
vm_name = cluster_name + "-node-" + str(j)
api.request("vm", "create",
# {'hostname': vm_name, 'plan_id': 4, 'region': 'roubaix', 'image_id': 148540, 'storage': 70})
# {'hostname': vm_name, 'plan_id': 88, 'region': 'toronto', 'image_id': 240279, 'storage': 35})
{'hostname': vm_name, 'plan_id': 88, 'region': 'toronto', 'image_id': 240277, 'storage': 35})
# sleep while lunanode setting up public ip addresses for each VMs
time.sleep(180)
results = api.request('vm', 'list')
f = open(r"/home/hme/inventory-" + cluster_name, "w+")
hfile = open(r"/home/hme/user_list-" + cluster_name, "w+")
val = results.get("vms")
all_key= ['vm_id','name','primaryip']
#print(val)
user='ubuntu'
for z in range(0,len(val)):
if x in val[z].get(all_key[1]):
#print(val[z].get(all_key[0]))
name=val[z].get(all_key[1])
ip= val[z].get(all_key[2])
results = api.request('vm', 'info', {'vm_id': val[z].get(all_key[0])})
thepass=results.get('info')
part=thepass.get('login_details').split(':')
password=part[2]
line = "{} ansible_ssh_user={} ansible_ssh_pass={} ansible_ssh_extra_args='-o StrictHostKeyChecking=no'\n".format(ip, user , password.strip())
f.write(line)
f.close()
# print (user_dic)
#list_user = user_dic.keys();
#natural = natsort.natsorted(list_user)
# print natural
#for vts in range(0, len(natural)):
# myip = user_dic[natural[vts]]
# user_line = "{} \t {} \t ubuntu \t lawn-vex \n".format(natural[vts], myip)
# hfile.write(user_line)
#hfile.close()