Statistics
| Branch: | Tag: | Revision:

root / snf-deploy / fabfile.py @ 703d78d6

History | View | Annotate | Download (37.7 kB)

1
from __future__ import with_statement
2
from fabric.api import *
3
from fabric.contrib.console import confirm
4
from random import choice
5
from fabric.operations import run, put
6
import re
7
import shutil, os
8
from functools import wraps
9
import imp
10
import ConfigParser
11
import sys
12
import tempfile
13
import ast
14
from snfdeploy.lib import *
15
from snfdeploy import massedit
16

    
17

    
18
def setup_env(confdir="conf", packages="packages",
19
              templates="files", cluster_name="ganeti1", autoconf=False, disable_colors=False, key_inject=False):
20
    print("Loading configuration for synnefo...")
21
    print(" * Using config files under %s..." % confdir)
22
    print(" * Using %s and %s for packages and templates accordingly..." % (packages, templates))
23

    
24
    autoconf = ast.literal_eval(autoconf)
25
    disable_colors = ast.literal_eval(disable_colors)
26
    env.key_inject = ast.literal_eval(key_inject)
27
    conf = Conf.configure(confdir=confdir, cluster_name=cluster_name, autoconf=autoconf)
28
    env.env = Env(conf)
29

    
30
    env.local = autoconf
31
    env.password = env.env.password
32
    env.user = env.env.user
33
    env.shell = "/bin/bash -c"
34

    
35
    if disable_colors:
36
        disable_color()
37

    
38
    if env.env.cms.hostname in [env.env.accounts.hostname, env.env.cyclades.hostname, env.env.pithos.hostname]:
39
      env.cms_pass = True
40
    else:
41
      env.cms_pass = False
42

    
43
    if env.env.accounts.hostname in [env.env.cyclades.hostname, env.env.pithos.hostname]:
44
      env.csrf_disable = True
45
    else:
46
      env.csrf_disable = False
47

    
48

    
49
    env.roledefs = {
50
        "nodes": env.env.ips,
51
        "ips": env.env.ips,
52
        "accounts": [env.env.accounts.ip],
53
        "cyclades": [env.env.cyclades.ip],
54
        "pithos": [env.env.pithos.ip],
55
        "cms": [env.env.cms.ip],
56
        "mq": [env.env.mq.ip],
57
        "db": [env.env.db.ip],
58
        "ns": [env.env.ns.ip],
59
        "client": [env.env.client.ip],
60
        "router": [env.env.router.ip],
61
    }
62

    
63
    env.enable_lvm = False
64
    env.enable_drbd = False
65
    if ast.literal_eval(env.env.create_extra_disk) and env.env.extra_disk:
66
        env.enable_lvm = True
67
        env.enable_drbd = True
68

    
69
    env.roledefs.update({
70
        "ganeti": env.env.cluster_ips,
71
        "master": [env.env.master.ip],
72
    })
73

    
74

    
75
def install_package(package):
76
    debug(env.host, " * Installing package %s..." % package)
77
    APT_GET = "export DEBIAN_FRONTEND=noninteractive ;apt-get install -y --force-yes "
78

    
79
    if ast.literal_eval(env.env.use_local_packages):
80
        with settings(warn_only=True):
81
            deb = local("ls %s/%s*deb" % (env.env.packages, package))
82
            if deb:
83
                debug(env.host, " * Package %s found in %s..." % (package, env.env.packages))
84
                put(deb, "/tmp/")
85
                try_run("dpkg -i /tmp/%s*deb || " % package + APT_GET + "-f")
86
                try_run("rm /tmp/%s*deb" % package)
87
                return
88

    
89
    info = getattr(env.env, package)
90
    if info in ["stable", "squeeze-backports", "testing", "unstable"]:
91
        APT_GET += " -t %s %s " % (info, package)
92
    elif info:
93
        APT_GET += " %s=%s " % (package, info)
94
    else:
95
        APT_GET += package
96

    
97
    try_run(APT_GET)
98

    
99
    return
100

    
101

    
102
@roles("ns")
103
def update_ns_for_ganeti():
104
    debug(env.host, "Updating name server entries for backend %s..." % env.env.cluster.fqdn)
105
    update_arecord(env.env.cluster)
106
    update_ptrrecord(env.env.cluster)
107
    try_run("/etc/init.d/bind9 restart")
108

    
109

    
110
@roles("ns")
111
def update_ns_for_node(node):
112
    info = env.env.nodes_info.get(node)
113
    update_arecord(info)
114
    update_ptrrecord(info)
115
    try_run("/etc/init.d/bind9 restart")
116

    
117

    
118
@roles("ns")
119
def update_arecord(host):
120
    filename = "/etc/bind/zones/" + env.env.domain
121
    cmd = """
122
    echo '{0}' >> {1}
123
    """.format(host.arecord, filename)
124
    try_run(cmd)
125

    
126

    
127
@roles("ns")
128
def update_cnamerecord(host):
129
    filename = "/etc/bind/zones/" + env.env.domain
130
    cmd = """
131
    echo '{0}' >> {1}
132
    """.format(host.cnamerecord, filename)
133
    try_run(cmd)
134

    
135

    
136
@roles("ns")
137
def update_ptrrecord(host):
138
    filename = "/etc/bind/rev/synnefo.in-addr.arpa.zone"
139
    cmd = """
140
    echo '{0}' >> {1}
141
    """.format(host.ptrrecord, filename)
142
    try_run(cmd)
143

    
144
@roles("nodes")
145
def apt_get_update():
146
    debug(env.host, "apt-get update....")
147
    try_run("apt-get update")
148

    
149
@roles("ns")
150
def setup_ns():
151
    debug(env.host, "Setting up name server..")
152
    #WARNING: this should be remove after we are done
153
    # because gevent does pick randomly nameservers and google does
154
    # not know our setup!!!!!
155
    apt_get_update()
156
    install_package("bind9")
157
    tmpl = "/etc/bind/named.conf.local"
158
    replace = {
159
      "domain": env.env.domain,
160
      }
161
    custom = customize_settings_from_tmpl(tmpl, replace)
162
    put(custom, tmpl)
163

    
164
    try_run("mkdir -p /etc/bind/zones")
165
    tmpl = "/etc/bind/zones/example.com"
166
    replace = {
167
      "domain": env.env.domain,
168
      "ns_node_ip": env.env.ns.ip,
169
      }
170
    custom = customize_settings_from_tmpl(tmpl, replace)
