Updates ODL Pipeline scripts for CSIT
[sdnvpn.git] / odl-pipeline / lib / utils / node_manager.py
1 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #
10 from ssh_util import SshUtil
11
12
13 class NodeManager(object):
14
15     env_nodes = []
16     env_node_dict = {}
17     primary_controller = None
18
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)
23
24     def add_node(self, node_name, node_config):
25         from node import Node
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
32         return node
33
34     def get_nodes(self):
35         return self.env_nodes
36
37     def get_node(self, name):
38         return self.env_node_dict[name]
39
40     @classmethod
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)
45
46
47 class NodeManagerException(Exception):
48     def __init__(self, value):
49         self.value = value