Updates docs for SR1 with final revision
[genesis.git] / fuel / 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 import yaml
11 import io
12
13
14 class HardwareAdapter(object):
15
16     def __init__(self, yaml_path):
17         self.dha_struct = None
18         self.parse_yaml(yaml_path)
19
20     def parse_yaml(self, yaml_path):
21         with io.open(yaml_path) as yaml_file:
22             self.dha_struct = yaml.load(yaml_file)
23
24     def get_adapter_type(self):
25         return self.dha_struct['adapter']
26
27     def get_all_node_ids(self):
28         node_ids = []
29         for node in self.dha_struct['nodes']:
30             node_ids.append(node['id'])
31         node_ids.sort()
32         return node_ids
33
34     def get_fuel_node_id(self):
35         for node in self.dha_struct['nodes']:
36             if 'isFuel' in node and node['isFuel']:
37                 return node['id']
38
39     def get_node_ids(self):
40         node_ids = []
41         fuel_node_id = self.get_fuel_node_id()
42         for node in self.dha_struct['nodes']:
43             if node['id'] != fuel_node_id:
44                 node_ids.append(node['id'])
45         node_ids.sort()
46         return node_ids
47
48     def get_node_property(self, node_id, property_name):
49         for node in self.dha_struct['nodes']:
50             if node['id'] == node_id and property_name in node:
51                 return node[property_name]
52
53     def get_fuel_access(self):
54         for node in self.dha_struct['nodes']:
55             if 'isFuel' in node and node['isFuel']:
56                 return node['username'], node['password']
57
58     def get_disks(self):
59         return self.dha_struct['disks']