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 ###############################################################################
15 class HardwareAdapter(object):
17 def __init__(self, yaml_path):
18 self.dha_struct = None
19 self.parse_yaml(yaml_path)
21 def parse_yaml(self, yaml_path):
22 with io.open(yaml_path) as yaml_file:
23 self.dha_struct = yaml.load(yaml_file)
25 def get_adapter_type(self):
26 return self.dha_struct['adapter']
28 def get_all_node_ids(self):
30 for node in self.dha_struct['nodes']:
31 node_ids.append(node['id'])
35 def get_fuel_node_id(self):
36 for node in self.dha_struct['nodes']:
37 if 'isFuel' in node and node['isFuel']:
40 def get_node_ids(self):
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'])
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]
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']
60 return self.dha_struct['disks']
62 def get_number_cpus(self, role):
63 role_cpus_dict = self.dha_struct.get('number_cpus')
65 return role_cpus_dict.get(role)