Statistics
| Branch: | Tag: | Revision:

root / snf-deploy / snfdeploy / __init__.py @ c0c8263a

History | View | Annotate | Download (19 kB)

1 ad76b118 Dimitris Aragiorgis
import json
2 ad76b118 Dimitris Aragiorgis
import time
3 ad76b118 Dimitris Aragiorgis
import ipaddr
4 ad76b118 Dimitris Aragiorgis
import os
5 ad76b118 Dimitris Aragiorgis
import signal
6 ad76b118 Dimitris Aragiorgis
import time
7 ad76b118 Dimitris Aragiorgis
import ConfigParser
8 ad76b118 Dimitris Aragiorgis
import argparse
9 ad76b118 Dimitris Aragiorgis
import sys
10 ad76b118 Dimitris Aragiorgis
import re
11 ad76b118 Dimitris Aragiorgis
import random
12 ad76b118 Dimitris Aragiorgis
import subprocess
13 ad76b118 Dimitris Aragiorgis
import imp
14 ad76b118 Dimitris Aragiorgis
import ast
15 ad76b118 Dimitris Aragiorgis
from snfdeploy.lib import *
16 ad76b118 Dimitris Aragiorgis
17 ad76b118 Dimitris Aragiorgis
def print_available_actions(command):
18 ad76b118 Dimitris Aragiorgis
19 bbc3b7e7 Ilias Tsitsimpis
  if command == "keygen":
20 bbc3b7e7 Ilias Tsitsimpis
    print """
21 bbc3b7e7 Ilias Tsitsimpis
Usage: snf-deploy keygen [--force]
22 bbc3b7e7 Ilias Tsitsimpis

23 bbc3b7e7 Ilias Tsitsimpis
  Generate new ssh keys (both rsa and dsa keypairs)
24 bbc3b7e7 Ilias Tsitsimpis

25 bbc3b7e7 Ilias Tsitsimpis
  """
26 bbc3b7e7 Ilias Tsitsimpis
27 ad76b118 Dimitris Aragiorgis
  if command == "vcluster":
28 ad76b118 Dimitris Aragiorgis
    print """
29 ad76b118 Dimitris Aragiorgis
Usage: snf-deploy vcluster
30 ad76b118 Dimitris Aragiorgis

31 ad76b118 Dimitris Aragiorgis
  Run the following actions concerning the local virtual cluster:
32 ad76b118 Dimitris Aragiorgis

33 ad76b118 Dimitris Aragiorgis
    - Download base image and create additional disk (if --create-extra-disk is passed)
34 ad76b118 Dimitris Aragiorgis
    - Does all the network related actions (bridge, iptables, NAT)
35 ad76b118 Dimitris Aragiorgis
    - Launches dnsmasq for dhcp server on bridge
36 ad76b118 Dimitris Aragiorgis
    - Creates the virtual cluster (with kvm)
37 ad76b118 Dimitris Aragiorgis

38 ad76b118 Dimitris Aragiorgis
  """
39 ad76b118 Dimitris Aragiorgis
40 ad76b118 Dimitris Aragiorgis
  if command == "prepare":
41 ad76b118 Dimitris Aragiorgis
    print """
42 ad76b118 Dimitris Aragiorgis
Usage: snf-deploy prepare
43 ad76b118 Dimitris Aragiorgis

44 ad76b118 Dimitris Aragiorgis
  Run the following actions concerning deployment preparation:
45 ad76b118 Dimitris Aragiorgis

46 ad76b118 Dimitris Aragiorgis
    - Setup an internal Domain Name Server
47 ad76b118 Dimitris Aragiorgis
    - Tweak hosts and add ssh keys
48 ad76b118 Dimitris Aragiorgis
    - Check network setup
49 ad76b118 Dimitris Aragiorgis
    - Setup apt repository and apt-get update
50 ad76b118 Dimitris Aragiorgis
    - Setup the nfs server and clients among all nodes
51 ad76b118 Dimitris Aragiorgis

52 ad76b118 Dimitris Aragiorgis
  """
53 ad76b118 Dimitris Aragiorgis
54 ad76b118 Dimitris Aragiorgis
  if command == "backend":
55 ad76b118 Dimitris Aragiorgis
    print """
56 ad76b118 Dimitris Aragiorgis
Usage: snf-deploy backend [update]
57 ad76b118 Dimitris Aragiorgis

58 ad76b118 Dimitris Aragiorgis
  Run the following actions concerning a ganeti backend:
59 ad76b118 Dimitris Aragiorgis

60 ad76b118 Dimitris Aragiorgis
    - Create and add a backend to cyclades
61 ad76b118 Dimitris Aragiorgis
    - Does all the net-infra specific actions in backend nodes
62 ad76b118 Dimitris Aragiorgis
      (create/connect bridges, iptables..)
63 ad76b118 Dimitris Aragiorgis
    - Does all the storage-infra specific actions in backend nodes
64 ad76b118 Dimitris Aragiorgis
      depending on the --extra-disk option (create VG, enable lvm/drbd storage..)
65 ad76b118 Dimitris Aragiorgis

66 ad76b118 Dimitris Aragiorgis
    or
67 ad76b118 Dimitris Aragiorgis

68 ad76b118 Dimitris Aragiorgis
    - Update packages in an already registered backend in cyclades.
69 ad76b118 Dimitris Aragiorgis

70 ad76b118 Dimitris Aragiorgis
  """
71 ad76b118 Dimitris Aragiorgis
72 ad76b118 Dimitris Aragiorgis
  if command == "run":