171
    remote = "/etc/bind/zones/" + env.env.domain
172
    put(custom, remote)
173

    
174
    try_run("mkdir -p /etc/bind/rev")
175
    tmpl = "/etc/bind/rev/synnefo.in-addr.arpa.zone"
176
    replace = {
177
      "domain": env.env.domain,
178
      }
179
    custom = customize_settings_from_tmpl(tmpl, replace)
180
    put(custom, tmpl)
181

    
182
    tmpl = "/etc/bind/named.conf.options"
183
    replace = {
184
      "NODE_IPS": ";".join(env.env.ips),
185
      }
186
    custom = customize_settings_from_tmpl(tmpl, replace)
187
    put(custom, tmpl, mode=0644)
188

    
189
    for role, info in env.env.roles.iteritems():
190
        if role == "ns":
191
            continue
192
        update_cnamerecord(info)
193
    for node, info in env.env.nodes_info.iteritems():
194
        update_arecord(info)
195
        update_ptrrecord(info)
196

    
197
    try_run("/etc/init.d/bind9 restart")
198

    
199

    
200
@roles("nodes")
201
def check_dhcp():
202
    debug(env.host, "Checking IPs for synnefo..")
203
    for n, info in env.env.nodes_info.iteritems():
204
        try_run("ping -c 1 " + info.ip, True)
205

    
206
@roles("nodes")
207
def check_dns():
208
    debug(env.host, "Checking fqdns for synnefo..")
209
    for n, info in env.env.nodes_info.iteritems():
210
        try_run("ping -c 1 " + info.fqdn, True)
211

    
212
    for n, info in env.env.roles.iteritems():
213
        try_run("ping -c 1 " + info.fqdn, True)
214

    
215
@roles("nodes")
216
def check_connectivity():
217
    debug(env.host, "Checking internet connectivity..")
218
    try_run("ping -c 1 www.google.com", True)
219

    
220

    
221
@roles("nodes")
222
def check_ssh():
223
    debug(env.host, "Checking password-less ssh..")
224
    for n, info in env.env.nodes_info.iteritems():
225
        try_run("ssh " + info.fqdn + "  date", True)
226

    
227

    
228
@roles("ips")
229
def add_keys():
230
    if not env.key_inject:
231
      debug(env.host, "Skipping ssh keys injection..")
232
      return
233
    else:
234
      debug(env.host, "Adding rsa/dsa keys..")
235
    try_run("mkdir -p /root/.ssh")
236
    cmd = """
237
for f in $(ls /root/.ssh/*); do
238
  cp $f $f.bak
239
done
240
    """
241
    try_run(cmd)
242
    files = ["authorized_keys", "id_dsa", "id_dsa.pub",
243
             "id_rsa", "id_rsa.pub"]
244
    for f in files:
245
      tmpl = "/root/.ssh/" + f
246
      replace = {}
247
      custom = customize_settings_from_tmpl(tmpl, replace)
248
      put(custom, tmpl, mode=0600)
249

    
250
    cmd = """
251
if [ -e /root/.ssh/authorized_keys.bak ]; then
252
  cat /root/.ssh/authorized_keys.bak >> /root/.ssh/authorized_keys
253
fi
254
    """
255
    debug(env.host, "Updating exising authorized keys..")
256
    try_run(cmd)
257

    
258
@roles("ips")
259
def setup_resolv_conf():
260
    debug(env.host, "Tweak /etc/resolv.conf...")
261
    try_run("/etc/init.d/network-manager stop")
262
    tmpl = "/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate"
263
    replace = {}
264
    custom = customize_settings_from_tmpl(tmpl, replace)
265
    put(custom, tmpl, mode=0644)
266
    try_run("cp /etc/resolv.conf /etc/resolv.conf.bak")
267
    tmpl = "/etc/resolv.conf"
268
    replace = {
269
      "domain": env.env.domain,
270
      "ns_node_ip": env.env.ns.ip,
271
      }
272
    custom = customize_settings_from_tmpl(tmpl, replace)
273
    try:
274
      put(custom, tmpl)
275
    except:
276
      pass
277
    try_run("chattr +i /etc/resolv.conf")
278

    
279

    
280
@roles("ips")
281
def setup_hosts():
282
    debug(env.host, "Tweaking /etc/hosts and ssh_config files...")
283
    try_run("echo StrictHostKeyChecking no >> /etc/ssh/ssh_config")
284
    cmd = " sed -i 's/^127.*/127.0.0.1 localhost/g' /etc/hosts "
285
    try_run(cmd)
286

    
287

    
288
def try_run(cmd, abort=False):
289
    try:
290
      if env.local:
291
        return local(cmd, capture=True)
292
      else:
293
        return run(cmd)
294
    except:
295
      debug(env.host, "WARNING: command failed. Continuing anyway...")
296
      if abort:
297
        raise
298

    
299
def create_bridges():
300
    debug(env.host, " * Creating bridges...")
301
    install_package("bridge-utils")
302
    cmd = """
303
    brctl addbr {0} ; ip link set {0} up
304
    """.format(env.env.common_bridge)
305
    try_run(cmd)
306

    
307

    
308
def connect_bridges():
309
    debug(env.host, " * Connecting bridges...")
310
    cmd = """
311
    brctl addif {0} {1}
312
    """.format(env.env.common_bridge, env.env.public_iface)
313
    #try_run(cmd)
314

    
315

    
316
@roles("ganeti")
317
def setup_net_infra():
318
    debug(env.host, "Setup networking infrastracture..")
319
    create_bridges()
320
    connect_bridges()
321

    
322

    
323
@roles("ganeti")
324
def setup_lvm():
325
    debug(env.host, "create volume group %s for ganeti.." % env.env.vg)
326
    if env.enable_lvm:
327
        install_package("lvm2")
328
        cmd = """
329
        pvcreate {0}
330
        vgcreate {1} {0}
331
        """.format(env.env.extra_disk, env.env.vg)
332
        try_run(cmd)
333

    
334

    
335
def customize_settings_from_tmpl(tmpl, replace):
336
    debug(env.host, " * Customizing template %s..." % tmpl)
337
    local = env.env.templates + tmpl
338
    _, custom = tempfile.mkstemp()
339
    shutil.copyfile(local, custom)
340
    for k, v in replace.iteritems():
341
        regex = "re.sub('%{0}%', '{1}', line)".format(k.upper(), v)
342
        massedit.edit_files([custom], [regex], dry_run=False)
