-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·138 lines (112 loc) · 4.7 KB
/
main.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/python -tt
import os
import sys
import optparse
import getpass
import time
from iniparse import INIConfig
sys.path.append('ec2')
sys.path.append('shell')
sys.path.append('local')
from ec2lib import ec2h
from commandRunner import execute
from localLib import lc
parser = optparse.OptionParser()
parser.add_option('-n', '--name', help='name the environment')
parser.add_option('-e', '--install_env', help='pick environment: ec2,local',
dest='install_env', type='string')
(opts, args) = parser.parse_args()
cfg = INIConfig(open('config'))
myenv = INIConfig(open('environment'))
def checkEnvState(thisDict):
for i in thisDict.keys():
instance = thisDict[i].__dict__
hostname = instance['public_dns_name'].encode('ascii')
#quick check to make sure everything is up and running
x = execute(i, hostname, 'root', cfg.EC2.east_key,
cfg.EC2.east_keyName)
if not x.connectionSuccessful:
exit(-1)
print(x.rc('hostname'))
def get_rhui_version():
dvd = cfg.MAIN.dvd
return dvd.split('/')[-1].split('-')[3]
def startInstances(rhuiEnv):
## start an instance
e = ec2h(cfg.EC2.region, cfg.EC2.username, cfg.EC2.password)
myConn = e.getConnection()
dict = {}
for i in rhuiEnv:
sec_group = [cfg.EC2.sec_group]
thisInstance = e.startInstance(cfg.EC2.ami_id, cfg.EC2.east_keyName, sec_group, cfg.EC2.hwp)
instanceDetails = thisInstance.__dict__
this_hostname = instanceDetails['public_dns_name']
print(this_hostname)
dict[i] = thisInstance
return dict
if __name__ == '__main__':
if cfg.MAIN.environment == 'ec2':
thisEnv = list(myenv)
dict = startInstances(thisEnv)
## wait for instance and check ssh
print('wait for instances to boot for 130 seconds')
time.sleep(float(cfg.EC2.sleepForInstance))
print('done waiting for instances to boot')
checkEnvState(dict)
rhuiEnv = {}
clientEnv = {}
if 'RHUA' in thisEnv:
rhua = dict['RHUA'].__dict__
rhuaCMD = execute('RHUA', rhua['public_dns_name'].encode('ascii'),
'root', cfg.EC2.east_key, cfg.EC2.east_keyName)
rhuiEnv['rhua'] = rhua
rhuiEnv['rhuaCMD'] = rhuaCMD
rhua['ent_cert'] = cfg.ENT_CERTS.cert
if 'CDS1' in thisEnv:
cds1 = dict['CDS1'].__dict__
cds1CMD = execute('CDS1', cds1['public_dns_name'].encode('ascii'),
'root', cfg.EC2.east_key, cfg.EC2.east_keyName)
rhuiEnv['cds1'] = cds1
rhuiEnv['cds1CMD'] = cds1CMD
if 'CDS2' in thisEnv:
cds2 = dict['CDS2'].__dict__
cds2CMD = execute('CDS2', cds2['public_dns_name'].encode('ascii'),
'root', cfg.EC2.east_key, cfg.EC2.east_keyName)
rhuiEnv['cds2'] = cds2
rhuiEnv['cds2CMD'] = cds2CMD
if 'CDS3' in thisEnv:
cds3 = dict['CDS3'].__dict__
cds3CMD = execute('CDS3', cds3['public_dns_name'].encode('ascii'),
'root', cfg.EC2.east_key, cfg.EC2.east_keyName)
rhuiEnv['cds3'] = cds3
rhuiEnv['cds3CMD'] = cds3CMD
if 'CLIENT1' in thisEnv:
client1 = dict['CLIENT1'].__dict__
client1CMD = execute('CLIENT1',
client1['public_dns_name'].encode('ascii'), 'root',
cfg.EC2.east_key, cfg.EC2.east_keyName)
if 'CLIENT2' in thisEnv:
client2 = dict['CLIENT2'].__dict__
client2CMD = execute('CLIENT2',
client2['public_dns_name'].encode('ascii'),
'root', cfg.EC2.east_key, cfg.EC2.east_keyName)
if 'PROXY' in thisEnv:
proxy = dict['PROXY'].__dict__
proxyCMD = execute('PROXY',
proxy['public_dns_name'].encode('ascii'),
'root', cfg.EC2.east_key, cfg.EC2.east_keyName)
proxy['proxyAuth'] = cfg.PROXY.auth
clientEnv['proxy']= proxy
clientEnv['proxyCMD']= proxyCMD
#Install RHUI
if 'RHUA' in thisEnv:
lc.prepInstall(rhuiEnv, clientEnv, cfg)
lc.runInstall(rhuiEnv, cfg.EC2.east_key, get_rhui_version(), cfg)
#install CDS
if 'CDS1' or 'CDS2' or 'CDS3' in thisEnv:
lc.installCDS(thisEnv, rhuiEnv, cfg)
#Install PROXY
if 'PROXY' in thisEnv:
lc.installSquidProxy(clientEnv, rhuiEnv)
elif cfg.MAIN.environment == 'local':
print('in local')