73 ad76b118 Dimitris Aragiorgis
    print """
74 ad76b118 Dimitris Aragiorgis
Usage: snf-deploy run <action> [<action>...]
75 ad76b118 Dimitris Aragiorgis

76 ad76b118 Dimitris Aragiorgis
  Run any of the following fabric commands:
77 ad76b118 Dimitris Aragiorgis

78 ad76b118 Dimitris Aragiorgis

79 ad76b118 Dimitris Aragiorgis
    Setup commands:        Init commands:                Admin commands:
80 ad76b118 Dimitris Aragiorgis
      setup_apache           add_pools                     activate_user
81 ad76b118 Dimitris Aragiorgis
      setup_apt              add_rapi_user                 add_backend
82 ad76b118 Dimitris Aragiorgis
      setup_astakos          add_nodes                     add_image_locally
83 ad76b118 Dimitris Aragiorgis
      setup_cms              astakos_loaddata              add_network
84 b29b8213 Christos Stavrakakis
      setup_common           astakos_register_components   add_ns
85 ad76b118 Dimitris Aragiorgis
      setup_cyclades         cms_loaddata                  add_user
86 ad76b118 Dimitris Aragiorgis
      setup_db               cyclades_loaddata             connect_bridges
87 ad76b118 Dimitris Aragiorgis
      setup_ganeti           enable_drbd                   create_bridges
88 ad76b118 Dimitris Aragiorgis
      setup_gtools           init_cluster                  create_vlans
89 ad76b118 Dimitris Aragiorgis
      setup_gunicorn         setup_nfs_clients             destroy_db
90 ad76b118 Dimitris Aragiorgis
      setup_hosts            setup_nfs_server              get_auth_token_from_db
91 ad76b118 Dimitris Aragiorgis
      setup_image_helper     update_ns_for_ganeti          get_service_details
92 ad76b118 Dimitris Aragiorgis
      setup_image_host                                     gnt_instance_add
93 ad76b118 Dimitris Aragiorgis
      setup_iptables                                       gnt_network_add
94 ad76b118 Dimitris Aragiorgis
      setup_kamaki         Test commands:                  register_image
95 ad76b118 Dimitris Aragiorgis
      setup_lvm              test                          restart_services
96 ad76b118 Dimitris Aragiorgis
      setup_mq                                             setup_drbd_dparams
97 ad76b118 Dimitris Aragiorgis
      setup_net_infra
98 ad76b118 Dimitris Aragiorgis
      setup_network
99 ad76b118 Dimitris Aragiorgis
      setup_ns
100 ad76b118 Dimitris Aragiorgis
      setup_pithos
101 ad76b118 Dimitris Aragiorgis
      setup_pithos_dir
102 ad76b118 Dimitris Aragiorgis
      setup_router
103 ad76b118 Dimitris Aragiorgis
      setup_vncauthproxy
104 ad76b118 Dimitris Aragiorgis
      setup_webproject
105 ad76b118 Dimitris Aragiorgis

106 ad76b118 Dimitris Aragiorgis
  """
107 ad76b118 Dimitris Aragiorgis
108 ad76b118 Dimitris Aragiorgis
  sys.exit(1)
109 ad76b118 Dimitris Aragiorgis
110 ad76b118 Dimitris Aragiorgis
111 ad76b118 Dimitris Aragiorgis
def create_dnsmasq_files(args, env):
112 ad76b118 Dimitris Aragiorgis
113 ad76b118 Dimitris Aragiorgis
  print("Customize dnsmasq..")
114 ad76b118 Dimitris Aragiorgis
  out = env.dns
115 ad76b118 Dimitris Aragiorgis
116 ad76b118 Dimitris Aragiorgis
  hostsfile = open(out + "/dhcp-hostsfile", "w")
117 ad76b118 Dimitris Aragiorgis
  optsfile = open(out + "/dhcp-optsfile", "w")
118 ad76b118 Dimitris Aragiorgis
  conffile = open(out + "/conf-file", "w")
119 ad76b118 Dimitris Aragiorgis
120 ad76b118 Dimitris Aragiorgis
  for node, info in env.nodes_info.iteritems():
121 ad76b118 Dimitris Aragiorgis
    # serve ip and hostname to nodes
122 ad76b118 Dimitris Aragiorgis
    hostsfile.write("%s,%s,%s,2m\n" % (info.mac, info.ip, info.hostname))
123 ad76b118 Dimitris Aragiorgis
124 ad76b118 Dimitris Aragiorgis
  hostsfile.write("52:54:56:*:*:*,ignore\n")
125 ad76b118 Dimitris Aragiorgis
126 ad76b118 Dimitris Aragiorgis
  # Netmask
127 ad76b118 Dimitris Aragiorgis
  optsfile.write("1,%s\n" % env.net.netmask)
128 ad76b118 Dimitris Aragiorgis
  # Gateway
129 ad76b118 Dimitris Aragiorgis
  optsfile.write("3,%s\n" % env.gateway)
130 ad76b118 Dimitris Aragiorgis
  # Namesevers
131 ad76b118 Dimitris Aragiorgis
  optsfile.write("6,%s\n" % "8.8.8.8")
132 ad76b118 Dimitris Aragiorgis
133 ad76b118 Dimitris Aragiorgis
  dnsconf = """
134 ad76b118 Dimitris Aragiorgis
user=dnsmasq
135 ad76b118 Dimitris Aragiorgis
bogus-priv
136 ad76b118 Dimitris Aragiorgis
no-poll
137 ad76b118 Dimitris Aragiorgis
no-negcache
138 ad76b118 Dimitris Aragiorgis
leasefile-ro
139 ad76b118 Dimitris Aragiorgis
bind-interfaces
140 ad76b118 Dimitris Aragiorgis
except-interface=lo
141 ad76b118 Dimitris Aragiorgis
dhcp-fqdn
142 ad76b118 Dimitris Aragiorgis
no-resolv
143 ad76b118 Dimitris Aragiorgis
# disable DNS
144 ad76b118 Dimitris Aragiorgis
port=0
145 ad76b118 Dimitris Aragiorgis
""".format(env.ns.ip)
146 ad76b118 Dimitris Aragiorgis
147 ad76b118 Dimitris Aragiorgis
  dnsconf += """
148 ad76b118 Dimitris Aragiorgis
# serve domain and search domain for resolv.conf
149 ad76b118 Dimitris Aragiorgis
domain={5}
150 ad76b118 Dimitris Aragiorgis
interface={0}
151 ad76b118 Dimitris Aragiorgis
dhcp-hostsfile={1}
152 ad76b118 Dimitris Aragiorgis
dhcp-optsfile={2}
153 ad76b118 Dimitris Aragiorgis
dhcp-range={0},{4},static,2m
154 ad76b118 Dimitris Aragiorgis
""".format(env.bridge, hostsfile.name, optsfile.name,
155 ad76b118 Dimitris Aragiorgis
           env.domain, env.net.network, env.domain)
156 ad76b118 Dimitris Aragiorgis
157 ad76b118 Dimitris Aragiorgis
  conffile.write(dnsconf)
158 ad76b118 Dimitris Aragiorgis
159 ad76b118 Dimitris Aragiorgis
  hostsfile.close()
160 ad76b118 Dimitris Aragiorgis
  optsfile.close()
161 ad76b118 Dimitris Aragiorgis
  conffile.close()
162 ad76b118 Dimitris Aragiorgis
163 ad76b118 Dimitris Aragiorgis
164 ad76b118 Dimitris Aragiorgis
def cleanup(args, env):
165 ad76b118 Dimitris Aragiorgis
  print("Cleaning up bridge, NAT, resolv.conf...")
166 ad76b118 Dimitris Aragiorgis
167 ad76b118 Dimitris Aragiorgis
  for f in os.listdir(env.run):
168 ad76b118 Dimitris Aragiorgis
    if re.search(".pid$", f):
169 ad76b118 Dimitris Aragiorgis
      check_pidfile(os.path.join(env.run, f))
