-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_workstation.py
85 lines (69 loc) · 2.7 KB
/
setup_workstation.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
#!/usr/bin/env python3
import os
import re
from platform import system
from subprocess import run
from time import sleep
BRIDGE_RULES = """ACTION=="add", SUBSYSTEM=="module", KERNEL=="br_netfilter", \
RUN+="/usr/lib/systemd/systemd-sysctl --prefix=/net/bridge"
"""
BRIDGE_CONF = """net.bridge.bridge-nf-call-arptables = 0
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
"""
def sysrc(service, option, rc_path=None):
arg = f'-f {rc_path}' if rc_path is not None else ''
run(f'sysrc {arg} {service}={option}', shell=True)
def freebsd_service(service, option):
run(f'service {service} {option}', shell=True)
def setup_Linux():
packages = open('linux-packages').read().replace('\n', ' ')
run(f'apt install -y {packages}', shell=True)
sleep(1)
qemuconf = open('/etc/libvirt/qemu.conf').read()
if '#user = "root"' in qemuconf:
qemuconf = re.sub(r'#user = "root"', 'user = "root"', qemuconf)
if '#user = "root"' in qemuconf:
qemuconf = re.sub(r'#group = "root"', 'group = "root"', qemuconf)
# save_parser_file = open('/etc/libvirt/qemu.conf', 'w')
# save_parser_file.writelines(qemuconf)
# save_parser_file.close()
# save_bridge_rules = open('/etc/udev/rules.d/99-bridge.rules', 'w')
# save_bridge_rules.writelines(BRIDGE_RULES)
# save_bridge_rules.close()
# save_bridge_conf = open('/etc/sysctl.d/bridge.conf', 'w')
# save_bridge_conf.writelines(BRIDGE_CONF)
# save_bridge_conf.close()
# sleep(1)
# run('sysctl -p /etc/sysctl.d/bridge.conf', shell=True)
run('systemctl restart libvirtd', shell=True)
sleep(1)
def setup_FreeBSD():
packages = open('freebsd-packages').read().replace('\n', ' ')
run(f'pkg install -y {packages}', shell=True)
sysrc('vm_enable', 'YES')
sysrc('vm_dir', '/usr/local/ixautomation/vms')
sysrc('libvirtd_enable', 'YES')
freebsd_service('vm', 'start')
freebsd_service('libvirtd', 'start')
print('Install iXautomation with the following command as root:')
print('# cd src ; python setup.py install\n')
print('After to setup the bridge run ixautomation with --setup-bridge and '
'the interface to setup the bridge like bellow: ')
print('# ixautomation --setup-bridge <interface>\n')
print("Replace <interface> with you interface like igb1")
if system() == 'Linux':
setup_Linux()
elif system() == 'FreeBSD':
setup_FreeBSD()
else:
print(f'{system()} is not supported yet')
exit(1)
# create /data' if it does not exist
if os.path.exists('/data'):
os.system('chown root:libvirt /data')
os.system('chmod 770 /data')
else:
os.mkdir('/data')
os.system('chown root:libvirt /data')
os.system('chmod 770 /data')