-
Notifications
You must be signed in to change notification settings - Fork 11
/
juno-computenode.py
236 lines (194 loc) · 10.2 KB
/
juno-computenode.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#! /usr/bin/python
import sys
import os
import time
import fcntl
import struct
import socket
import subprocess
# These are module names which are not installed by default.
# These modules will be loaded later after downloading
iniparse = None
psutil = None
def kill_process(process_name):
for proc in psutil.process_iter():
if proc.name == process_name:
proc.kill()
def delete_file(file_path):
if os.path.isfile(file_path):
os.remove(file_path)
else:
print("Error: %s file not found" % file_path)
def write_to_file(file_path, content):
open(file_path, "a").write(content)
def add_to_conf(conf_file, section, param, val):
config = iniparse.ConfigParser()
config.readfp(open(conf_file))
if not config.has_section(section):
config.add_section(section)
val += '\n'
config.set(section, param, val)
with open(conf_file, 'w') as f:
config.write(f)
def delete_from_conf(conf_file, section, param):
config = iniparse.ConfigParser()
config.readfp(open(conf_file))
if param is None:
config.remove_section(section)
else:
config.remove_option(section, param)
with open(conf_file, 'w') as f:
config.write(f)
def get_from_conf(conf_file, section, param):
config = iniparse.ConfigParser()
config.readfp(open(conf_file))
if param is None:
raise Exception("parameter missing")
else:
return config.get(section, param)
def print_format(string):
print "+%s+" %("-" * len(string))
print "|%s|" % string
print "+%s+" %("-" * len(string))
def execute(command, display=False):
print_format("Executing : %s " % command)
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if display:
while True:
nextline = process.stdout.readline()
if nextline == '' and process.poll() != None:
break
sys.stdout.write(nextline)
sys.stdout.flush()
output, stderr = process.communicate()
exitCode = process.returncode
else:
output, stderr = process.communicate()
exitCode = process.returncode
if (exitCode == 0):
return output.strip()
else:
print "Error", stderr
print "Failed to execute command %s" % command
print exitCode, output
raise Exception(output)
def get_ip_address(ifname):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
except Exception:
print "Cannot get IP Address for Interface %s" % ifname
sys.exit(1)
def initialize_system():
if not os.geteuid() == 0:
sys.exit('Please re-run the script with root user')
execute("apt-get clean" , True)
execute("apt-get autoclean -y" , True)
execute("apt-get update -y" , True)
execute("apt-get install ubuntu-cloud-keyring python-setuptools python-iniparse python-psutil -y", True)
delete_file("/etc/apt/sources.list.d/juno.list")
execute("echo deb http://ubuntu-cloud.archive.canonical.com/ubuntu trusty-updates/juno main >> /etc/apt/sources.list.d/juno.list")
execute("apt-get update -y", True)
execute("apt-get install vlan bridge-utils -y", True)
execute("sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf")
global iniparse
if iniparse is None:
iniparse = __import__('iniparse')
global psutil
if psutil is None:
psutil = __import__('psutil')
#=================================================================================
#================== Components Installation Starts Here ========================
#=================================================================================
my_ip = get_ip_address('eth1')
ip_address = raw_input('Controller IP: ')
ip_address_mgnt= raw_input('Controller Mgmt IP: ')
def install_and_configure_ntp():
execute("apt-get install ntp -y")
execute("sed -i 's/server 0.ubuntu.pool.ntp.org/#server 0.ubuntu.pool.ntp.org/g' /etc/ntp.conf")
execute("sed -i 's/server 1.ubuntu.pool.ntp.org/#server 1.ubuntu.pool.ntp.org/g' /etc/ntp.conf")
execute("sed -i 's/server 2.ubuntu.pool.ntp.org/#server 2.ubuntu.pool.ntp.org/g' /etc/ntp.conf")
execute("sed -i 's/server 3.ubuntu.pool.ntp.org/#server 3.ubuntu.pool.ntp.org/g' /etc/ntp.conf")
execute("sed -i 's/server ntp.ubuntu.com/server %s/g' /etc/ntp.conf" %ip_address)
execute("service ntp restart", True)
def install_and_configure_nova():
nova_conf = "/etc/nova/nova.conf"
nova_paste_conf = "/etc/nova/api-paste.ini"
nova_compute_conf = "/etc/nova/nova-compute.conf"
execute("apt-get install qemu-kvm libvirt-bin python-libvirt -y")
execute("apt-get install nova-compute-kvm novnc -y", True)
add_to_conf(nova_paste_conf, "filter:authtoken", "auth_host", ip_address_mgnt)
add_to_conf(nova_paste_conf, "filter:authtoken", "auth_port", "35357")
add_to_conf(nova_paste_conf, "filter:authtoken", "auth_protocol", "http")
add_to_conf(nova_paste_conf, "filter:authtoken", "admin_tenant_name", "service")
add_to_conf(nova_paste_conf, "filter:authtoken", "admin_user", "nova")
add_to_conf(nova_paste_conf, "filter:authtoken", "admin_password", "nova")
add_to_conf(nova_conf, "DEFAULT", "logdir", "/var/log/nova")
add_to_conf(nova_conf, "DEFAULT", "verbose", "True")
add_to_conf(nova_conf, "DEFAULT", "debug", "True")
add_to_conf(nova_conf, "DEFAULT", "lock_path", "/var/lib/nova")
add_to_conf(nova_conf, "DEFAULT", "rabbit_host", ip_address_mgnt)
add_to_conf(nova_conf, "DEFAULT", "sql_connection", "mysql://nova:nova@%s/nova" %ip_address_mgnt)
add_to_conf(nova_conf, "DEFAULT", "glance_api_servers", "%s:9292" %ip_address_mgnt)
add_to_conf(nova_conf, "DEFAULT", "compute_driver", "libvirt.LibvirtDriver")
add_to_conf(nova_conf, "DEFAULT", "dhcpbridge_flagfile", "/etc/nova/nova.conf")
add_to_conf(nova_conf, "DEFAULT", "firewall_driver", "nova.virt.firewall.NoopFirewallDriver")
add_to_conf(nova_conf, "DEFAULT", "security_group_api", "neutron")
add_to_conf(nova_conf, "DEFAULT", "libvirt_vif_driver", "nova.virt.libvirt.vif.LibvirtGenericVIFDriver")
add_to_conf(nova_conf, "DEFAULT", "root_helper", "sudo nova-rootwrap /etc/nova/rootwrap.conf")
add_to_conf(nova_conf, "DEFAULT", "compute_driver", "libvirt.LibvirtDriver")
add_to_conf(nova_conf, "DEFAULT", "auth_strategy", "keystone")
add_to_conf(nova_conf, "DEFAULT", "novnc_enabled", "true")
add_to_conf(nova_conf, "DEFAULT", "novncproxy_base_url", "http://%s:6080/vnc_auto.html" % ip_address)
add_to_conf(nova_conf, "DEFAULT", "novncproxy_port", "6080")
add_to_conf(nova_conf, "DEFAULT", "vncserver_proxyclient_address", my_ip)
add_to_conf(nova_conf, "DEFAULT", "vncserver_listen", "0.0.0.0")
add_to_conf(nova_conf, "DEFAULT", "network_api_class", "nova.network.neutronv2.api.API")
add_to_conf(nova_conf, "DEFAULT", "neutron_admin_username", "neutron")
add_to_conf(nova_conf, "DEFAULT", "neutron_admin_password", "neutron")
add_to_conf(nova_conf, "DEFAULT", "neutron_admin_tenant_name", "service")
add_to_conf(nova_conf, "DEFAULT", "neutron_admin_auth_url", "http://%s:5000/v2.0/"%ip_address_mgnt)
add_to_conf(nova_conf, "DEFAULT", "neutron_auth_strategy", "keystone")
add_to_conf(nova_conf, "DEFAULT", "neutron_url", "http://%s:9696/"%ip_address_mgnt)
add_to_conf(nova_compute_conf, "DEFAULT", "libvirt_type", "qemu")
add_to_conf(nova_compute_conf, "DEFAULT", "compute_driver", "libvirt.LibvirtDriver")
add_to_conf(nova_compute_conf, "DEFAULT", "libvirt_vif_type", "ethernet")
execute("service libvirt-bin restart", True)
execute("service nova-compute restart", True)
def install_and_configure_ovs():
neutron_conf = "/etc/neutron/neutron.conf"
neutron_paste_conf = "/etc/neutron/api-paste.ini"
neutron_plugin_conf = "/etc/neutron/plugins/ml2/ml2_conf.ini"
execute("apt-get install openvswitch-switch openvswitch-datapath-dkms -y", True)
execute("ovs-vsctl --may-exist add-br br-int")
execute("ovs-vsctl --may-exist add-br br-eth2")
execute("ovs-vsctl --may-exist add-port br-eth2 eth2")
execute("apt-get install neutron-plugin-openvswitch-agent -y", True)
add_to_conf(neutron_conf, "DEFAULT", "core_plugin", "neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2")
add_to_conf(neutron_conf, "DEFAULT", "verbose", "True")
add_to_conf(neutron_conf, "DEFAULT", "debug", "True")
add_to_conf(neutron_conf, "DEFAULT", "auth_strategy", "keystone")
add_to_conf(neutron_conf, "DEFAULT", "rabbit_host", ip_address_mgnt)
add_to_conf(neutron_conf, "DEFAULT", "rabbit_port", "5672")
add_to_conf(neutron_conf, "DEFAULT", "allow_overlapping_ips", "False")
add_to_conf(neutron_conf, "DEFAULT", "root_helper", "sudo neutron-rootwrap /etc/neutron/rootwrap.conf")
add_to_conf(neutron_paste_conf, "filter:authtoken", "auth_host", ip_address_mgnt)
add_to_conf(neutron_paste_conf, "filter:authtoken", "auth_port", "35357")
add_to_conf(neutron_paste_conf, "filter:authtoken", "auth_protocol", "http")
add_to_conf(neutron_paste_conf, "filter:authtoken", "admin_tenant_name", "service")
add_to_conf(neutron_paste_conf, "filter:authtoken", "admin_user", "neutron")
add_to_conf(neutron_paste_conf, "filter:authtoken", "admin_password", "neutron")
add_to_conf(neutron_plugin_conf, "securitygroup", "firewall_driver", "neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver")
add_to_conf(neutron_plugin_conf, "DATABASE", "sql_connection", "mysql://neutron:neutron@%s/neutron"%ip_address_mgnt)
add_to_conf(neutron_plugin_conf, "OVS", "bridge_mappings", "physnet1:br-eth2")
add_to_conf(neutron_plugin_conf, "OVS", "tenant_network_type", "vlan")
add_to_conf(neutron_plugin_conf, "OVS", "network_vlan_ranges", "physnet1:1000:2999")
add_to_conf(neutron_plugin_conf, "OVS", "integration_bridge", "br-int")
execute("service neutron-plugin-openvswitch-agent restart", True)
initialize_system()
install_and_configure_ntp()
install_and_configure_nova()
install_and_configure_ovs()