170 ad76b118 Dimitris Aragiorgis
171 ad76b118 Dimitris Aragiorgis
  create_dir(env.run, True)
172 ad76b118 Dimitris Aragiorgis
  # create_dir(env.cmd, True)
173 ad76b118 Dimitris Aragiorgis
  cmd = """
174 ad76b118 Dimitris Aragiorgis
  iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
175 ad76b118 Dimitris Aragiorgis
  echo 0 > /proc/sys/net/ipv4/ip_forward
176 ad76b118 Dimitris Aragiorgis
  iptables -D INPUT -i {2} -j ACCEPT
177 ad76b118 Dimitris Aragiorgis
  iptables -D FORWARD -i {2} -j ACCEPT
178 ad76b118 Dimitris Aragiorgis
  iptables -D OUTPUT -o {2} -j ACCEPT
179 ad76b118 Dimitris Aragiorgis
  """.format(env.subnet, get_default_route()[1], env.bridge)
180 ad76b118 Dimitris Aragiorgis
  os.system(cmd)
181 ad76b118 Dimitris Aragiorgis
182 ad76b118 Dimitris Aragiorgis
  cmd = """
183 ad76b118 Dimitris Aragiorgis
  ip link show {0} && ip addr del {1}/{2} dev {0}
184 ad76b118 Dimitris Aragiorgis
  sleep 1
185 ad76b118 Dimitris Aragiorgis
  ip link set {0} down
186 ad76b118 Dimitris Aragiorgis
  sleep 1
187 ad76b118 Dimitris Aragiorgis
  brctl delbr {0}
188 ad76b118 Dimitris Aragiorgis
  """.format(env.bridge, env.gateway, env.net.prefixlen)
189 ad76b118 Dimitris Aragiorgis
  os.system(cmd)
190 ad76b118 Dimitris Aragiorgis
191 ad76b118 Dimitris Aragiorgis
192 ad76b118 Dimitris Aragiorgis
def network(args, env):
193 ad76b118 Dimitris Aragiorgis
  print("Create bridge..Add gateway IP..Activate NAT..Append NS options to resolv.conf")
194 ad76b118 Dimitris Aragiorgis
195 ad76b118 Dimitris Aragiorgis
  cmd = """
196 ad76b118 Dimitris Aragiorgis
  ! ip link show {0} && brctl addbr {0} && ip link set {0} up
197 ad76b118 Dimitris Aragiorgis
  sleep 1
198 ad76b118 Dimitris Aragiorgis
  ip link set promisc on dev {0}
199 ad76b118 Dimitris Aragiorgis
  ip addr add {1}/{2} dev {0}
200 ad76b118 Dimitris Aragiorgis
  """.format(env.bridge, env.gateway, env.net.prefixlen)
201 ad76b118 Dimitris Aragiorgis
  os.system(cmd)
202 ad76b118 Dimitris Aragiorgis
203 ad76b118 Dimitris Aragiorgis
  cmd = """
204 ad76b118 Dimitris Aragiorgis
  iptables -t nat -A POSTROUTING -s {0} -o {1} -j MASQUERADE
205 ad76b118 Dimitris Aragiorgis
  echo 1 > /proc/sys/net/ipv4/ip_forward
206 ad76b118 Dimitris Aragiorgis
  iptables -I INPUT 1 -i {2} -j ACCEPT
207 ad76b118 Dimitris Aragiorgis
  iptables -I FORWARD 1 -i {2} -j ACCEPT
208 ad76b118 Dimitris Aragiorgis
  iptables -I OUTPUT 1 -o {2} -j ACCEPT
209 ad76b118 Dimitris Aragiorgis
  """.format(env.subnet, get_default_route()[1], env.bridge)
210 ad76b118 Dimitris Aragiorgis
  os.system(cmd)
211 ad76b118 Dimitris Aragiorgis
212 ad76b118 Dimitris Aragiorgis
213 ad76b118 Dimitris Aragiorgis
def image(args, env):
214 ad76b118 Dimitris Aragiorgis
  if env.os == "ubuntu":
215 ad76b118 Dimitris Aragiorgis
    url = env.ubuntu_image_url
216 ad76b118 Dimitris Aragiorgis
  else:
217 ad76b118 Dimitris Aragiorgis
    url = env.squeeze_image_url
218 ad76b118 Dimitris Aragiorgis
219 ad76b118 Dimitris Aragiorgis
  disk0 = "{0}/{1}.disk0".format(env.images, env.os)
220 ad76b118 Dimitris Aragiorgis
  disk1 = "{0}/{1}.disk1".format(env.images, env.os)
221 ad76b118 Dimitris Aragiorgis
222 ad76b118 Dimitris Aragiorgis
  if url and not os.path.exists(disk0):
223 ad76b118 Dimitris Aragiorgis
    cmd = "wget {0} -O {1}".format(url, disk0)
224 ad76b118 Dimitris Aragiorgis
    os.system(cmd)
225 ad76b118 Dimitris Aragiorgis
226 ad76b118 Dimitris Aragiorgis
  if ast.literal_eval(env.create_extra_disk) and not os.path.exists(disk1):
227 ad76b118 Dimitris Aragiorgis
    if env.lvg:
228 ad76b118 Dimitris Aragiorgis
      cmd = "lvcreate -L30G -n{0}.disk1 {1}".format(env.os, env.lvg)
229 ad76b118 Dimitris Aragiorgis
      os.system(cmd)
230 ad76b118 Dimitris Aragiorgis
      cmd = "ln -s /dev/{0}/{1}.disk1 {2}".format(env.lvg, env.os, disk1)
231 ad76b118 Dimitris Aragiorgis
      os.system(cmd)
232 ad76b118 Dimitris Aragiorgis
    else:
233 ad76b118 Dimitris Aragiorgis
      cmd = "dd if=/dev/zero of={0} bs=10M count=3000".format(disk1)
234 ad76b118 Dimitris Aragiorgis
      os.system(cmd)
235 ad76b118 Dimitris Aragiorgis
236 ad76b118 Dimitris Aragiorgis
237 ad76b118 Dimitris Aragiorgis
def fabcommand(args, env, actions, nodes=[]):
238 ad76b118 Dimitris Aragiorgis
  levels = ["status", "aborts", "warnings", "running",
239 ad76b118 Dimitris Aragiorgis
            "stdout", "stderr", "user", "debug"]
240 ad76b118 Dimitris Aragiorgis
241 ad76b118 Dimitris Aragiorgis
  level_aliases = {
242 ad76b118 Dimitris Aragiorgis
    "output": ["stdout", "stderr"],
243 ad76b118 Dimitris Aragiorgis
    "everything": ["warnings", "running", "user", "output"]
244 ad76b118 Dimitris Aragiorgis
    }
