Commit 2d0a73fe authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis

deploy: Add context module

This module will be used as a common execution context
just like fabric's env. A context is basically the node, role,
cluster, and setup that a components gets installed. The new
Context class is a configuration snapshot for the given context.
It exports helper methods to get the node's and cluster's info, etc.
This class is used to initialize the target component class.
Signed-off-by: default avatarDimitris Aragiorgis <>
parent 41376567
# Copyright (C) 2010-2014 GRNET S.A.
# 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.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
import sys
from snfdeploy import constants
from snfdeploy import config
context = sys.modules[__name__]
class Context(object):
def __repr__(self):
ret = "[%s %s] " % (self.node_info.ip,
ret += "[%s %s %s %s]" % \
(self.node, self.role, self.setup, self.cluster)
return ret
def __init__(self, node=None, role=None, cluster=None, setup=None):
if not node:
node = context.node
if not role:
role = context.role
if not setup:
setup = context.setup
if not cluster:
cluster = context.cluster
self.node = node
self.role = role
self.cluster = cluster
self.setup = setup
def update(self, node=None, role=None, cluster=None, setup=None):
if node:
self.node = node
if role:
self.role = role
if cluster:
self.cluster = cluster
if setup:
self.setup = setup
def update_info(self):
self.ns = self.get(constants.NS)
self.nfs = self.get(constants.NFS) = self.get(constants.MQ)
self.db = self.get(constants.DB)
self.astakos = self.get(constants.ASTAKOS)
self.cyclades = self.get(constants.CYCLADES)
self.pithos = self.get(constants.PITHOS)
self.stats = self.get(constants.STATS)
self.cms = self.get(constants.CMS)
self.router = self.get(constants.ROUTER)
def get(self, role):
return config.get_single_node_role_info(self.setup, role)
def node_info(self):
return config.get_info(node=self.node)
def cluster_info(self):
return config.get_info(cluster=self.cluster)
def clusters(self):
return config.get(self.setup, constants.CLUSTERS)
def masters(self):
return config.get(self.cluster, constants.MASTER)
def master(self):
return config.get_single_node_role_info(self.cluster, constants.MASTER)
def vmcs(self):
return config.get(self.cluster, constants.VMC)
def nodes(self):
return list(set(self.masters + self.vmcs))
def get(role):
return config.get(context.setup, role)
def backup():
context.node_backup = context.node
context.role_backup = context.role
context.cluster_backup = context.cluster
context.setup_backup = context.setup
def restore():
context.node = context.node_backup
context.role = context.role_backup
context.cluster = context.cluster_backup
context.setup = context.setup_backup
def init(args):
context.node = args.node
context.role = args.role
context.cluster = args.cluster
context.setup = args.setup
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment