84 lines
1.9 KiB
Bash
Executable File
84 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# Script for switching between the Ubuntu and CentOS based bootstrap images.
|
|
# Usage: fuel-bootstrap-image-set centos|ubuntu
|
|
# FIXME(azvyagintsev) https://bugs.launchpad.net/fuel/+bug/1522066
|
|
set -e
|
|
MYSELF="${0##*/}"
|
|
ASTUTE_YAML="/etc/fuel/astute.yaml"
|
|
cobbler_manifest="/etc/puppet/modules/nailgun/examples/cobbler-only.pp"
|
|
astute_manifest="/etc/puppet/modules/nailgun/examples/astute-only.pp"
|
|
|
|
run_puppet () {
|
|
local container="$1"
|
|
local manifest="$2"
|
|
local ret=''
|
|
set +e
|
|
dockerctl shell "$container" puppet apply --detailed-exitcodes -dv "$manifest"
|
|
ret=$?
|
|
set -e
|
|
if [ "$ret" = "0" ] || [ "$ret" = "2" ]; then
|
|
return 0
|
|
else
|
|
cat >&2 <<-EOF
|
|
$MYSELF: puppet apply $manifest failed: exit code $ret
|
|
$MYSELF: container: $container
|
|
EOF
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
maybe_restart_dnsmasq () {
|
|
if ! dockerctl shell cobbler service dnsmasq status >/dev/null; then
|
|
dockerctl shell cobbler service dnsmasq restart
|
|
fi
|
|
}
|
|
|
|
verify_bootstrap_flavor () {
|
|
local flavor="$1"
|
|
if [ -z "$flavor" ]; then
|
|
cat >&2 <<-EOF
|
|
$MYSELF: error: no bootstrap image specified
|
|
Usage: $MYSELF centos|ubuntu
|
|
EOF
|
|
exit 1
|
|
fi
|
|
case "$flavor" in
|
|
centos|CentOS)
|
|
flavor='centos'
|
|
;;
|
|
ubuntu|Ubuntu)
|
|
flavor='ubuntu'
|
|
;;
|
|
*)
|
|
cat >&2 <<-EOF
|
|
$MYSELF: error: unknown bootstrap image: $flavor
|
|
$MYSELF: available bootstrap images: ubuntu, centos
|
|
EOF
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
write_astute_yaml () {
|
|
local flavor="$1"
|
|
python <<-PYEOF
|
|
from fuelmenu.fuelmenu import Settings
|
|
conf = Settings().read("$ASTUTE_YAML").get('BOOTSTRAP', {})
|
|
conf['flavor'] = "$flavor"
|
|
Settings().write({'BOOTSTRAP': conf}, outfn="$ASTUTE_YAML", defaultsfile=None)
|
|
PYEOF
|
|
}
|
|
|
|
switch_bootstrap () {
|
|
local flavor="$1"
|
|
verify_bootstrap_flavor "$flavor"
|
|
write_astute_yaml "$flavor"
|
|
run_puppet cobbler "$cobbler_manifest"
|
|
# XXX: sometimes dnsmasq stops after cobbler sync
|
|
maybe_restart_dnsmasq
|
|
run_puppet astute "$astute_manifest"
|
|
dockerctl shell astute service astute restart
|
|
}
|
|
|
|
switch_bootstrap $1
|