Merge "Smaller non-HA virtual deployment template"
[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             roles = commafy(self.dea.get_node_role(blade))
46             self.node_roles_dict[node] = (roles, blade)
47
48     def configure_environment(self):
49         release_list = parse(exec_cmd('fuel release -l'))
50         for release in release_list:
51             if release[R['name']] == self.wanted_release:
52                 break
53         config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR,
54                                           release[R['id']],
55                                           self.node_roles_dict)
56         config_env.configure_environment()
57         self.env_id = config_env.env_id
58
59     def deploy_cloud(self):
60         dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id,
61                          self.node_roles_dict, self.no_health_check)
62         dep.deploy()
63
64     def deploy(self):
65
66         self.assign_roles_to_cluster_node_ids()
67
68         self.configure_environment()
69
70         self.deploy_cloud()
71
72
73 def parse_arguments():
74     parser = ArgParser(prog='python %s' % __file__)
75     parser.add_argument('-nh', dest='no_health_check', action='store_true',
76                         default=False,
77                         help='Don\'t run health check after deployment')
78     parser.add_argument('dea_file', action='store',
79                         help='Deployment Environment Adapter: dea.yaml')
80     args = parser.parse_args()
81     check_file_exists(args.dea_file)
82
83     kwargs = {'dea_file': args.dea_file,
84               'no_health_check': args.no_health_check}
85     return kwargs
86
87
88 def main():
89     kwargs = parse_arguments()
90     deploy = Deploy(**kwargs)
91     deploy.deploy()
92
93 if __name__ == '__main__':
94     main()