Automatic Deployment
[genesis.git] / fuel / deploy / dea.py
1 import yaml
2
3 class DeploymentEnvironmentAdapter(object):
4     def __init__(self):
5         self.dea_struct = None
6         self.blade_ids = {}
7         self.blades = {}
8         self.shelf_ids = []
9
10     def parse_yaml(self, yaml_path):
11         with open(yaml_path) as yaml_file:
12             self.dea_struct = yaml.load(yaml_file)
13         self.collect_shelf_and_blade_info()
14
15     def get_no_of_blades(self):
16         no_of_blades = 0
17         for shelf in self.dea_struct['shelf']:
18             no_of_blades += len(shelf['blade'])
19         return no_of_blades
20
21     def get_server_type(self):
22         return self.dea_struct['server_type']
23
24     def get_environment_name(self):
25         return self.dea_struct['name']
26
27     def get_shelf_ids(self):
28         return self.shelf_ids
29
30     def get_blade_ids(self, shelf_id):
31         return self.blade_ids[shelf_id]
32
33     def collect_shelf_and_blade_info(self):
34         self.blade_ids = {}
35         self.blades = {}
36         self.shelf_ids = []
37         for shelf in self.dea_struct['shelf']:
38              self.shelf_ids.append(shelf['id'])
39              blade_ids = self.blade_ids[shelf['id']] = []
40              blades = self.blades[shelf['id']] = {}
41              for blade in shelf['blade']:
42                  blade_ids.append(blade['id'])
43                  blades[blade['id']] = blade
44
45     def is_controller(self, shelf_id, blade_id):
46         blade = self.blades[shelf_id][blade_id]
47         return (True if 'role' in blade and blade['role'] == 'controller'
48                 else False)
49
50     def is_compute_host(self, shelf_id, blade_id):
51         blade = self.blades[shelf_id][blade_id]
52         return True if 'role' not in blade else False