245 ad76b118 Dimitris Aragiorgis
246 ad76b118 Dimitris Aragiorgis
  hide = ",".join(level_aliases["everything"])
247 ad76b118 Dimitris Aragiorgis
  show = None
248 ad76b118 Dimitris Aragiorgis
249 ad76b118 Dimitris Aragiorgis
  if args.verbose == 1:
250 ad76b118 Dimitris Aragiorgis
    show = ",".join(levels[:3])
251 ad76b118 Dimitris Aragiorgis
    hide = ",".join(levels[3:])
252 ad76b118 Dimitris Aragiorgis
  elif args.verbose == 2:
253 ad76b118 Dimitris Aragiorgis
    show = ",".join(levels[:4])
254 ad76b118 Dimitris Aragiorgis
    hide = ",".join(levels[4:])
255 ad76b118 Dimitris Aragiorgis
  elif args.verbose >= 3 or args.debug:
256 ad76b118 Dimitris Aragiorgis
    show = ",".join(levels)
257 ad76b118 Dimitris Aragiorgis
    hide = None
258 ad76b118 Dimitris Aragiorgis
259 ad76b118 Dimitris Aragiorgis
  if args.ssh_key:
260 ad76b118 Dimitris Aragiorgis
    fabcmd = "fab -i %s " % args.ssh_key
261 ad76b118 Dimitris Aragiorgis
  else:
262 ad76b118 Dimitris Aragiorgis
    fabcmd = "fab "
263 ad76b118 Dimitris Aragiorgis
264 ad76b118 Dimitris Aragiorgis
  fabcmd += " --fabfile {4}/fabfile.py \
265 b7c00e75 Dionysis Grigoropoulos
setup_env:confdir={0},packages={1},templates={2},cluster_name={3},\
266 e5b4db06 Dimitris Aragiorgis
autoconf={5},disable_colors={6},key_inject={7} \
267 b7c00e75 Dionysis Grigoropoulos
".format(args.confdir, env.packages, env.templates, args.cluster_name,
268 e5b4db06 Dimitris Aragiorgis
         env.lib, args.autoconf, args.disable_colors, args.key_inject)
269 ad76b118 Dimitris Aragiorgis
270 ad76b118 Dimitris Aragiorgis
  if nodes:
271 ad76b118 Dimitris Aragiorgis
    hosts = [env.nodes_info[n].hostname for n in nodes]
272 ad76b118 Dimitris Aragiorgis
    actions = [a + ':hosts="%s"' % ";".join(hosts) for a in actions]
273 ad76b118 Dimitris Aragiorgis
274 ad76b118 Dimitris Aragiorgis
  extra = " ".join(actions)
275 ad76b118 Dimitris Aragiorgis
276 ad76b118 Dimitris Aragiorgis
  fabcmd += extra
277 ad76b118 Dimitris Aragiorgis
278 ad76b118 Dimitris Aragiorgis
  if show:
279 ad76b118 Dimitris Aragiorgis
    fabcmd += " --show %s " % show
280 ad76b118 Dimitris Aragiorgis
  if hide:
281 ad76b118 Dimitris Aragiorgis
    fabcmd += " --hide %s " % hide
282 ad76b118 Dimitris Aragiorgis
283 ad76b118 Dimitris Aragiorgis
  # print("snf-deploy run " + " ".join(actions) + " -vvv")
284 ad76b118 Dimitris Aragiorgis
  print(fabcmd)
285 ad76b118 Dimitris Aragiorgis
286 ad76b118 Dimitris Aragiorgis
  if not args.dry_run:
287 ad76b118 Dimitris Aragiorgis
    os.system(fabcmd)
288 ad76b118 Dimitris Aragiorgis
289 ad76b118 Dimitris Aragiorgis
290 ad76b118 Dimitris Aragiorgis
def cluster(args, env):
291 ad76b118 Dimitris Aragiorgis
  for hostname, mac in env.node2mac.iteritems():
292 ad76b118 Dimitris Aragiorgis
    launch_vm(args, env, hostname, mac)
293 ad76b118 Dimitris Aragiorgis
294 ad76b118 Dimitris Aragiorgis
  time.sleep(30)
295 ad76b118 Dimitris Aragiorgis
  os.system("reset")
296 ad76b118 Dimitris Aragiorgis
297 ad76b118 Dimitris Aragiorgis
298 ad76b118 Dimitris Aragiorgis
def launch_vm(args, env, hostname, mac):
299 ad76b118 Dimitris Aragiorgis
  check_pidfile("%s/%s.pid" % (env.run, hostname))
300 ad76b118 Dimitris Aragiorgis
301 ad76b118 Dimitris Aragiorgis
  print("Launching cluster node {0}..".format(hostname))
302 ad76b118 Dimitris Aragiorgis
  os.environ["BRIDGE"] = env.bridge
303 ad76b118 Dimitris Aragiorgis
  if args.vnc:
304 ad76b118 Dimitris Aragiorgis
    graphics = "-vnc :{0}".format(random.randint(1, 1000))
305 ad76b118 Dimitris Aragiorgis
  else:
306 ad76b118 Dimitris Aragiorgis
    graphics = "-nographic"
307 ad76b118 Dimitris Aragiorgis
308 ad76b118 Dimitris Aragiorgis
  disks = """ \
309 ad76b118 Dimitris Aragiorgis
-drive file={0}/{1}.disk0,format=raw,if=none,id=drive0,snapshot=on \
310 ad76b118 Dimitris Aragiorgis
-device virtio-blk-pci,drive=drive0,id=virtio-blk-pci.0 \
311 ad76b118 Dimitris Aragiorgis
  """.format(env.images, env.os)
312 ad76b118 Dimitris Aragiorgis
313 ad76b118 Dimitris Aragiorgis
  if ast.literal_eval(env.create_extra_disk):
314 ad76b118 Dimitris Aragiorgis
    disks += """ \
315 ad76b118 Dimitris Aragiorgis
-drive file={0}/{1}.disk1,format=raw,if=none,id=drive1,snapshot=on \
316 ad76b118 Dimitris Aragiorgis
-device virtio-blk-pci,drive=drive1,id=virtio-blk-pci.1 \
317 ad76b118 Dimitris Aragiorgis
  """.format(env.images, env.os)
318 ad76b118 Dimitris Aragiorgis
319 ad76b118 Dimitris Aragiorgis
320 ad76b118 Dimitris Aragiorgis
  ifup = env.lib + "/ifup"
