Update of endpoint addresses
[fuel.git] / deploy / dha_adapters / hardware_adapter.py
1 ###############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # szilard.cserey@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ###############################################################################
9
10
11 import yaml
12 import io
13
14
15 class HardwareAdapter(object):
16
17     def __init__(self, yaml_path):
18         self.dha_struct = None
19         self.parse_yaml(yaml_path)
20
21     def parse_yaml(self, yaml_path):
22         with io.open(yaml_path) as yaml_file:
23             self.dha_struct = yaml.load(yaml_file)
24
25     def get_adapter_type(self):
26         return self.dha_struct['adapter']
27
28     def get_all_node_ids(self):
29         node_ids = []
30         for node in self.dha_struct['nodes']:
31             node_ids.append(node['id'])
32         node_ids.sort()
33         return node_ids
34
35     def get_fuel_node_id(self):
36         for node in self.dha_struct['nodes']:
37             if 'isFuel' in node and node['isFuel']:
38                 return node['id']
39
40     def get_node_ids(self):
41         node_ids = []
42         fuel_node_id = self.get_fuel_node_id()
43         for node in self.dha_struct['nodes']:
44             if node['id'] != fuel_node_id:
45                 node_ids.append(node['id'])
46         node_ids.sort()
47         return node_ids
48
49     def get_node_property(self, node_id, property_name):
50         for node in self.dha_struct['nodes']:
51             if node['id'] == node_id and property_name in node:
52                 return node[property_name]
53
54     def get_fuel_access(self):
55         for node in self.dha_struct['nodes']:
56             if 'isFuel' in node and node['isFuel']:
57                 return node['username'], node['password']
58
59     def get_disks(self):
60         return self.dha_struct['disks']