343

    
344
    return custom
345

    
346

    
347
@roles("nodes")
348
def setup_apt():
349
    debug(env.host, "Setting up apt sources...")
350
    install_package("curl")
351
    cmd = """
352
    echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf
353
    curl -k https://dev.grnet.gr/files/apt-grnetdev.pub | apt-key add -
354
    """
355
    try_run(cmd)
356
    tmpl = "/etc/apt/sources.list.d/okeanos.list"
357
    replace = {}
358
    custom = customize_settings_from_tmpl(tmpl, replace)
359
    put(custom, tmpl)
360
    apt_get_update()
361

    
362

    
363
@roles("cyclades", "cms", "pithos", "accounts")
364
def restart_services():
365
    debug(env.host, " * Restarting apache2 and gunicorn...")
366
    try_run("/etc/init.d/gunicorn restart")
367
    try_run("/etc/init.d/apache2 restart")
368

    
369

    
370
def setup_gunicorn():
371
    debug(env.host, " * Setting up gunicorn...")
372
    install_package("gunicorn")
373
    tmpl = "/etc/gunicorn.d/synnefo"
374
    replace = {}
375
    custom = customize_settings_from_tmpl(tmpl, replace)
376
    put(custom, tmpl, mode=0644)
377
    try_run("/etc/init.d/gunicorn restart")
378

    
379

    
380
def setup_apache():
381
    debug(env.host, " * Setting up apache2...")
382
    host_info = env.env.ips_info[env.host]
383
    install_package("apache2")
384
    tmpl = "/etc/apache2/sites-available/synnefo"
385
    replace = {
386
        "HOST": host_info.fqdn,
387
    }
388
    custom = customize_settings_from_tmpl(tmpl, replace)
389
    put(custom, tmpl)
390
    tmpl = "/etc/apache2/sites-available/synnefo-ssl"
391
    custom = customize_settings_from_tmpl(tmpl, replace)
392
    put(custom, tmpl)
393
    cmd = """
394
    a2enmod ssl
395
    a2enmod rewrite
396
    a2dissite default
397
    a2ensite synnefo
398
    a2ensite synnefo-ssl
399
    a2enmod headers
400
    a2enmod proxy_http
401
    a2dismod autoindex
402
    """
403
    try_run(cmd)
404
    try_run("/etc/init.d/apache2 restart")
405

    
406

    
407
@roles("mq")
408
def setup_mq():
409
    debug(env.host, "Setting up RabbitMQ...")
410
    install_package("rabbitmq-server")
411
    cmd = """
412
    rabbitmqctl add_user {0} {1}
413
    rabbitmqctl set_permissions {0} ".*" ".*" ".*"
414
    rabbitmqctl delete_user guest
415
    rabbitmqctl set_user_tags {0} administrator
416
    """.format(env.env.synnefo_user, env.env.synnefo_rabbitmq_passwd)
417
    try_run(cmd)
418
    try_run("/etc/init.d/rabbitmq-server restart")
419

    
420

    
421
@roles("db")
422
def allow_access_in_db(ip, user="all", method="md5"):
423
    cmd = """
424
    echo host all {0} {1}/32 {2} >> /etc/postgresql/8.4/main/pg_hba.conf
425
    """.format(user, ip, method)
426
    try_run(cmd)
427
    try_run("/etc/init.d/postgresql restart")
428

    
429
@roles("db")
430
def setup_db():
431
    debug(env.host, "Setting up DataBase server...")
432
    install_package("postgresql")
433

    
434
    tmpl = "/tmp/db-init.psql"
435
    replace = {
436
        "synnefo_user": env.env.synnefo_user,
437
        "synnefo_db_passwd": env.env.synnefo_db_passwd,
438
        }
439
    custom = customize_settings_from_tmpl(tmpl, replace)
440
    put(custom, tmpl)
441
    cmd = 'su - postgres -c "psql -w -f %s" ' % tmpl
442
    try_run(cmd)
443
    cmd = """
444
    echo "listen_addresses = '*'" >> /etc/postgresql/8.4/main/postgresql.conf
445
    """
446
    try_run(cmd)
447

    
448
    allow_access_in_db(env.host, "all", "trust")
449
    try_run("/etc/init.d/postgresql restart")
450

    
451

    
452
@roles("db")
453
def destroy_db():
454
    try_run("""su - postgres -c ' psql -w -c "drop database snf_apps" '""")
455
    try_run("""su - postgres -c ' psql -w -c "drop database snf_pithos" '""")
456

    
457

    
458
def setup_webproject():
459
    debug(env.host, " * Setting up snf-webproject...")
460
    with settings(hide("everything")):
461
        try_run("ping -c1 " + env.env.db.ip)
462
    setup_common()
463
    install_package("snf-webproject")
464
    install_package("python-psycopg2")
465
    install_package("python-gevent")
466
    tmpl = "/etc/synnefo/webproject.conf"
467
    replace = {
468
        "synnefo_user": env.env.synnefo_user,
469
        "synnefo_db_passwd": env.env.synnefo_db_passwd,
470
        "db_node": env.env.db.ip,
471
        "domain": env.env.domain,
472
    }
473
    custom = customize_settings_from_tmpl(tmpl, replace)
474
    put(custom, tmpl, mode=0644)
475
    with settings(host_string=env.env.db.ip):
476
        host_info = env.env.ips_info[env.host]
477
        allow_access_in_db(host_info.ip, "all", "trust")
478
    try_run("/etc/init.d/gunicorn restart")
479

    
480

    
481
def setup_common():
482
    debug(env.host, " * Setting up snf-common...")
483
    host_info = env.env.ips_info[env.host]
484
    install_package("python-objpool")
485
    install_package("snf-common")
486
    install_package("python-astakosclient")
487
    install_package("snf-django-lib")
488
    install_package("snf-branding")
489
    tmpl = "/etc/synnefo/common.conf"
490
    replace = {
491
        #FIXME:
492
        "EMAIL_SUBJECT_PREFIX": env.host,
493
        "domain": env.env.domain,
494
        "HOST": host_info.fqdn,
495
    }
496
    custom = customize_settings_from_tmpl(tmpl, replace)
497
    put(custom, tmpl, mode=0644)
498
    try_run("/etc/init.d/gunicorn restart")
499

    
500
@roles("accounts")
501
def astakos_loaddata():
502
    debug(env.host, " * Loading initial data to astakos...")
503
    cmd = """
504
    snf-manage loaddata groups
505
    """
