Updates docs for SR1 with final revision
[genesis.git] / fuel / 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 os
12 import yaml
13 import io
14 import glob
15
16 import common
17 from dea import DeploymentEnvironmentAdapter
18 from configure_environment import ConfigureEnvironment
19 from deployment import Deployment
20
21 YAML_CONF_DIR = '/var/lib/opnfv'
22
23 N = common.N
24 E = common.E
25 R = common.R
26 RO = common.RO
27 exec_cmd = common.exec_cmd
28 parse = common.parse
29 err = common.err
30 check_file_exists = common.check_file_exists
31 log = common.log
32 commafy = common.commafy
33 ArgParser = common.ArgParser
34
35
36 class Deploy(object):
37
38     def __init__(self, dea_file, blade_node_file, no_health_check):
39         self.dea = DeploymentEnvironmentAdapter(dea_file)
40         self.blade_node_file = blade_node_file
41         self.no_health_check = no_health_check
42         self.macs_per_blade = {}
43         self.blades = self.dea.get_node_ids()
44         self.blade_node_dict = {}
45         self.node_roles_dict = {}
46         self.env_id = None
47         self.wanted_release = self.dea.get_property('wanted_release')
48
49     def get_blade_node_mapping(self):
50         with io.open(self.blade_node_file, 'r') as stream:
51             self.blade_node_dict = yaml.load(stream)
52
53     def assign_roles_to_cluster_node_ids(self):
54         self.node_roles_dict = {}
55         for blade, node in self.blade_node_dict.iteritems():
56             roles = commafy(self.dea.get_node_role(blade))
57             self.node_roles_dict[node] = (roles, blade)
58
59     def configure_environment(self):
60         release_list = parse(exec_cmd('fuel release -l'))
61         for release in release_list:
62             if release[R['name']] == self.wanted_release:
63                 break
64         config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR,
65                                           release[R['id']],
66                                           self.node_roles_dict)
67         config_env.configure_environment()
68         self.env_id = config_env.env_id
69
70     def deploy_cloud(self):
71         dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id,
72                          self.node_roles_dict, self.no_health_check)
73         dep.deploy()
74
75     def deploy(self):
76
77         self.get_blade_node_mapping()
78
79         self.assign_roles_to_cluster_node_ids()
80
81         self.configure_environment()
82
83         self.deploy_cloud()
84
85
86 def parse_arguments():
87     parser = ArgParser(prog='python %s' % __file__)
88     parser.add_argument('-nh', dest='no_health_check', action='store_true',
89                         default=False,
90                         help='Don\'t run health check after deployment')
91     parser.add_argument('dea_file', action='store',
92                         help='Deployment Environment Adapter: dea.yaml')
93     parser.add_argument('blade_node_file', action='store',
94                         help='Blade Node mapping: blade_node.yaml')
95     args = parser.parse_args()
96     check_file_exists(args.dea_file)
97     check_file_exists(args.blade_node_file)
98     return (args.dea_file, args.blade_node_file, args.no_health_check)
99
100
101 def main():
102     dea_file, blade_node_file, no_health_check = parse_arguments()
103     deploy = Deploy(dea_file, blade_node_file, no_health_check)
104     deploy.deploy()
105
106 if __name__ == '__main__':
107     main()