2 # Copyright (c) 2015 All rights reserved
3 # This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
10 from ssh_util import SshUtil
13 class NodeManager(object):
17 primary_controller = None
19 def __init__(self, config=None):
20 if config is not None:
21 for (node_name, node_config) in config.iteritems():
22 self.add_node(node_name, node_config)
24 def add_node(self, node_name, node_config):
26 if not node_config.get('address'):
27 raise NodeManagerException("IP address missing from node_config:"
28 " {}".format(node_config))
29 node = Node(node_name, dict=node_config)
30 self.env_nodes.append(node)
31 self.env_node_dict[node_name] = node
37 def get_node(self, name):
38 return self.env_node_dict[name]
41 def gen_ssh_config(cls, node):
42 if node not in cls.env_nodes:
43 cls.env_nodes.append(node)
44 SshUtil.gen_ssh_config(cls.env_nodes)
47 class NodeManagerException(Exception):
48 def __init__(self, value):