506
    try_run(cmd)
507

    
508

    
509
@roles("accounts")
510
def astakos_register_services():
511
    debug(env.host, " * Register services in astakos...")
512
    cmd = """
513
    snf-manage component-add "home" https://{0} home-icon.png
514
    snf-manage component-add "cyclades" https://{1}/cyclades/ui/
515
    snf-manage component-add "pithos" https://{2}/pithos/ui/
516
    snf-manage component-add "astakos" https://{3}/astakos/ui/
517
    """.format(env.env.cms.fqdn, env.env.cyclades.fqdn, env.env.pithos.fqdn, env.env.accounts.fqdn)
518
    try_run(cmd)
519
    import_service("astakos")
520
    import_service("pithos")
521
    import_service("cyclades")
522
    tmpl = "/tmp/resources.json"
523
    replace = {}
524
    custom = customize_settings_from_tmpl(tmpl, replace)
525
    put(custom, tmpl)
526
    try_run("snf-manage resource-import --json %s" % tmpl)
527
    cmd = """
528
    snf-manage resource-modify --limit 40G pithos.diskspace
529
    snf-manage resource-modify --limit 2 astakos.pending_app
530
    snf-manage resource-modify --limit 4 cyclades.vm
531
    snf-manage resource-modify --limit 40G cyclades.disk
532
    snf-manage resource-modify --limit 8G cyclades.ram
533
    snf-manage resource-modify --limit 16 cyclades.cpu
534
    snf-manage resource-modify --limit 4 cyclades.network.private
535
    """
536
    try_run(cmd)
537

    
538

    
539
@roles("accounts")
540
def add_user():
541
    debug(env.host, " * adding user %s to astakos..." % env.env.user_email)
542
    email=env.env.user_email
543
    name=env.env.user_name
544
    lastname=env.env.user_lastname
545
    passwd=env.env.user_passwd
546
    cmd = """
547
    snf-manage user-add {0} {1} {2}
548
    """.format(email, name, lastname)
549
    try_run(cmd)
550
    with settings(host_string=env.env.db.ip):
551
        uid, user_auth_token, user_uuid = get_auth_token_from_db(email)
552
    cmd = """
553
    snf-manage user-modify --password {0} {1}
554
    """.format(passwd, uid)
555
    try_run(cmd)
556

    
557

    
558
@roles("accounts")
559
def activate_user(user_email=None):
560
    if not user_email:
561
      user_email = env.env.user_email
562
    debug(env.host, " * Activate user %s..." % user_email)
563
    with settings(host_string=env.env.db.ip):
564
        uid, user_auth_token, user_uuid = get_auth_token_from_db(user_email)
565

    
566
    cmd = """
567
    snf-manage user-modify --verify {0}
568
    snf-manage user-modify --accept {0}
569
    """.format(uid)
570
    try_run(cmd)
571

    
572
@roles("accounts")
573
def setup_astakos():
574
    debug(env.host, "Setting up snf-astakos-app...")
575
    setup_gunicorn()
576
    setup_apache()
577
    setup_webproject()
578
    install_package("python-django-south")
579
    install_package("snf-astakos-app")
580
    install_package("kamaki")
581

    
582
    tmpl = "/etc/synnefo/astakos.conf"
583
    replace = {
584
      "ACCOUNTS": env.env.accounts.fqdn,
585
      "domain": env.env.domain,
586
      "CYCLADES": env.env.cyclades.fqdn,
587
      "PITHOS": env.env.pithos.fqdn,
588
    }
589
    custom = customize_settings_from_tmpl(tmpl, replace)
590
    put(custom, tmpl, mode=0644)
591
    if env.csrf_disable:
592
      cmd = """
593
cat <<EOF >> /etc/synnefo/astakos.conf
594
try:
595
  MIDDLEWARE_CLASSES.remove('django.middleware.csrf.CsrfViewMiddleware')
596
except:
597
  pass
598
EOF
599
"""
600
      try_run(cmd)
601

    
602
    try_run("/etc/init.d/gunicorn restart")
603

    
604
    cmd = """
605
    snf-manage syncdb --noinput
606
    snf-manage migrate im --delete-ghost-migrations
607
    snf-manage migrate quotaholder_app
608
    """
609
    try_run(cmd)
610

    
611
def import_service(service):
612
    tmpl = "/tmp/%s.json" % service
613
    replace = {
614
      "DOMAIN": env.env.domain,
615
      }
616
    custom = customize_settings_from_tmpl(tmpl, replace)
617
    put(custom, tmpl)
618
    try_run("snf-manage service-import --json %s" % tmpl)
619

    
620
@roles("accounts")
621
def get_service_details(service="pithos"):
622
    debug(env.host, " * Getting registered details for %s service..." % service)
623
    result = try_run("snf-manage component-list")
624
    r = re.compile(r".*%s.*" % service, re.M)
625
    service_id, _, _, service_token = r.search(result).group().split()
626
    # print("%s: %s %s" % (service, service_id, service_token))
627
    return (service_id, service_token)
628

    
629

    
630
@roles("db")
631
def get_auth_token_from_db(user_email=None):
632
    if not user_email:
633
        user_email=env.env.user_email
634
    debug(env.host, " * Getting authentication token and uuid for user %s..." % user_email)
635
    cmd = """
636
    echo "select id, auth_token, uuid, email from auth_user, im_astakosuser where auth_user.id = im_astakosuser.user_ptr_id and auth_user.email = '{0}';" > /tmp/psqlcmd
637
    su - postgres -c  "psql -w -d snf_apps -f /tmp/psqlcmd"
638
    """.format(user_email)
639

    
640
    result = try_run(cmd)
641
    r = re.compile(r"(\d+)[ |]*(\S+)[ |]*(\S+)[ |]*" + user_email, re.M)
642
    match = r.search(result)
643
    uid, user_auth_token, user_uuid = match.groups()
644
    # print("%s: %s %s %s" % ( user_email, uid, user_auth_token, user_uuid))
645

    
646
    return (uid, user_auth_token, user_uuid)
647

    
648

    
649
@roles("cms")
650
def cms_loaddata():
651
    debug(env.host, " * Loading cms initial data...")
652
    if env.cms_pass:
653
      debug(env.host, "Aborting. Prerequisites not met.")
654
      return
655
    tmpl = "/tmp/sites.json"
656
    replace = {}
657
    custom = customize_settings_from_tmpl(tmpl, replace)
658
    put(custom, tmpl)
