Merge "Rebase of ks.cfg due to upstream changes" into stable/brahmaputra
[fuel.git] / deploy / cloud / deploy.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
11 import yaml
12 import io
13
14 from dea import DeploymentEnvironmentAdapter
15 from configure_environment import ConfigureEnvironment
16 from deployment import Deployment
17
18 from common import (
19     R,
20     exec_cmd,
21     parse,
22     check_file_exists,
23     commafy,
24     ArgParser,
25 )
26
27 YAML_CONF_DIR = '/var/lib/opnfv'
28
29
30 class Deploy(object):
31
32     def __init__(self, dea_file, no_health_check):
33         self.dea = DeploymentEnvironmentAdapter(dea_file)
34         self.no_health_check = no_health_check
35         self.macs_per_blade = {}
36         self.blades = self.dea.get_node_ids()
37         self.blade_node_dict = self.dea.get_blade_node_map()
38         self.node_roles_dict = {}
39         self.env_id = None
40         self.wanted_release = self.dea.get_property('wanted_release')
41
42     def assign_roles_to_cluster_node_ids(self):
43         self.node_roles_dict = {}
44         for blade, node in self.blade_node_dict.iteritems():
45             if self.dea.get_node_role(blade):
46                 roles = commafy(self.dea.get_node_role(blade))
47                 self.node_roles_dict[node] = (roles, blade)
48
49     def configure_environment(self):
50         release_list = parse(exec_cmd('fuel release -l'))
51         for release in release_list:
52             if release[R['name']] == self.wanted_release:
53                 break
54         config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR,
55                                           release[R['id']],
56                                           self.node_roles_dict)
57         config_env.configure_environment()
58         self.env_id = config_env.env_id
59
60     def deploy_cloud(self):
61         dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id,
62                          self.node_roles_dict, self.no_health_check)
63         dep.deploy()
64
65     def deploy(self):
66
67         self.assign_roles_to_cluster_node_ids()
68
69         self.configure_environment()
70
71         self.deploy_cloud()
72
73
74 def parse_arguments():
75     parser = ArgParser(prog='python %s' % __file__)
76     parser.add_argument('-nh', dest='no_health_check', action='store_true',
77                         default=False,
78                         help='Don\'t run health check after deployment')
79     parser.add_argument('dea_file', action='store',
80                         help='Deployment Environment Adapter: dea.yaml')
81     args = parser.parse_args()
82     check_file_exists(args.dea_file)
83
84     kwargs = {'dea_file': args.dea_file,
85               'no_health_check': args.no_health_check}
86     return kwargs
87
88
89 def main():
90     kwargs = parse_arguments()
91     deploy = Deploy(**kwargs)
92     deploy.deploy()
93
94 if __name__ == '__main__':
95     main()