fabfile.py 2.61 KB
Newer Older
Ilias Tsitsimpis's avatar
Ilias Tsitsimpis committed
1 2
# Too many lines in module pylint: disable-msg=C0302
# Too many arguments (7/5) pylint: disable-msg=R0913
3

Vangelis Koukis's avatar
Vangelis Koukis committed
4
# Copyright (C) 2010-2014 GRNET S.A.
5
#
Vangelis Koukis's avatar
Vangelis Koukis committed
6 7 8 9
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
10
#
Vangelis Koukis's avatar
Vangelis Koukis committed
11 12 13 14
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
15
#
Vangelis Koukis's avatar
Vangelis Koukis committed
16 17
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18

Ilias Tsitsimpis's avatar
Ilias Tsitsimpis committed
19 20 21 22 23
"""
Fabric file for snf-deploy

"""

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
24
from __future__ import with_statement
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
25 26 27 28
from fabric.api import env, execute, parallel
from snfdeploy import context
from snfdeploy import constants
from snfdeploy import roles
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
29 30


Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
31 32 33 34
def setup_env(args):
    env.component = args.component
    env.method = args.method
    env.ctx = context.Context()
35

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
36

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
37 38 39 40 41
@parallel
def setup_vmc():
    env.ctx.update(node=env.host)
    VMC = roles.get(constants.VMC, env.ctx)
    VMC.setup()
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
42

43

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
44 45 46
def setup_master():
    env.ctx.update(node=env.host)
    _setup_role(constants.MASTER)
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
47 48


Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
49 50 51 52 53
@parallel
def setup_cluster():
    env.ctx.update(cluster=env.host)
    execute(setup_master, hosts=env.ctx.masters)
    execute(setup_vmc, hosts=env.ctx.vmcs)
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
54 55


Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
56 57 58 59
def _setup_role(role):
    env.ctx.update(node=env.host)
    ROLE = roles.get(role, env.ctx)
    ROLE.setup()
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
60 61


Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
62 63
def setup_role(role):
    execute(_setup_role, role, hosts=context.get(role))
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
64

65

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
66 67 68 69 70
def setup_synnefo():
    setup_role(constants.NS)
    setup_role(constants.NFS)
    setup_role(constants.DB)
    setup_role(constants.MQ)
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
71

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
72 73 74 75
    setup_role(constants.ASTAKOS)
    setup_role(constants.PITHOS)
    setup_role(constants.CYCLADES)
    setup_role(constants.CMS)
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
76

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
77
    execute(setup_cluster, hosts=env.ctx.clusters)
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
78

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
79 80
    setup_role(constants.STATS)
    setup_role(constants.CLIENT)
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
81 82


Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
83 84 85 86
def setup_ganeti():
    setup_role(constants.NS)
    setup_role(constants.NFS)
    execute(setup_cluster, hosts=env.ctx.clusters)
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
87

88

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
89 90 91 92 93 94
def _setup_qa():
    env.ctx.update(cluster=env.host)
    setup_role(constants.NS)
    setup_role(constants.NFS)
    setup_cluster()
    setup_role(constants.DEV)
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
95

Ilias Tsitsimpis's avatar
Ilias Tsitsimpis committed
96

97
def setup_qa():
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
98
    execute(_setup_qa, hosts=env.ctx.clusters)
99 100


101
def setup():
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
102 103 104 105 106 107 108 109 110 111
    if env.component:
        target = env.component
    else:
        target = env.ctx.role
    C = roles.get(target, env.ctx)
    if env.method:
        fn = getattr(C, env.method)
        fn()
    else:
        C.setup()