659

    
660
    tmpl = "/tmp/page.json"
661
    replace = {}
662
    custom = customize_settings_from_tmpl(tmpl, replace)
663
    put(custom, tmpl)
664

    
665
    cmd = """
666
    snf-manage loaddata /tmp/sites.json
667
    snf-manage loaddata /tmp/page.json
668
    snf-manage createsuperuser --username=admin --email=admin@{0} --noinput
669
    """.format(env.env.domain)
670
    try_run(cmd)
671

    
672

    
673
@roles("cms")
674
def setup_cms():
675
    debug(env.host, "Setting up cms...")
676
    if env.cms_pass:
677
      debug(env.host, "Aborting. Prerequisites not met.")
678
      return
679
    with settings(hide("everything")):
680
        try_run("ping -c1 accounts." + env.env.domain)
681
    setup_gunicorn()
682
    setup_apache()
683
    setup_webproject()
684
    install_package("snf-cloudcms")
685

    
686
    tmpl = "/etc/synnefo/cms.conf"
687
    replace = {
688
        "ACCOUNTS": env.env.accounts.fqdn,
689
        }
690
    custom = customize_settings_from_tmpl(tmpl, replace)
691
    put(custom, tmpl, mode=0644)
692
    try_run("/etc/init.d/gunicorn restart")
693

    
694

    
695
    cmd = """
696
    snf-manage syncdb
697
    snf-manage migrate --delete-ghost-migrations
698
    """.format(env.env.domain)
699
    try_run(cmd)
700

    
701

    
702
def setup_nfs_dirs():
703
    debug(env.host, " * Creating NFS mount point for pithos and ganeti...")
704
    cmd = """
705
    mkdir -p {0}
706
    cd {0}
707
    mkdir -p data
708
    chown www-data:www-data data
709
    chmod g+ws data
710
    mkdir -p /srv/okeanos
711
    """.format(env.env.pithos_dir)
712
    try_run(cmd)
713

    
714

    
715
@roles("nodes")
716
def setup_nfs_clients():
717
    if env.host == env.env.pithos.ip:
718
      return
719

    
720
    debug(env.host, " * Mounting pithos NFS mount point...")
721
    with settings(hide("everything")):
722
        try_run("ping -c1 " + env.env.pithos.hostname)
723
    install_package("nfs-common")
724
    for d in [env.env.pithos_dir, "/srv/okeanos"]:
725
      try_run("mkdir -p " + d)
726
      cmd = """
727
      echo "{0}:/{1} {2}  nfs4 defaults,rw,noatime,nodiratime,intr,rsize=1048576,wsize=1048576,noacl" >> /etc/fstab
728
      """.format(env.env.pithos.hostname, os.path.basename(d), d)
729
      try_run(cmd)
730
      try_run("mount " + d)
731

    
732

    
733
@roles("pithos")
734
def setup_nfs_server():
735
    debug(env.host, " * Setting up NFS server for pithos...")
736
    setup_nfs_dirs()
737
    install_package("nfs-kernel-server")
738
    tmpl = "/etc/exports"
739
    replace = {
740
      "pithos_dir": env.env.pithos_dir,
741
      "srv": os.path.dirname(env.env.pithos_dir),
742
      "subnet": env.env.subnet
743
      }
744
    custom = customize_settings_from_tmpl(tmpl, replace)
745
    put(custom, tmpl)
746
    try_run("/etc/init.d/nfs-kernel-server restart")
747

    
748

    
749
@roles("pithos")
750
def setup_pithos():
751
    debug(env.host, "Setting up snf-pithos-app...")
752
    with settings(hide("everything")):
753
        try_run("ping -c1 accounts." + env.env.domain)
754
        try_run("ping -c1 " + env.env.db.ip)
755
    setup_gunicorn()
756
    setup_apache()
757
    setup_webproject()
758

    
759
    with settings(host_string=env.env.accounts.ip):
760
        service_id, service_token = get_service_details("pithos")
761

    
762
    install_package("kamaki")
763
    install_package("snf-pithos-backend")
764
    install_package("snf-pithos-app")
765
    tmpl = "/etc/synnefo/pithos.conf"
766
    replace = {
767
        "ACCOUNTS": env.env.accounts.fqdn,
768
        "PITHOS": env.env.pithos.fqdn,
769
        "db_node": env.env.db.ip,
770
        "synnefo_user": env.env.synnefo_user,
771
        "synnefo_db_passwd": env.env.synnefo_db_passwd,
772
        "pithos_dir": env.env.pithos_dir,
773
        "PITHOS_SERVICE_TOKEN": service_token,
774
        "proxy": env.env.pithos.hostname == env.env.accounts.hostname
775
        }
776
    custom = customize_settings_from_tmpl(tmpl, replace)
777
    put(custom, tmpl, mode=0644)
778
    try_run("/etc/init.d/gunicorn restart")
779

    
780
    install_package("snf-pithos-webclient")
781
    tmpl = "/etc/synnefo/webclient.conf"
782
    replace = {
783
        "ACCOUNTS": env.env.accounts.fqdn,
784
        "PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE": service_id,
785
        }
786
    custom = customize_settings_from_tmpl(tmpl, replace)
787
    put(custom, tmpl, mode=0644)
788

    
789
    try_run("/etc/init.d/gunicorn restart")
790
    #TOFIX: the previous command lets pithos-backend create blocks and maps
791
    #       with root owner
792
    try_run("chown -R www-data:www-data %s/data " % env.env.pithos_dir)
793
    #try_run("pithos-migrate stamp 4c8ccdc58192")
794
    #try_run("pithos-migrate upgrade head")
795

    
796

    
797
def add_wheezy():
798
    tmpl = "/etc/apt/sources.list.d/wheezy.list"
799
    replace = {}
800
    custom = customize_settings_from_tmpl(tmpl, replace)
801
    put(custom, tmpl)
802
    apt_get_update()
803

    
804

    
805
def remove_wheezy():
806
    try_run("rm -f /etc/apt/sources.list.d/wheezy.list")
807
    apt_get_update()
808

    
809

    
810
@roles("ganeti")
811
def setup_ganeti():
812
    debug(env.host, "Setting up snf-ganeti...")
813
    node_info = env.env.ips_info[env.host]
814
    with settings(hide("everything")):
815
        #if env.enable_lvm:
816
        #    try_run("vgs " + env.env.vg)
817
        try_run("getent hosts " + env.env.cluster.fqdn)
