Merge "Autodeploy inspired on Prototype #2"
[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 use_fuel_custom_install(self):
38         return self.dha_struct['fuelCustomInstall']
39
40     def get_node_property(self, node_id, property_name):
41         for node in self.dha_struct['nodes']:
42             if node['id'] == node_id and property_name in node:
43                 return node[property_name]
44
45     def node_can_zero_mbr(self, node_id):
46         return self.get_node_property(node_id, 'nodeCanZeroMBR')
47
48     def get_fuel_access(self):
49         for node in self.dha_struct['nodes']:
50             if 'isFuel' in node and node['isFuel']:
51                 return node['username'], node['password']