321 ad76b118 Dimitris Aragiorgis
  nics = """ \
322 ad76b118 Dimitris Aragiorgis
-netdev tap,id=netdev0,script={0},downscript=no \
323 ad76b118 Dimitris Aragiorgis
-device virtio-net-pci,mac={1},netdev=netdev0,id=virtio-net-pci.0 \
324 ad76b118 Dimitris Aragiorgis
-netdev tap,id=netdev1,script={0},downscript=no \
325 ad76b118 Dimitris Aragiorgis
-device virtio-net-pci,mac={2},netdev=netdev1,id=virtio-net-pci.1 \
326 ad76b118 Dimitris Aragiorgis
-netdev tap,id=netdev2,script={0},downscript=no \
327 ad76b118 Dimitris Aragiorgis
-device virtio-net-pci,mac={3},netdev=netdev2,id=virtio-net-pci.2 \
328 ad76b118 Dimitris Aragiorgis
  """.format(ifup, mac, randomMAC(), randomMAC())
329 ad76b118 Dimitris Aragiorgis
330 ad76b118 Dimitris Aragiorgis
  cmd = """
331 ad76b118 Dimitris Aragiorgis
/usr/bin/kvm -name {0} -pidfile {1}/{0}.pid -balloon virtio -daemonize \
332 ad76b118 Dimitris Aragiorgis
-monitor unix:{1}/{0}.monitor,server,nowait -usbdevice tablet -boot c \
333 ad76b118 Dimitris Aragiorgis
{2} \
334 ad76b118 Dimitris Aragiorgis
{3} \
335 ad76b118 Dimitris Aragiorgis
-m {4} -smp {5} {6} \
336 ad76b118 Dimitris Aragiorgis
  """.format(hostname, env.run, disks, nics, args.mem, args.smp, graphics)
337 ad76b118 Dimitris Aragiorgis
  print cmd
338 ad76b118 Dimitris Aragiorgis
  os.system(cmd)
339 ad76b118 Dimitris Aragiorgis
340 ad76b118 Dimitris Aragiorgis
341 ad76b118 Dimitris Aragiorgis
def dnsmasq(args, env):
342 ad76b118 Dimitris Aragiorgis
  check_pidfile(env.run + "/dnsmasq.pid")
343 ad76b118 Dimitris Aragiorgis
  cmd = "dnsmasq --pid-file={0}/dnsmasq.pid --conf-file={1}/conf-file".format(env.run, env.dns)
344 ad76b118 Dimitris Aragiorgis
  os.system(cmd)
345 ad76b118 Dimitris Aragiorgis
346 ad76b118 Dimitris Aragiorgis
347 ad76b118 Dimitris Aragiorgis
def get_packages(args, env):
348 ad76b118 Dimitris Aragiorgis
  if env.package_url:
349 ad76b118 Dimitris Aragiorgis
    os.system("rm {0}/*.deb".format(env.packages))
350 ad76b118 Dimitris Aragiorgis
    os.system("wget -r --level=1 -nH --no-parent --cut-dirs=4 {0} -P {1}".format(env.package_url, env.packages))
351 ad76b118 Dimitris Aragiorgis
352 ad76b118 Dimitris Aragiorgis
353 ad76b118 Dimitris Aragiorgis
def parse_options():
354 ad76b118 Dimitris Aragiorgis
  parser = argparse.ArgumentParser()
355 ad76b118 Dimitris Aragiorgis
356 ad76b118 Dimitris Aragiorgis
  # Directories to load/store config
357 ad76b118 Dimitris Aragiorgis
  parser.add_argument("-c", dest="confdir",
358 ad76b118 Dimitris Aragiorgis
                      default="/etc/snf-deploy",
359 ad76b118 Dimitris Aragiorgis
                      help="Directory to find default configuration")
360 ad76b118 Dimitris Aragiorgis
  parser.add_argument("--dry-run", dest="dry_run",
361 ad76b118 Dimitris Aragiorgis
                      default=False, action="store_true",
362 ad76b118 Dimitris Aragiorgis
                      help="Do not execute or write anything.")
363 ad76b118 Dimitris Aragiorgis
  parser.add_argument("-v", dest="verbose",
364 ad76b118 Dimitris Aragiorgis
                      default=0, action="count",
365 ad76b118 Dimitris Aragiorgis
                      help="Increase verbosity.")
366 ad76b118 Dimitris Aragiorgis
  parser.add_argument("-d", dest="debug",
367 ad76b118 Dimitris Aragiorgis
                      default=False, action="store_true",
368 ad76b118 Dimitris Aragiorgis
                      help="Debug mode")
369 ad76b118 Dimitris Aragiorgis
  parser.add_argument("--autoconf", dest="autoconf",
370 ad76b118 Dimitris Aragiorgis
                      default=False, action="store_true",
371 ad76b118 Dimitris Aragiorgis
                      help="In case of all in one auto conf setup")
372 ad76b118 Dimitris Aragiorgis
373 ad76b118 Dimitris Aragiorgis
  # virtual cluster related options
374 ad76b118 Dimitris Aragiorgis
  parser.add_argument("--mem", dest="mem",
375 ad76b118 Dimitris Aragiorgis
                      default=2024,
376 ad76b118 Dimitris Aragiorgis
                      help="Memory for every virutal node")
377 ad76b118 Dimitris Aragiorgis
  parser.add_argument("--smp", dest="smp",
378 ad76b118 Dimitris Aragiorgis
                      default=1,
379 ad76b118 Dimitris Aragiorgis
                      help="Virtual CPUs for every virtual node")
380 ad76b118 Dimitris Aragiorgis
  parser.add_argument("--vnc", dest="vnc",
381 ad76b118 Dimitris Aragiorgis
                      default=False, action="store_true",
382 ad76b118 Dimitris Aragiorgis
                      help="Wheter virtual nodes will have a vnc console or not")
383 bbc3b7e7 Ilias Tsitsimpis
  parser.add_argument("--force", dest="force",
384 ad76b118 Dimitris Aragiorgis
                      default=False, action="store_true",
385 bbc3b7e7 Ilias Tsitsimpis
                      help="Force the creation of new ssh key pairs")
386 ad76b118 Dimitris Aragiorgis
387 ad76b118 Dimitris Aragiorgis
  parser.add_argument("-i", "--ssh-key", dest="ssh_key",
388 ad76b118 Dimitris Aragiorgis
                      default=None,
389 ad76b118 Dimitris Aragiorgis
                      help="Path of an existing ssh key to use")
390 ad76b118 Dimitris Aragiorgis
391 40d11d5f Dimitris Aragiorgis
  parser.add_argument("--no-key-inject", dest="key_inject",
392 40d11d5f Dimitris Aragiorgis
                      default=True, action="store_false",
393 40d11d5f Dimitris Aragiorgis
                      help="Whether to inject ssh key pairs to hosts")
394 40d11d5f Dimitris Aragiorgis
395 ad76b118 Dimitris Aragiorgis
  # backend related options
