Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (19 kB)

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

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

25 4b36944e Ilias Tsitsimpis
  """
26 4b36944e Ilias Tsitsimpis
27 0ac84a9a Dimitris Aragiorgis
  if command == "vcluster":
28 0ac84a9a Dimitris Aragiorgis
    print """
29 0ac84a9a Dimitris Aragiorgis
Usage: snf-deploy vcluster
30 0ac84a9a Dimitris Aragiorgis

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

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

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

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

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

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

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

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

66 0ac84a9a Dimitris Aragiorgis
    or
67 0ac84a9a Dimitris Aragiorgis

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

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

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

78 0ac84a9a Dimitris Aragiorgis

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

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

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

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