#!/bin/bash -e # shellcheck disable=SC2155,SC1001 ############################################################################## # Copyright (c) 2017 Mirantis Inc., Enea AB and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## # # Library of shell functions # function generate_ssh_key { local mcp_ssh_key=$(basename "${SSH_KEY}") local user=${USER} if [ -n "${SUDO_USER}" ] && [ "${SUDO_USER}" != 'root' ]; then user=${SUDO_USER} fi if [ -f "${SSH_KEY}" ]; then cp "${SSH_KEY}" . ssh-keygen -f "${mcp_ssh_key}" -y > "${mcp_ssh_key}.pub" fi [ -f "${mcp_ssh_key}" ] || ssh-keygen -f "${mcp_ssh_key}" -N '' sudo install -D -o "${user}" -m 0600 "${mcp_ssh_key}" "${SSH_KEY}" } function get_base_image { local base_image=$1 local image_dir=$2 mkdir -p "${image_dir}" wget --progress=dot:giga -P "${image_dir}" -N "${base_image}" } function __kernel_modules { # Load mandatory kernel modules: loop, nbd local image_dir=$1 sudo modprobe loop if sudo modprobe nbd max_part=8 || sudo modprobe -f nbd max_part=8; then return 0 fi # CentOS (or RHEL family in general) do not provide 'nbd' out of the box echo "[WARN] 'nbd' kernel module cannot be loaded!" if [ ! -e /etc/redhat-release ]; then echo "[ERROR] Non-RHEL system detected, aborting!" echo "[ERROR] Try building 'nbd' manually or install it from a 3rd party." exit 1 fi # Best-effort attempt at building a non-maintaned kernel module local __baseurl local __subdir local __uname_r=$(uname -r) local __uname_m=$(uname -m) if [ "${__uname_m}" = 'x86_64' ]; then __baseurl='http://vault.centos.org/centos' __subdir='Source/SPackages' __srpm="kernel-${__uname_r%.${__uname_m}}.src.rpm" else __baseurl='http://vault.centos.org/altarch' __subdir="Source/${__uname_m}/Source/SPackages" # NOTE: fmt varies across releases (e.g. kernel-alt-4.11.0-44.el7a.src.rpm) __srpm="kernel-alt-${__uname_r%.${__uname_m}}.src.rpm" fi local __found='n' local __versions=$(curl -s "${__baseurl}/" | grep -Po 'href="\K7\.[\d\.]+') for ver in ${__versions}; do for comp in os updates; do local url="${__baseurl}/${ver}/${comp}/${__subdir}/${__srpm}" if wget "${url}" -O "${image_dir}/${__srpm}" > /dev/null 2>&1; then __found='y'; break 2 fi done done if [ "${__found}" = 'n' ]; then echo "[ERROR] Can't find the linux kernel SRPM for: ${__uname_r}" echo "[ERROR] 'nbd' module cannot be built, aborting!" echo "[ERROR] Try 'yum upgrade' or building 'nbd' krn module manually ..." exit 1 fi rpm -ivh "${image_dir}/${__srpm}" 2> /dev/null mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} # shellcheck disable=SC2016 echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros ( cd ~/rpmbuild/SPECS rpmbuild -bp --nodeps --target="${__uname_m}" kernel*.spec cd ~/rpmbuild/BUILD/"${__srpm%.src.rpm}"/linux-* sed -i 's/^.*\(CONFIG_BLK_DEV_NBD\).*$/\1=m/g' .config # http://centosfaq.org/centos/nbd-does-not-compile-for-3100-514262el7x86_64 if grep -Rq 'REQ_TYPE_DRV_PRIV' drivers/block; then sed -i 's/REQ_TYPE_SPECIAL/REQ_TYPE_DRV_PRIV/g' drivers/block/nbd.c fi gunzip -c "/boot/symvers-${__uname_r}.gz" > Module.symvers make prepare modules_prepare make M=drivers/block -j modinfo drivers/block/nbd.ko sudo mkdir -p "/lib/modules/${__uname_r}/extra/" sudo cp drivers/block/nbd.ko "/lib/modules/${__uname_r}/extra/" ) sudo depmod -a sudo modprobe nbd max_part=8 || sudo modprobe -f nbd max_part=8 } function mount_image { local image=$1 local image_dir=$2 OPNFV_MNT_DIR="${image_dir}/ubuntu" # Find free nbd, loop devices for dev in '/sys/class/block/nbd'*; do if [ "$(cat "${dev}/size")" = '0' ]; then OPNFV_NBD_DEV=/dev/$(basename "${dev}") break fi done OPNFV_LOOP_DEV=$(losetup -f) OPNFV_MAP_DEV=/dev/mapper/$(basename "${OPNFV_NBD_DEV}")p1 export OPNFV_MNT_DIR OPNFV_LOOP_DEV [ -n "${OPNFV_NBD_DEV}" ] && [ -n "${OPNFV_LOOP_DEV}" ] || exit 1 qemu-img resize "${image_dir}/${image}" 3G sudo qemu-nbd --connect="${OPNFV_NBD_DEV}" --aio=native --cache=none \ "${image_dir}/${image}" sudo kpartx -av "${OPNFV_NBD_DEV}" sleep 5 # /dev/nbdNp1 takes some time to come up # Hardcode partition index to 1, unlikely to change for Ubuntu UCA image if sudo growpart "${OPNFV_NBD_DEV}" 1; then sudo kpartx -u "${OPNFV_NBD_DEV}" sudo e2fsck -pf "${OPNFV_MAP_DEV}" sudo resize2fs "${OPNFV_MAP_DEV}" fi # grub-update does not like /dev/nbd*, so use a loop device to work around it sudo losetup "${OPNFV_LOOP_DEV}" "${OPNFV_MAP_DEV}" mkdir -p "${OPNFV_MNT_DIR}" sudo mount "${OPNFV_LOOP_DEV}" "${OPNFV_MNT_DIR}" sudo mount -t proc proc "${OPNFV_MNT_DIR}/proc" sudo mount -t sysfs sys "${OPNFV_MNT_DIR}/sys" sudo mount -o bind /dev "${OPNFV_MNT_DIR}/dev" sudo mkdir -p "${OPNFV_MNT_DIR}/run/resolvconf" sudo cp /etc/resolv.conf "${OPNFV_MNT_DIR}/run/resolvconf" echo "GRUB_DISABLE_OS_PROBER=true" | \ sudo tee -a "${OPNFV_MNT_DIR}/etc/default/grub" sudo sed -i -e 's/^\(GRUB_TIMEOUT\)=.*$/\1=1/g' -e 's/^GRUB_HIDDEN.*$//g' \ "${OPNFV_MNT_DIR}/etc/default/grub" } function apt_repos_pkgs_image { local apt_key_urls=(${1//,/ }) local all_repos=(${2//,/ }) local pkgs_i=(${3//,/ }) local pkgs_r=(${4//,/ }) [ -n "${OPNFV_MNT_DIR}" ] || exit 1 # APT keys if [ "${#apt_key_urls[@]}" -gt 0 ]; then for apt_key in "${apt_key_urls[@]}"; do sudo chroot "${OPNFV_MNT_DIR}" /bin/bash -c
heat_template_version: pike
description: >
Qpid dispatch router service configured with Puppet
parameters:
ServiceData:
default: {}
description: Dictionary packing service data
type: json
ServiceNetMap:
default: {}
description: Mapping of service_name -> network name. Typically set
via parameter_defaults in the resource registry. This
mapping overrides those in ServiceNetMapDefaults.
type: json
DefaultPasswords:
default: {}
type: json
RoleName:
default: ''
description: Role name on which the service is applied
type: string
RoleParameters:
default: {}
description