396 ad76b118 Dimitris Aragiorgis
  parser.add_argument("--cluster-name", dest="cluster_name",
397 ad76b118 Dimitris Aragiorgis
                      default="ganeti1",
398 ad76b118 Dimitris Aragiorgis
                      help="The cluster name in ganeti.conf")
399 ad76b118 Dimitris Aragiorgis
400 ad76b118 Dimitris Aragiorgis
  # backend related options
401 ad76b118 Dimitris Aragiorgis
  parser.add_argument("--cluster-node", dest="cluster_node",
402 ad76b118 Dimitris Aragiorgis
                      default=None,
403 ad76b118 Dimitris Aragiorgis
                      help="The node to add to the existing cluster")
404 ad76b118 Dimitris Aragiorgis
405 ad76b118 Dimitris Aragiorgis
  # available commands
406 ad76b118 Dimitris Aragiorgis
  parser.add_argument("command", type=str,
407 ad76b118 Dimitris Aragiorgis
                      choices=["packages", "vcluster", "prepare",
408 ad76b118 Dimitris Aragiorgis
                               "synnefo", "backend", "ganeti",
409 ad76b118 Dimitris Aragiorgis
                               "run", "cleanup", "test",
410 bbc3b7e7 Ilias Tsitsimpis
                               "all", "add", "keygen"],
411 ad76b118 Dimitris Aragiorgis
                      help="Run on of the supported deployment commands")
412 ad76b118 Dimitris Aragiorgis
413 ad76b118 Dimitris Aragiorgis
  # available actions for the run command
414 ad76b118 Dimitris Aragiorgis
  parser.add_argument("actions", type=str, nargs="*",
415 ad76b118 Dimitris Aragiorgis
                      help="Run one or more of the supported subcommands")
416 ad76b118 Dimitris Aragiorgis
417 b7c00e75 Dionysis Grigoropoulos
  # disable colors in terminal
418 b7c00e75 Dionysis Grigoropoulos
  parser.add_argument("--disable-colors", dest="disable_colors", default=False,
419 b7c00e75 Dionysis Grigoropoulos
                      action="store_true", help="Disable colors in terminal")
420 b7c00e75 Dionysis Grigoropoulos
421 ad76b118 Dimitris Aragiorgis
  return parser.parse_args()
422 ad76b118 Dimitris Aragiorgis
423 b7c00e75 Dionysis Grigoropoulos
424 ad76b118 Dimitris Aragiorgis
def get_actions(*args):
425 ad76b118 Dimitris Aragiorgis
    actions = {
426 ad76b118 Dimitris Aragiorgis
      # prepare actions
427 ad76b118 Dimitris Aragiorgis
      "ns":  ["setup_ns", "setup_resolv_conf"],
428 ad76b118 Dimitris Aragiorgis
      "hosts": ["setup_hosts", "add_keys"],
429 ad76b118 Dimitris Aragiorgis
      "check": ["check_dhcp", "check_dns", "check_connectivity", "check_ssh"],
430 ad76b118 Dimitris Aragiorgis
      "apt": ["apt_get_update", "setup_apt"],
431 ad76b118 Dimitris Aragiorgis
      "nfs": ["setup_nfs_server", "setup_nfs_clients"],
432 ad76b118 Dimitris Aragiorgis
      "prepare":  [
433 ad76b118 Dimitris Aragiorgis
        "setup_hosts", "add_keys",
434 ad76b118 Dimitris Aragiorgis
        "setup_ns", "setup_resolv_conf",
435 ad76b118 Dimitris Aragiorgis
        "check_dhcp", "check_dns", "check_connectivity", "check_ssh",
436 ad76b118 Dimitris Aragiorgis
        "apt_get_update", "setup_apt",
437 ad76b118 Dimitris Aragiorgis
        "setup_nfs_server", "setup_nfs_clients"
438 ad76b118 Dimitris Aragiorgis
        ],
439 ad76b118 Dimitris Aragiorgis
      # synnefo actions
440 ad76b118 Dimitris Aragiorgis
      "synnefo": [
441 ad76b118 Dimitris Aragiorgis
        "setup_mq", "setup_db",
442 ad76b118 Dimitris Aragiorgis
        "setup_astakos",
443 ad76b118 Dimitris Aragiorgis
        #TODO: astakos-quota fails if no user is added.
444 ad76b118 Dimitris Aragiorgis
        #      add_user fails if no groups found
445 b29b8213 Christos Stavrakakis
        "astakos_loaddata", "add_user", "activate_user",
446 b29b8213 Christos Stavrakakis
        "astakos_register_components",
447 ad76b118 Dimitris Aragiorgis
        "setup_cms", "cms_loaddata",
448 ad76b118 Dimitris Aragiorgis
        "setup_pithos",
449 b29b8213 Christos Stavrakakis
        "setup_cyclades", "cyclades_loaddata", "add_pools",
450 b29b8213 Christos Stavrakakis
        "export_services", "import_services", "setup_vncauthproxy",
451 ad76b118 Dimitris Aragiorgis
        "setup_kamaki", "upload_image", "register_image",
452 ad76b118 Dimitris Aragiorgis
        "setup_burnin"
453 ad76b118 Dimitris Aragiorgis
        ],
454 ad76b118 Dimitris Aragiorgis
      "supdate": [
455 ad76b118 Dimitris Aragiorgis
        "apt_get_update", "setup_astakos",
456 ad76b118 Dimitris Aragiorgis
        "setup_cms", "setup_pithos", "setup_cyclades"
457 ad76b118 Dimitris Aragiorgis
        ],
458 ad76b118 Dimitris Aragiorgis
      # backend actions
459 ad76b118 Dimitris Aragiorgis
      "backend": [
460 ad76b118 Dimitris Aragiorgis
        "update_ns_for_ganeti",
461 ad76b118 Dimitris Aragiorgis
        "setup_ganeti", "init_cluster",
462 ad76b118 Dimitris Aragiorgis
        "add_rapi_user", "add_nodes",
463 ad76b118 Dimitris Aragiorgis
        "setup_image_host", "setup_image_helper",
464 ad76b118 Dimitris Aragiorgis
        "setup_network",
465 ad76b118 Dimitris Aragiorgis
        "setup_gtools", "add_backend", "add_network",
466 ad76b118 Dimitris Aragiorgis
        "setup_lvm", "enable_lvm",
467 ad76b118 Dimitris Aragiorgis
        "enable_drbd", "setup_drbd_dparams",
468 ad76b118 Dimitris Aragiorgis
        "setup_net_infra", "setup_iptables", "setup_router",
469 ad76b118 Dimitris Aragiorgis
        ],
470 ad76b118 Dimitris Aragiorgis
      "bstorage": [
471 ad76b118 Dimitris Aragiorgis
        "setup_lvm", "enable_lvm",
472 ad76b118 Dimitris Aragiorgis
        "enable_drbd", "setup_drbd_dparams"
473 ad76b118 Dimitris Aragiorgis
        ],
474 ad76b118 Dimitris Aragiorgis
      "bnetwork": ["setup_net_infra", "setup_iptables", "setup_router"],
475 ad76b118 Dimitris Aragiorgis
      "bupdate": [
476 ad76b118 Dimitris Aragiorgis
        "apt_get_update", "setup_ganeti", "setup_image_host", "setup_image_helper",
477 ad76b118 Dimitris Aragiorgis
        "setup_network", "setup_gtools"
478 ad76b118 Dimitris Aragiorgis
        ],
479 ad76b118 Dimitris Aragiorgis
      # ganeti actions
480 ad76b118 Dimitris Aragiorgis
      "ganeti": [
481 ad76b118 Dimitris Aragiorgis
        "update_ns_for_ganeti",
482 ad76b118 Dimitris Aragiorgis
        "setup_ganeti", "init_cluster", "add_nodes",
483 ad76b118 Dimitris Aragiorgis
        "setup_image_host", "setup_image_helper", "add_image_locally",
484 ad76b118 Dimitris Aragiorgis
        "debootstrap", "setup_net_infra",
485 ad76b118 Dimitris Aragiorgis
        "setup_lvm", "enable_lvm", "enable_drbd", "setup_drbd_dparams",
486 ad76b118 Dimitris Aragiorgis
        ],
487 ad76b118 Dimitris Aragiorgis
      "gupdate": ["setup_apt", "setup_ganeti"],
488 ad76b118 Dimitris Aragiorgis
      "gdestroy": ["destroy_cluster"],
489 ad76b118 Dimitris Aragiorgis
      }