818
        try_run("getent hosts %s | grep -v ^127" % env.host)
819
        try_run("hostname -f | grep " + node_info.fqdn)
820
        #try_run("ip link show " + env.env.common_bridge)
821
        #try_run("ip link show " + env.env.common_bridge)
822
        #try_run("apt-get update")
823
    install_package("qemu-kvm")
824
    install_package("python-bitarray")
825
    add_wheezy()
826
    install_package("ganeti-htools")
827
    remove_wheezy()
828
    install_package("snf-ganeti")
829
    try_run("mkdir -p /srv/ganeti/file-storage/")
830
    cmd = """
831
cat <<EOF > /etc/ganeti/file-storage-paths
832
/srv/ganeti/file-storage
833
/srv/ganeti/shared-file-storage
834
EOF
835
"""
836
    try_run(cmd)
837

    
838

    
839
@roles("master")
840
def add_rapi_user():
841
    debug(env.host, " * Adding RAPI user to Ganeti backend...")
842
    cmd = """
843
    echo -n "{0}:Ganeti Remote API:{1}" | openssl md5
844
    """.format(env.env.synnefo_user, env.env.synnefo_rapi_passwd)
845
    result = try_run(cmd)
846
    cmd = """
847
    echo "{0} {1}{2} write" >> /var/lib/ganeti/rapi/users
848
    """.format(env.env.synnefo_user, '{ha1}',result)
849
    try_run(cmd)
850
    try_run("/etc/init.d/ganeti restart")
851

    
852
@roles("master")
853
def add_nodes():
854
    nodes = env.env.cluster_nodes.split(",")
855
    nodes.remove(env.env.master_node)
856
    debug(env.host, " * Adding nodes to Ganeti backend...")
857
    for n in nodes:
858
        add_node(n)
859

    
860
@roles("master")
861
def add_node(node):
862
    node_info = env.env.nodes_info[node]
863
    debug(env.host, " * Adding node %s to Ganeti backend..." % node_info.fqdn)
864
    cmd = "gnt-node add --no-ssh-key-check --master-capable=yes --vm-capable=yes " + node_info.fqdn
865
    try_run(cmd)
866

    
867
@roles("ganeti")
868
def enable_drbd():
869
    if env.enable_drbd:
870
        debug(env.host, " * Enabling DRBD...")
871
        try_run("modprobe drbd minor_count=255 usermode_helper=/bin/true")
872
        try_run("echo drbd minor_count=255 usermode_helper=/bin/true >> /etc/modules")
873

    
874
@roles("master")
875
def setup_drbd_dparams():
876
    if env.enable_drbd:
877
        debug(env.host, " * Twicking drbd related disk parameters in Ganeti...")
878
        cmd = """
879
        gnt-cluster modify --disk-parameters=drbd:metavg={0}
880
        gnt-group modify --disk-parameters=drbd:metavg={0} default
881
        """.format(env.env.vg)
882
        try_run(cmd)
883

    
884
@roles("master")
885
def enable_lvm():
886
    if env.enable_lvm:
887
        debug(env.host, " * Enabling LVM...")
888
        cmd = """
889
        gnt-cluster modify --vg-name={0}
890
        """.format(env.env.vg)
891
        try_run(cmd)
892
    else:
893
        debug(env.host, " * Disabling LVM...")
894
        try_run("gnt-cluster modify --no-lvm-storage")
895

    
896
@roles("master")
897
def destroy_cluster():
898
    debug(env.host, " * Destroying Ganeti cluster...")
899
    #TODO: remove instances first
900
    allnodes = env.env.cluster_hostnames[:]
901
    allnodes.remove(env.host)
902
    for n in allnodes:
903
      host_info = env.env.ips_info[host]
904
      debug(env.host, " * Removing node %s..." % n)
905
      cmd = "gnt-node remove  " + host_info.fqdn
906
      try_run(cmd)
907
    try_run("gnt-cluster destroy --yes-do-it")
908

    
909

    
910
@roles("master")
911
def init_cluster():
912
    debug(env.host, " * Initializing Ganeti backend...")
913
    # extra = ""
914
    # if env.enable_lvm:
915
    #     extra += " --vg-name={0} ".format(env.env.vg)
916
    # else:
917
    #     extra += " --no-lvm-storage "
918
    # if not env.enable_drbd:
919
    #     extra += " --no-drbd-storage "
920
    extra = " --no-lvm-storage --no-drbd-storage "
921
    cmd = """
922
    gnt-cluster init --enabled-hypervisors=kvm \
923
                     {0} \
924
                     --nic-parameters link={1},mode=bridged \
925
                     --master-netdev {2} \
926
                     --default-iallocator hail \
927
                     --hypervisor-parameters kvm:kernel_path=,vnc_bind_address=0.0.0.0 \
928
                     --no-ssh-init --no-etc-hosts \
929
                    {3}
930

931
    """.format(extra, env.env.common_bridge,
932
               env.env.cluster_netdev, env.env.cluster.fqdn)
933
    try_run(cmd)
934

    
935

    
936
@roles("ganeti")
937
def debootstrap():
938
    install_package("ganeti-instance-debootstrap")
939

    
940

    
941
@roles("ganeti")
942
def setup_image_host():
943
    debug(env.host, "Setting up snf-image...")
944
    install_package("snf-pithos-backend")
945
    install_package("snf-image")
946
    try_run("mkdir -p /srv/okeanos")
947
    tmpl = "/etc/default/snf-image"
948
    replace = {
949
        "synnefo_user": env.env.synnefo_user,
950
        "synnefo_db_passwd": env.env.synnefo_db_passwd,
951
        "pithos_dir": env.env.pithos_dir,
952
        "db_node": env.env.db.ip,
953
    }
954
    custom = customize_settings_from_tmpl(tmpl, replace)
955
    put(custom, tmpl)
956

    
957

    
958
@roles("ganeti")
959
def setup_image_helper():
960
    debug(env.host, " * Updating helper image...")
961
    cmd = """
962
    snf-image-update-helper -y
963
    """
964
    try_run(cmd)
965

    
966

    
967
@roles("ganeti")
968
def setup_gtools():
969
    debug(env.host, " * Setting up snf-cyclades-gtools...")
970
    with settings(hide("everything")):
971
        try_run("ping -c1 " + env.env.mq.ip)
972
    setup_common()
973
    install_package("snf-cyclades-gtools")
974
    tmpl = "/etc/synnefo/gtools.conf"
