1 ##############################################################################
2 # Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others.
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 ##############################################################################
10 # Used to modify undercloud qcow2 image
16 from apex.common import constants as con
17 from apex.common import utils
18 from apex.virtual import utils as virt_utils
21 def add_upstream_packages(image):
23 Adds required base upstream packages to Undercloud for deployment
32 'python2-networking-sfc',
33 'openstack-ironic-inspector',
35 'docker-distribution',
36 'openstack-tripleo-validations',
39 'python-tripleoclient',
40 'openstack-tripleo-heat-templates'
42 # Remove incompatible python-docker version
43 virt_ops.append({con.VIRT_RUN_CMD: "yum remove -y python-docker-py"})
46 virt_ops.append({con.VIRT_INSTALL: pkg})
47 virt_utils.virt_customize(virt_ops, image)
50 def inject_calipso_installer(tmp_dir, image):
52 Downloads calipso installer script from artifacts.opnfv.org
53 and puts it under /root/ for further installation process.
56 calipso_file = os.path.basename(con.CALIPSO_INSTALLER_URL)
57 calipso_url = con.CALIPSO_INSTALLER_URL.replace(calipso_file, '')
58 utils.fetch_upstream_and_unpack(tmp_dir, calipso_url, [calipso_file])
61 {con.VIRT_UPLOAD: "{}/{}:/root/".format(tmp_dir, calipso_file)}]
62 virt_utils.virt_customize(virt_ops, image)
63 logging.info("Calipso injected into {}".format(image))
65 # TODO(trozet): add unit testing for calipso injector
66 # TODO(trozet): add rest of build for undercloud here as well
69 def update_repos(image, branch):
71 {con.VIRT_RUN_CMD: "rm -f /etc/yum.repos.d/delorean*"},
72 {con.VIRT_RUN_CMD: "yum-config-manager --add-repo "
73 "https://trunk.rdoproject.org/centos7/{}"
74 "/delorean.repo".format(con.RDO_TAG)},
75 {con.VIRT_RUN_CMD: "yum clean all"},
76 {con.VIRT_INSTALL: "python2-tripleo-repos"},
77 {con.VIRT_RUN_CMD: "tripleo-repos -b {} {} ceph".format(branch,
80 virt_utils.virt_customize(virt_ops, image)
83 def expand_disk(image, desired_size=50):
85 Expands a disk image to desired_size in GigaBytes
86 :param image: image to resize
87 :param desired_size: desired size in GB
90 # there is a lib called vminspect which has some dependencies and is
91 # not yet available in pip. Consider switching to this lib later.
93 img_out = json.loads(subprocess.check_output(
94 ['qemu-img', 'info', '--output=json', image],
95 stderr=subprocess.STDOUT).decode())
96 disk_gb_size = int(img_out['virtual-size'] / 1000000000)
97 if disk_gb_size < desired_size:
98 logging.info("Expanding disk image: {}. Current size: {} is less"
99 "than require size: {}".format(image, disk_gb_size,
101 diff_size = desired_size - disk_gb_size
102 subprocess.check_call(['qemu-img', 'resize', image,
103 "+{}G".format(diff_size)],
104 stderr=subprocess.STDOUT)
106 except (subprocess.CalledProcessError, json.JSONDecodeError, KeyError) \
108 logging.warning("Unable to resize disk, disk may not be large "
109 "enough: {}".format(e))