-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_backends.jl
executable file
·73 lines (64 loc) · 2.6 KB
/
build_backends.jl
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
#!/Users/kfischer/julia/julia
include("openstack-test.jl")
function build_backend(sname)
serv = get_server(sname; flavor = "lg.12core")
backend_networking(serv)
provision(serv,["apt","build-essential","git","gfortran","ncurses","julia","docker"])
run(ssh_cmd(nova,token,serv,"ijulia.pem","sudo stop docker && sudo start docker"))
install_collectd(serv)
build_docker_containers(sname)
end
backend_networking(sname) = backend_networking(get_server(sname; flavor = "lg.12core"))
function backend_networking(serv::OpenStack.Server)
write_networking(serv,"""
# Allow communication between the fontend node and the containers
iptables -A FORWARD -s \$DOCKER_NETWORK -d \$FRONTEND_NODE -j ACCEPT
iptables -A FORWARD -s \$FRONTEND_NODE -d \$DOCKER_NETWORK -j ACCEPT
iptables -A INPUT -s \$FRONTEND_NODE -d \$DOCKER_NETWORK -j ACCEPT
# Allow communication between the fontend node and the containers
iptables -A FORWARD -s \$DOCKER_NETWORK -d \$STAGING_NODE -j ACCEPT
iptables -A FORWARD -s \$STAGING_NODE -d \$DOCKER_NETWORK -j ACCEPT
iptables -A INPUT -s \$STAGING_NODE -d \$DOCKER_NETWORK -j ACCEPT
# Disallow inter-container communication
iptables -A FORWARD -s \$DOCKER_NETWORK -d \$DOCKER_NETWORK -j DROP
iptables -A FORWARD -d \$DOCKER_NETWORK -s \$DOCKER_NETWORK -j DROP
# Disallow container access to internal network
iptables -A FORWARD -s \$DOCKER_NETWORK -d 192.168.0.0/24 -j DROP
""")
end
function build_docker_containers(sname)
serv = get_server(sname; flavor = "m1.12core")
port = rand(10000:30000)
p = spawn((`ssh -N -n -p 22 -o StrictHostKeyChecking=no -L $port:localhost:4243 -i ijulia.pem ubuntu@$(ips(nova,token,serv)[1])` |> STDOUT) .>STDERR)
sleep(4.0) #Wait while SSH session is being established
build_docker_container("127.0.0.1",port,"julia-container")
build_docker_container("127.0.0.1",port,"webdav-container")
build_docker_container("127.0.0.1",port,"webdav-passwd-container")
kill(p)
end
if length(ARGS) >= 1
if ARGS[1] == "rsync"
f = rsync_backend
elseif ARGS[1] == "network"
f = backend_networking
elseif ARGS[1] == "container"
f = build_docker_containers
elseif ARGS[1] == "build"
f = build_backend
else
error("Unrecognized command")
end
else
error("must specify a command")
end
if length(ARGS) != 2
error("must specify a container")
end
if ARGS[2] == "all"
for b in ["ijulia-backend-0","ijulia-backend-2","ijulia_backend-3"]
@async f(b)
end
else
f(ARGS[2])
end
wait()