490 ad76b118 Dimitris Aragiorgis
491 ad76b118 Dimitris Aragiorgis
    ret = []
492 ad76b118 Dimitris Aragiorgis
    for x in args:
493 ad76b118 Dimitris Aragiorgis
      ret += actions[x]
494 ad76b118 Dimitris Aragiorgis
495 ad76b118 Dimitris Aragiorgis
    return ret
496 ad76b118 Dimitris Aragiorgis
497 ad76b118 Dimitris Aragiorgis
498 bbc3b7e7 Ilias Tsitsimpis
def must_create_keys(force, env):
499 bbc3b7e7 Ilias Tsitsimpis
    """Check if we need to create ssh keys
500 bbc3b7e7 Ilias Tsitsimpis

501 bbc3b7e7 Ilias Tsitsimpis
    If force is true we are going to overide the old keys.
502 bbc3b7e7 Ilias Tsitsimpis
    Else if there are already generated keys to use, don't create new ones.
503 bbc3b7e7 Ilias Tsitsimpis

504 bbc3b7e7 Ilias Tsitsimpis
    """
505 bbc3b7e7 Ilias Tsitsimpis
    if force:
506 bbc3b7e7 Ilias Tsitsimpis
        return True
507 bbc3b7e7 Ilias Tsitsimpis
    d = os.path.join(env.templates, "root/.ssh")
508 bbc3b7e7 Ilias Tsitsimpis
    auth_keys_exists = os.path.exists(os.path.join(d, "authorized_keys"))
509 bbc3b7e7 Ilias Tsitsimpis
    dsa_exists = os.path.exists(os.path.join(d, "id_dsa"))
510 bbc3b7e7 Ilias Tsitsimpis
    dsa_pub_exists = os.path.exists(os.path.join(d, "id_dsa.pub"))
511 bbc3b7e7 Ilias Tsitsimpis
    rsa_exists = os.path.exists(os.path.join(d, "id_rsa"))
512 bbc3b7e7 Ilias Tsitsimpis
    rsa_pub_exists = os.path.exists(os.path.join(d, "id_rsa.pub"))
513 bbc3b7e7 Ilias Tsitsimpis
    # If any of the above doesn't exist return True
514 bbc3b7e7 Ilias Tsitsimpis
    return not (dsa_exists and dsa_pub_exists
515 bbc3b7e7 Ilias Tsitsimpis
                and rsa_exists and rsa_pub_exists
516 bbc3b7e7 Ilias Tsitsimpis
                and auth_keys_exists)
517 bbc3b7e7 Ilias Tsitsimpis
518 bbc3b7e7 Ilias Tsitsimpis
519 bbc3b7e7 Ilias Tsitsimpis
def do_create_keys(args, env):
520 ad76b118 Dimitris Aragiorgis
  d = os.path.join(env.templates, "root/.ssh")
521 ad76b118 Dimitris Aragiorgis
  a = os.path.join(d, "authorized_keys")
522 ad76b118 Dimitris Aragiorgis
  for t in ("dsa", "rsa"):
523 ad76b118 Dimitris Aragiorgis
    f = os.path.join(d, "id_" + t)
524 ad76b118 Dimitris Aragiorgis
    cmd = 'ssh-keygen -q -t {0} -f {1} -N ""'.format(t, f)
525 ad76b118 Dimitris Aragiorgis
    os.system(cmd)
526 ad76b118 Dimitris Aragiorgis
    cmd = 'cat {0}.pub >> {1}'.format(f, a)
527 ad76b118 Dimitris Aragiorgis
    os.system(cmd)
528 ad76b118 Dimitris Aragiorgis
529 ad76b118 Dimitris Aragiorgis
def add_node(args, env):
530 ad76b118 Dimitris Aragiorgis
    actions = [
531 ad76b118 Dimitris Aragiorgis
      "update_ns_for_node:" + args.cluster_node,
532 ad76b118 Dimitris Aragiorgis
      ]
533 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions)
534 ad76b118 Dimitris Aragiorgis
    actions = [
535 ad76b118 Dimitris Aragiorgis
      "setup_resolv_conf",
536 ad76b118 Dimitris Aragiorgis
      "apt_get_update",
537 ad76b118 Dimitris Aragiorgis
      "setup_apt",
538 ad76b118 Dimitris Aragiorgis
      "setup_hosts",
539 ad76b118 Dimitris Aragiorgis
      "add_keys",
540 ad76b118 Dimitris Aragiorgis
      ]
541 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions, [args.cluster_node])
542 ad76b118 Dimitris Aragiorgis
543 ad76b118 Dimitris Aragiorgis
    actions = get_actions("check")
544 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions)
545 ad76b118 Dimitris Aragiorgis
546 ad76b118 Dimitris Aragiorgis
    actions = [
547 ad76b118 Dimitris Aragiorgis
      "setup_nfs_clients",
548 ad76b118 Dimitris Aragiorgis
      "setup_ganeti",
549 ad76b118 Dimitris Aragiorgis
      "setup_image_host", "setup_image_helper", "setup_network", "setup_gtools",
550 ad76b118 Dimitris Aragiorgis
      ]
