Adds ability to deploy from upstream openstack
[apex.git] / apex / builders / overcloud_builder.py
1 ##############################################################################
2 # Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others.
3 #
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 # Used to modify overcloud qcow2 image
11
12 import logging
13
14 from apex.builders import common_builder as c_builder
15 from apex.common import constants as con
16 from apex.virtual import utils as virt_utils
17
18
19 def inject_opendaylight(odl_version, image, tmp_dir):
20     assert odl_version in con.VALID_ODL_VERSIONS
21     # add repo
22     if odl_version == 'master':
23         odl_pkg_version = con.VALID_ODL_VERSIONS[-2]
24         branch = odl_version
25     else:
26         odl_pkg_version = odl_version
27         branch = "stable/{}".format(odl_version)
28     odl_url = "https://nexus.opendaylight.org/content/repositories" \
29               "/opendaylight-{}-epel-7-x86_64-devel/".format(odl_pkg_version)
30     repo_name = "opendaylight-{}".format(odl_pkg_version)
31     c_builder.add_repo(odl_url, repo_name, image, tmp_dir)
32     # download puppet-opendaylight
33     archive = c_builder.create_git_archive(
34         repo_url=con.PUPPET_ODL_URL, repo_name='puppet-opendaylight',
35         tmp_dir=tmp_dir, branch=branch, prefix='opendaylight/')
36     # install ODL, puppet-odl
37     virt_ops = [
38         {con.VIRT_INSTALL: 'opendaylight'},
39         {con.VIRT_UPLOAD: "{}:/etc/puppet/modules/".format(archive)},
40         {con.VIRT_RUN_CMD: 'rm -rf /etc/puppet/modules/opendaylight'},
41         {con.VIRT_RUN_CMD: "cd /etc/puppet/modules/ && tar xvf "
42                            "puppet-opendaylight.tar"}
43     ]
44     virt_utils.virt_customize(virt_ops, image)
45     logging.info("OpenDaylight injected into {}".format(image))