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, plugins_dir,
40 self.dea = DeploymentEnvironmentAdapter(dea_file)
41 self.blade_node_file = blade_node_file
42 self.plugins_dir = plugins_dir
43 self.no_health_check = no_health_check
44 self.macs_per_blade = {}
45 self.blades = self.dea.get_node_ids()
46 self.blade_node_dict = {}
47 self.node_roles_dict = {}
49 self.wanted_release = self.dea.get_property('wanted_release')
51 def get_blade_node_mapping(self):
52 with io.open(self.blade_node_file, 'r') as stream:
53 self.blade_node_dict = yaml.load(stream)
55 def assign_roles_to_cluster_node_ids(self):
56 self.node_roles_dict = {}
57 for blade, node in self.blade_node_dict.iteritems():
58 roles = commafy(self.dea.get_node_role(blade))
59 self.node_roles_dict[node] = (roles, blade)
61 def configure_environment(self):
62 release_list = parse(exec_cmd('fuel release -l'))
63 for release in release_list:
64 if release[R['name']] == self.wanted_release:
66 config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR,
69 config_env.configure_environment()
70 self.env_id = config_env.env_id
72 def deploy_cloud(self):
73 dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id,
74 self.node_roles_dict, self.no_health_check)
77 def install_plugins(self):
78 log('Installing Fuel Plugins')
79 if self.plugins_dir and os.path.isdir(self.plugins_dir):
80 for f in glob.glob('%s/*.rpm' % self.plugins_dir):
81 log('Found plugin %s, installing ...' % f)
82 r, c = exec_cmd('fuel plugins --install %s' % f, False)
83 if c > 0 and 'does not update installed package' not in r:
84 err('Installation of Fuel Plugin %s failed' % f)
88 self.install_plugins()
90 self.get_blade_node_mapping()
92 self.assign_roles_to_cluster_node_ids()
94 self.configure_environment()
99 def parse_arguments():
100 parser = ArgParser(prog='python %s' % __file__)
101 parser.add_argument('-nh', dest='no_health_check', action='store_true',
103 help='Don\'t run health check after deployment')
104 parser.add_argument('dea_file', action='store',
105 help='Deployment Environment Adapter: dea.yaml')
106 parser.add_argument('blade_node_file', action='store',
107 help='Blade Node mapping: blade_node.yaml')
108 parser.add_argument('plugins_dir', nargs='?', action='store',
109 help='Plugins directory')
110 args = parser.parse_args()
111 check_file_exists(args.dea_file)
112 check_file_exists(args.blade_node_file)
113 return (args.dea_file, args.blade_node_file, args.plugins_dir,
114 args.no_health_check)
119 dea_file, blade_node_file, plugins_dir, no_health_check = parse_arguments()
121 deploy = Deploy(dea_file, blade_node_file, plugins_dir, no_health_check)
124 if __name__ == '__main__':