-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
120 lines (89 loc) · 4.27 KB
/
setup.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
import configparser
import sys
import os.path
from subprocess import call
def checkBoltedConfigurationFile(boltedConfig, bmiConfig):
# print(boltedConfig['general']['hil'])
# use ping to check vm is reachable !!!!
if str(boltedConfig['serverip']['hil']) == "0.0.0.0" or \
str(boltedConfig['serverip']['bmi']) == "0.0.0.0" or \
str(boltedConfig['serverip']['keylime-server']) == "0.0.0.0" or \
str(boltedConfig['serverip']['keylime-client']) == "0.0.0.0" or \
str(boltedConfig['bmi']['uid']).startswith('<') or \
str(boltedConfig['bmi']['service']).startswith('<') or \
str(boltedConfig['fs']['id']).startswith('<') or \
str(boltedConfig['fs']['pool']).startswith('<') or \
str(boltedConfig['fs']['conf_file']).startswith('<') or \
str(boltedConfig['fs']['keyring']).startswith('<'):
print "ERROR: Please change the configuration file to proceed"
return
if not (os.path.exists('ceph_keyring/'+str(boltedConfig['fs']['keyring'])) and \
os.path.exists('ceph_keyring/'+str(boltedConfig['fs']['conf_file']))):
print "ERROR: Please place your ceph key files into ceph_keyring folder."
return
print("Now start installing bolted system.\n")
if os.path.exists('hosts'):
os.remove('hosts')
with open("hosts", "w+") as f:
f.write("[hil]\n")
f.write(str(boltedConfig['serverip']['hil']))
f.write("\n\n[bmi]\n")
f.write(str(boltedConfig['serverip']['bmi']))
f.write("\n\n[keylime-server]\n")
f.write(str(boltedConfig['serverip']['keylime-server']))
f.write("\n\n[keylime-client]\n")
f.write(str(boltedConfig['serverip']['keylime-client']))
f.write("\n")
# Reconfigure BMI config file
bmiConfig['bmi']['uid'] = boltedConfig['bmi']['uid']
bmiConfig['bmi']['service'] = boltedConfig['bmi']['service']
bmiConfig['fs']['id'] = boltedConfig['fs']['id']
bmiConfig['fs']['pool'] = boltedConfig['fs']['pool']
bmiConfig['fs']['conf_file'] = boltedConfig['fs']['conf_file']
bmiConfig['fs']['keyring'] = boltedConfig['fs']['keyring']
bmiConfig['net_isolator']['url'] = boltedConfig['serverip']['hil']+':80'
# Overwrite the original BMI conf file
with open("containers/bmi/bmi_config.cfg", 'w') as f:
bmiConfig.write(f)
print('Now running all the ansible scripts')
call(["sudo", "cp", "/etc/ansible/hosts", "tmp_hosts"])
call(["sudo", "cp", "hosts", "/etc/ansible/hosts"])
# installing docker and dependencies on all VMs
# call(["ansible-playbook", "ansible/docker_install.yml"])
# deploying keylime server component
call(["ansible-playbook", "ansible/keylime_server_deploy.yml"])
# deploying keylime client node component
keylimeclientargs = ['ansible-playbook', 'ansible/keylime_client_deploy.yml', '-e']
keylimeserverip = 'myip=' + str(boltedConfig['serverip']['keylime-server'])
print(keylimeserverip)
keylimeclientargs.append(keylimeserverip)
print(keylimeclientargs)
call(keylimeclientargs)
# deploying hil component
call(["ansible-playbook", "ansible/hil_deploy.yml"])
# deploying bmi component
call(["ansible-playbook", "ansible/bmi_deploy.yml"])
call(["sudo", "cp", "tmp_hosts", "/etc/ansible/hosts"])
if os.path.exists('hosts'):
os.remove('hosts')
if os.path.exists('tmp_hosts'):
os.remove('tmp_hosts')
def main():
# print(sys.argv[1] == 'install')
if len(sys.argv) <= 1:
print("Please input argument.\n")
if not os.path.exists('bolted.cfg'):
print "File 'bolted.cfg' can not be found from current directory, please check before you proceed."
sys.exit()
if not os.path.exists('containers/bmi/bmi_config.cfg'):
print "File 'bmi_config.cfg' can not be found from containers/bmi/, please check before you proceed."
sys.exit()
if sys.argv[1] == "install":
print("Install bolted system.\n")
boltedConfig = configparser.ConfigParser()
boltedConfig.read('bolted.cfg')
bmiConfig = configparser.ConfigParser()
bmiConfig.read('containers/bmi/bmi_config.cfg')
checkBoltedConfigurationFile(boltedConfig, bmiConfig)
if __name__ == "__main__":
main()