roles.py 1.51 KB
Newer Older
Vangelis Koukis's avatar
Vangelis Koukis committed
1
# Copyright (C) 2010-2014 GRNET S.A.
2
#
Vangelis Koukis's avatar
Vangelis Koukis committed
3 4 5 6
# 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.
7
#
Vangelis Koukis's avatar
Vangelis Koukis committed
8 9 10 11
# 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.
12
#
Vangelis Koukis's avatar
Vangelis Koukis committed
13 14
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
16 17
from snfdeploy import constants
from snfdeploy import components
18 19


Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
_ROLE_MAP = {
    constants.NS: components.NS,
    constants.NFS: components.NFS,
    constants.DB: components.DB,
    constants.MQ: components.MQ,
    constants.ASTAKOS: components.Astakos,
    constants.CYCLADES: components.Cyclades,
    constants.PITHOS: components.Pithos,
    constants.CMS: components.CMS,
    constants.STATS: components.Stats,
    constants.MASTER: components.Master,
    constants.VMC: components.VMC,
    constants.CLIENT: components.Client,
    constants.DEV: components.GanetiDev,
    constants.ROUTER: components.Router,
35
    }
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49


def _get_role_map(role):
    if role in _ROLE_MAP:
        return _ROLE_MAP[role]
    else:
        return getattr(components, role)


def get(role, ctx):
    assert role and ctx
    c = _get_role_map(role)
    ctx.role = role
    return c(ctx=ctx)