975
    replace = {
976
        "synnefo_user": env.env.synnefo_user,
977
        "synnefo_rabbitmq_passwd": env.env.synnefo_rabbitmq_passwd,
978
        "mq_node": env.env.mq.ip,
979
    }
980
    custom = customize_settings_from_tmpl(tmpl, replace)
981
    put(custom, tmpl)
982

    
983
    cmd = """
984
    sed -i 's/false/true/' /etc/default/snf-ganeti-eventd
985
    /etc/init.d/snf-ganeti-eventd start
986
    """
987
    try_run(cmd)
988

    
989

    
990
@roles("ganeti")
991
def setup_iptables():
992
    debug(env.host, " * Setting up iptables to mangle DHCP requests...")
993
    cmd = """
994
    iptables -t mangle -A PREROUTING -i br+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42
995
    iptables -t mangle -A PREROUTING -i tap+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42
996
    iptables -t mangle -A PREROUTING -i prv+ -p udp -m udp --dport 67 -j NFQUEUE --queue-num 42
997

998
    ip6tables -t mangle -A PREROUTING -i br+ -p ipv6-icmp -m icmp6 --icmpv6-type 133 -j NFQUEUE --queue-num 43
999
    ip6tables -t mangle -A PREROUTING -i br+ -p ipv6-icmp -m icmp6 --icmpv6-type 135 -j NFQUEUE --queue-num 44
1000
    """
1001
    try_run(cmd)
1002

    
1003
@roles("ganeti")
1004
def setup_network():
1005
    debug(env.host, "Setting up networking for Ganeti instances (nfdhcpd, etc.)...")
1006
    install_package("nfqueue-bindings-python")
1007
    install_package("nfdhcpd")
1008
    tmpl = "/etc/nfdhcpd/nfdhcpd.conf"
1009
    replace = {
1010
      "ns_node_ip": env.env.ns.ip
1011
      }
1012
    custom = customize_settings_from_tmpl(tmpl, replace)
1013
    put(custom, tmpl)
1014
    try_run("/etc/init.d/nfdhcpd restart")
1015

    
1016
    install_package("snf-network")
1017
    cmd = """
1018
    sed -i 's/MAC_MASK.*/MAC_MASK = ff:ff:f0:00:00:00/' /etc/default/snf-network
1019
    """
1020
    try_run(cmd)
1021

    
1022

    
1023
@roles("router")
1024
def setup_router():
1025
    debug(env.host, " * Setting up internal router for NAT...")
1026
    cmd = """
1027
    echo 1 > /proc/sys/net/ipv4/ip_forward
1028
    iptables -t nat -A POSTROUTING -s {0} -o {3} -j MASQUERADE
1029
    ip addr add {1} dev {2}
1030
    ip route add {0} dev {2} src {1}
1031
    """.format(env.env.synnefo_public_network_subnet,
1032
               env.env.synnefo_public_network_gateway,
1033
               env.env.common_bridge, env.env.public_iface)
1034
    try_run(cmd)
1035

    
1036
@roles("cyclades")
1037
def cyclades_loaddata():
1038
    debug(env.host, " * Loading initial data for cyclades...")
1039
    tmpl = "/tmp/flavor.json"
1040
    replace = {}
1041
    custom = customize_settings_from_tmpl(tmpl, replace)
1042
    put(custom, tmpl)
1043
    try_run("snf-manage loaddata " + tmpl)
1044
    #run("snf-manage loaddata flavors")
1045

    
1046

    
1047
@roles("cyclades")
1048
def setup_cyclades():
1049
    debug(env.host, "Setting up snf-cyclades-app...")
1050
    with settings(hide("everything")):
1051
        try_run("ping -c1 accounts." + env.env.domain)
1052
        try_run("ping -c1 " + env.env.db.ip)
1053
        try_run("ping -c1 " + env.env.mq.ip)
1054
    setup_gunicorn()
1055
    setup_apache()
1056
    setup_webproject()
1057
    install_package("memcached")
1058
    install_package("python-memcache")
1059
    install_package("snf-pithos-backend")
1060
    install_package("kamaki")
1061
    install_package("snf-cyclades-app")
1062
    install_package("python-django-south")
1063
    tmpl = "/etc/synnefo/cyclades.conf"
1064

    
1065
    with settings(host_string=env.env.accounts.ip):
1066
        service_id, service_token = get_service_details("cyclades")
1067

    
1068
    replace = {
1069
        "ACCOUNTS": env.env.accounts.fqdn,
1070
        "CYCLADES": env.env.cyclades.fqdn,
1071
        "mq_node": env.env.mq.ip,
1072
        "db_node": env.env.db.ip,
1073
        "synnefo_user": env.env.synnefo_user,
1074
        "synnefo_db_passwd": env.env.synnefo_db_passwd,
1075
        "synnefo_rabbitmq_passwd": env.env.synnefo_rabbitmq_passwd,
1076
        "pithos_dir": env.env.pithos_dir,
1077
        "common_bridge": env.env.common_bridge,
1078
        "HOST": env.env.cyclades.ip,
1079
        "domain": env.env.domain,
1080
        "CYCLADES_SERVICE_TOKEN": service_token,
1081
        "proxy": env.env.cyclades.hostname == env.env.accounts.hostname
1082
        }
1083
    custom = customize_settings_from_tmpl(tmpl, replace)
1084
    put(custom, tmpl, mode=0644)
1085
    try_run("/etc/init.d/gunicorn restart")
1086

    
1087
    cmd = """
1088
    sed -i 's/false/true/' /etc/default/snf-dispatcher
1089
    /etc/init.d/snf-dispatcher start
1090
    """
1091
    try_run(cmd)
1092

    
1093
    try_run("snf-manage syncdb")
1094
    try_run("snf-manage migrate --delete-ghost-migrations")
1095

    
1096

    
1097
@roles("cyclades")
1098
def get_backend_id(cluster_name="ganeti1.synnefo.deploy.local"):
1099
    backend_id = try_run("snf-manage backend-list 2>/dev/null | grep %s | awk '{print $1}'" % cluster_name)
1100
    return backend_id
1101

    
1102

    
1103
@roles("cyclades")
1104
def add_backend():
1105
    debug(env.host, "adding %s ganeti backend to cyclades..." % env.env.cluster.fqdn)
1106
    with settings(hide("everything")):
1107
        try_run("ping -c1 " + env.env.cluster.fqdn)
