Merge "Corrected links associated with release docs. To be updated along with the...
[genesis.git] / fuel / deploy / dha_adapters / hardware_adapter.py
1 import yaml
2 import io
3
4 class HardwareAdapter(object):
5     def __init__(self, yaml_path):
6         self.dha_struct = None
7         self.parse_yaml(yaml_path)
8
9     def parse_yaml(self, yaml_path):
10         with io.open(yaml_path) as yaml_file:
11             self.dha_struct = yaml.load(yaml_file)
12
13     def get_adapter_type(self):
14         return self.dha_struct['adapter']
15
16     def get_all_node_ids(self):
17         node_ids = []
18         for node in self.dha_struct['nodes']:
19             node_ids.append(node['id'])
20         node_ids.sort()
21         return node_ids
22
23     def get_fuel_node_id(self):
24         for node in self.dha_struct['nodes']:
25             if 'isFuel' in node and node['isFuel']:
26                 return node['id']
27
28     def get_node_ids(self):
29         node_ids = []
30         fuel_node_id = self.get_fuel_node_id()
31         for node in self.dha_struct['nodes']:
32             if node['id'] != fuel_node_id:
33                 node_ids.append(node['id'])
34         node_ids.sort()
35         return node_ids
36
37     def get_node_property(self, node_id, property_name):
38         for node in self.dha_struct['nodes']:
39             if node['id'] == node_id and property_name in node:
40                 return node[property_name]
41
42     def get_fuel_access(self):
43         for node in self.dha_struct['nodes']:
44             if 'isFuel' in node and node['isFuel']:
45                 return node['username'], node['password']
46
47     def get_disks(self):
48         return self.dha_struct['disks']