551 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions, [args.cluster_node])
552 ad76b118 Dimitris Aragiorgis
553 ad76b118 Dimitris Aragiorgis
    actions = [
554 ad76b118 Dimitris Aragiorgis
      "add_node:" + args.cluster_node,
555 ad76b118 Dimitris Aragiorgis
      ]
556 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions)
557 ad76b118 Dimitris Aragiorgis
558 ad76b118 Dimitris Aragiorgis
    actions = [
559 ad76b118 Dimitris Aragiorgis
      "setup_lvm", "enable_drbd",
560 ad76b118 Dimitris Aragiorgis
      "setup_net_infra", "setup_iptables",
561 ad76b118 Dimitris Aragiorgis
      ]
562 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions, [args.cluster_node])
563 ad76b118 Dimitris Aragiorgis
564 ad76b118 Dimitris Aragiorgis
def main():
565 ad76b118 Dimitris Aragiorgis
  args = parse_options()
566 ad76b118 Dimitris Aragiorgis
567 ad76b118 Dimitris Aragiorgis
  conf = Conf.configure(args.confdir, args.cluster_name, args, args.autoconf)
568 ad76b118 Dimitris Aragiorgis
  env = Env(conf)
569 ad76b118 Dimitris Aragiorgis
570 ad76b118 Dimitris Aragiorgis
  create_dir(env.run, False)
571 ad76b118 Dimitris Aragiorgis
  create_dir(env.dns, False)
572 ad76b118 Dimitris Aragiorgis
573 bbc3b7e7 Ilias Tsitsimpis
  # Check if there are keys to use
574 bbc3b7e7 Ilias Tsitsimpis
  if args.command == "keygen":
575 bbc3b7e7 Ilias Tsitsimpis
    if must_create_keys(args.force, env):
576 bbc3b7e7 Ilias Tsitsimpis
      do_create_keys(args, env)
577 bbc3b7e7 Ilias Tsitsimpis
      return 0
578 bbc3b7e7 Ilias Tsitsimpis
    else:
579 bbc3b7e7 Ilias Tsitsimpis
      print "Keys already existed.. aborting"
580 bbc3b7e7 Ilias Tsitsimpis
      return 1
581 bbc3b7e7 Ilias Tsitsimpis
  else:
582 bbc3b7e7 Ilias Tsitsimpis
    if (args.key_inject and (args.ssh_key is None)
583 bbc3b7e7 Ilias Tsitsimpis
        and must_create_keys(False, env)):
584 bbc3b7e7 Ilias Tsitsimpis
      print "No ssh keys to use. Run `snf-deploy keygen' first."
585 bbc3b7e7 Ilias Tsitsimpis
      return 1
586 bbc3b7e7 Ilias Tsitsimpis
587 ad76b118 Dimitris Aragiorgis
  if args.command == "test":
588 ad76b118 Dimitris Aragiorgis
    conf.print_config()
589 ad76b118 Dimitris Aragiorgis
590 ad76b118 Dimitris Aragiorgis
  if args.command == "cleanup":
591 ad76b118 Dimitris Aragiorgis
    cleanup(args, env)
592 ad76b118 Dimitris Aragiorgis
593 ad76b118 Dimitris Aragiorgis
  if args.command == "packages":
594 ad76b118 Dimitris Aragiorgis
    create_dir(env.packages, True)
595 ad76b118 Dimitris Aragiorgis
    get_packages(args, env)
596 ad76b118 Dimitris Aragiorgis
597 ad76b118 Dimitris Aragiorgis
  if args.command == "vcluster":
598 ad76b118 Dimitris Aragiorgis
    image(args, env)
599 ad76b118 Dimitris Aragiorgis
    network(args, env)
600 ad76b118 Dimitris Aragiorgis
    create_dnsmasq_files(args, env)
601 ad76b118 Dimitris Aragiorgis
    dnsmasq(args, env)
602 ad76b118 Dimitris Aragiorgis
    cluster(args, env)
603 ad76b118 Dimitris Aragiorgis
604 ad76b118 Dimitris Aragiorgis
  if args.command == "prepare":
605 ad76b118 Dimitris Aragiorgis
    actions = get_actions("prepare")
606 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions)
607 ad76b118 Dimitris Aragiorgis
608 ad76b118 Dimitris Aragiorgis
  if args.command == "synnefo":
609 ad76b118 Dimitris Aragiorgis
    actions = get_actions("synnefo")
610 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions)
611 ad76b118 Dimitris Aragiorgis
612 ad76b118 Dimitris Aragiorgis
  if args.command == "backend":
613 ad76b118 Dimitris Aragiorgis
    actions = get_actions("backend")
614 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions)
615 ad76b118 Dimitris Aragiorgis
616 ad76b118 Dimitris Aragiorgis
  if args.command == "ganeti":
617 ad76b118 Dimitris Aragiorgis
    actions += get_actions("ganeti")
618 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions)
619 ad76b118 Dimitris Aragiorgis
620 ad76b118 Dimitris Aragiorgis
621 ad76b118 Dimitris Aragiorgis
622 ad76b118 Dimitris Aragiorgis
623 ad76b118 Dimitris Aragiorgis
  if args.command == "all":
624 ad76b118 Dimitris Aragiorgis
    actions = get_actions("prepare", "synnefo", "backend")
625 ad76b118 Dimitris Aragiorgis
    fabcommand(args, env, actions)
626 ad76b118 Dimitris Aragiorgis
627 ad76b118 Dimitris Aragiorgis
  if args.command == "add":
628 ad76b118 Dimitris Aragiorgis
    if args.cluster_node:
629 ad76b118 Dimitris Aragiorgis
      add_node(args, env)
630 ad76b118 Dimitris Aragiorgis
    else:
631 ad76b118 Dimitris Aragiorgis
      actions = get_actions("backend")
632 ad76b118 Dimitris Aragiorgis
      fabcommand(args, env, actions)
633 ad76b118 Dimitris Aragiorgis
634 ad76b118 Dimitris Aragiorgis
635 ad76b118 Dimitris Aragiorgis
  if args.command == "run":
636 ad76b118 Dimitris Aragiorgis
    if not args.actions:
637 ad76b118 Dimitris Aragiorgis
      print_available_actions(args.command)
638 ad76b118 Dimitris Aragiorgis
    else:
639 ad76b118 Dimitris Aragiorgis
      fabcommand(args, env, args.actions)
640 ad76b118 Dimitris Aragiorgis
641 ad76b118 Dimitris Aragiorgis
642 ad76b118 Dimitris Aragiorgis
if __name__ == "__main__":
643 ad76b118 Dimitris Aragiorgis
  sys.exit(main())