1108
    cmd = """
1109
    snf-manage backend-add --clustername={0} --user={1} --pass={2}
1110
    """.format(env.env.cluster.fqdn, env.env.synnefo_user,
1111
               env.env.synnefo_rapi_passwd)
1112
    try_run(cmd)
1113
    backend_id = get_backend_id(env.env.cluster.fqdn)
1114
    try_run("snf-manage backend-modify --drained=False " + backend_id)
1115

    
1116
@roles("cyclades")
1117
def pin_user_to_backend(user_email):
1118
    backend_id = get_backend_id(env.env.cluster.fqdn)
1119
    # pin user to backend
1120
    cmd = """
1121
cat <<EOF >> /etc/synnefo/cyclades.conf
1122

1123
BACKEND_PER_USER = {
1124
  '%s': %s,
1125
}
1126

1127
EOF
1128
/etc/init.d/gunicorn restart
1129
    """  % (user_email, backend_id)
1130
    try_run(cmd)
1131

    
1132
@roles("cyclades")
1133
def add_pools():
1134
    debug(env.host, " * Creating pools of resources (brigdes, mac prefixes) in cyclades...")
1135
    try_run("snf-manage pool-create --type=mac-prefix --base=aa:00:0 --size=65536")
1136
    try_run("snf-manage pool-create --type=bridge --base=prv --size=20")
1137

    
1138

    
1139
@roles("cyclades")
1140
def add_network():
1141
    debug(env.host, " * Adding public network in cyclades...")
1142
    backend_id = get_backend_id(env.env.cluster.fqdn)
1143
    cmd = """
1144
    snf-manage network-create --subnet={0} --gateway={1} --public --dhcp --flavor={2} --mode=bridged --link={3} --name=Internet --backend-id={4}
1145
    """.format(env.env.synnefo_public_network_subnet,
1146
               env.env.synnefo_public_network_gateway,
1147
               env.env.synnefo_public_network_type,
1148
               env.env.common_bridge, backend_id)
1149
    try_run(cmd)
1150

    
1151

    
1152
@roles("cyclades")
1153
def setup_vncauthproxy():
1154
    debug(env.host, " * Setting up vncauthproxy...")
1155
    install_package("snf-vncauthproxy")
1156
    cmd = """
1157
    echo CHUID="www-data:nogroup" >> /etc/default/vncauthproxy
1158
    rm /var/log/vncauthproxy/vncauthproxy.log
1159
    """
1160
    try_run(cmd)
1161
    try_run("/etc/init.d/vncauthproxy restart")
1162

    
1163
@roles("client")
1164
def setup_kamaki():
1165
    debug(env.host, "Setting up kamaki client...")
1166
    with settings(hide("everything")):
1167
        try_run("ping -c1 accounts." + env.env.domain)
1168
        try_run("ping -c1 cyclades." + env.env.domain)
1169
        try_run("ping -c1 pithos." + env.env.domain)
1170

    
1171
    with settings(host_string=env.env.db.ip):
1172
        uid, user_auth_token, user_uuid = get_auth_token_from_db(env.env.user_email)
1173

    
1174
    install_package("python-progress")
1175
    install_package("kamaki")
1176
    cmd = """
1177
    kamaki config set cloud.default.url "https://{0}/astakos/identity/v2.0/"
1178
    kamaki config set cloud.default.token {1}
1179
    """.format(env.env.accounts.fqdn, user_auth_token)
1180
    try_run(cmd)
1181
    try_run("kamaki file create images")
1182

    
1183
@roles("client")
1184
def upload_image(image="debian_base.diskdump"):
1185
    debug(env.host, " * Uploading initial image to pithos...")
1186
    image = "debian_base.diskdump"
1187
    try_run("wget {0} -O /tmp/{1}".format(env.env.debian_base_url, image))
1188
    try_run("kamaki file upload --container images /tmp/{0} {0}".format(image))
1189

    
1190
@roles("client")
1191
def register_image(image="debian_base.diskdump"):
1192
    debug(env.host, " * Register image to plankton...")
1193
    with settings(host_string=env.env.db.ip):
1194
        uid, user_auth_token, user_uuid = get_auth_token_from_db(env.env.user_email)
1195

    
1196
    pithos_url = "pithos://{0}/images/{1}".format(user_uuid, image)
1197
    cmd = """
1198
    sleep 5
1199
    kamaki image register "Debian Base" {0} --public --disk-format=diskdump --property OSFAMILY=linux --property ROOT_PARTITION=1 --property description="Debian Squeeze Base System" --property size=450M --property kernel=2.6.32 --property GUI="No GUI" --property sortorder=1 --property USERS=root --property OS=debian
1200
    """.format(pithos_url)
1201
    try_run(cmd)
1202

    
1203
@roles("client")
1204
def setup_burnin():
1205
    debug(env.host, "Setting up burnin testing tool...")
1206
    install_package("kamaki")
1207
    install_package("snf-tools")
1208

    
1209
@roles("pithos")
1210
def add_image_locally():
1211
    debug(env.host, " * Getting image locally in order snf-image to use it directly..")
1212
    image = "debian_base.diskdump"
1213
    try_run("wget {0} -O /srv/okeanos/{1}".format(env.env.debian_base_url, image))
1214

    
1215

    
1216
@roles("master")
1217
def gnt_instance_add(name="test"):
1218
    debug(env.host, " * Adding test instance to Ganeti...")
1219
    osp="""img_passwd=gamwtosecurity,img_format=diskdump,img_id=debian_base,img_properties='{"OSFAMILY":"linux"\,"ROOT_PARTITION":"1"}'"""
1220
    cmd = """
1221
    gnt-instance add  -o snf-image+default --os-parameters {0} -t plain --disk 0:size=1G --no-name-check --no-ip-check --net 0:ip=pool,network=test --no-install --hypervisor-parameters kvm:machine_version=pc-1.0 {1}
1222
    """.format(osp, name)
1223
    try_run(cmd)
1224

    
1225
@roles("master")
1226
def gnt_network_add(name="test", subnet="10.0.0.0/26", gw="10.0.0.1", mode="bridged", link="br0"):
1227
    debug(env.host, " * Adding test network to Ganeti...")
1228
    cmd = """
1229
    gnt-network add --network={1} --gateway={2} {0}
1230
    gnt-network connect {0} {3} {4}
1231
    """.format(name, subnet, gw, mode, link)
1232
    try_run(cmd)
1233

    
1234
@roles("ips")
1235
def test():
1236
    debug(env.host, "Testing...")
1237
    try_run("hostname && date")