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 ###############################################################################
17 from dea import DeploymentEnvironmentAdapter
18 from configure_environment import ConfigureEnvironment
19 from deployment import Deployment
21 YAML_CONF_DIR = '/var/lib/opnfv'
27 exec_cmd = common.exec_cmd
30 check_file_exists = common.check_file_exists
32 commafy = common.commafy
33 ArgParser = common.ArgParser
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 = {}
47 self.wanted_release = self.dea.get_property('wanted_release')
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)
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)
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:
64 config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR,
67 config_env.configure_environment()
68 self.env_id = config_env.env_id
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)
77 self.get_blade_node_mapping()
79 self.assign_roles_to_cluster_node_ids()
81 self.configure_environment()
86 def parse_arguments():
87 parser = ArgParser(prog='python %s' % __file__)
88 parser.add_argument('-nh', dest='no_health_check', action='store_true',
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)
102 dea_file, blade_node_file, no_health_check = parse_arguments()
103 deploy = Deploy(dea_file, blade_node_file, no_health_check)
106 if __name__ == '__main__':