Added container-cache option to templates

This change adds in the container-cache option within the mainline
default lxc templates. The pupose here is to allow a template to
pull from a location that may not be `@LOCALSTATEDIR@/cache/lxc`

Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2015-06-10 15:06:49 -05:00
parent 2a5da24387
commit 6dc6f80bfd
10 changed files with 32 additions and 17 deletions

View File

@ -761,7 +761,8 @@ then
fi
fi
cache_base=@LOCALSTATEDIR@/cache/lxc/centos/$basearch
# Allow the cache base to be set by environment variable
cache_base=${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc"}/centos/$basearch
# Let's do something better for the initial root password.
# It's not perfect but it will defeat common scanning brute force

View File

@ -58,10 +58,11 @@ am_in_userns() {
in_userns=0
[ $(am_in_userns) = "yes" ] && in_userns=1
# Allow the cache base to be set by environment variable
if [ $(id -u) -eq 0 ]; then
CACHE_D="@LOCALSTATEDIR@/cache/lxc/cirros"
CACHE_D=${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc/cirros"}
else
CACHE_D="$HOME/.cache/lxc/cirros"
CACHE_D=${LXC_CACHE_PATH:-"$HOME/.cache/lxc/cirros"}
fi
error() { echo "$@" 1>&2; }

View File

@ -37,6 +37,8 @@ MIRROR=${MIRROR:-http://http.debian.net/debian}
SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.debian.org/}
LOCALSTATEDIR="@LOCALSTATEDIR@"
LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
# Allows the lxc-cache directory to be set by environment variable
LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc"}
configure_debian()
{
@ -293,10 +295,10 @@ copy_debian()
install_debian()
{
cache="$LOCALSTATEDIR/cache/lxc/debian"
rootfs=$1
release=$2
arch=$3
cache="$4/debian"
mkdir -p $LOCALSTATEDIR/lock/subsys/
(
flock -x 9
@ -412,7 +414,7 @@ EOF
clean()
{
cache="$LOCALSTATEDIR/cache/lxc/debian"
cache=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc/debian"}
if [ ! -e $cache ]; then
exit 0
@ -575,7 +577,7 @@ if [ -z "$rootfs" ]; then
fi
fi
install_debian $rootfs $release $arch
install_debian $rootfs $release $arch $LXC_CACHE_PATH
if [ $? -ne 0 ]; then
echo "failed to install debian"
exit 1

View File

@ -380,7 +380,9 @@ else
LXC_CACHE_BASE="$HOME/.cache/lxc/"
fi
LXC_CACHE_PATH="$LXC_CACHE_BASE/download/$DOWNLOAD_DIST"
# Allow the setting of the LXC_CACHE_PATH with the usage of environment variables.
LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LXC_CACHE_BASE"}
LXC_CACHE_PATH=$LXC_CACHE_PATH/download/$DOWNLOAD_DIST
LXC_CACHE_PATH="$LXC_CACHE_PATH/$DOWNLOAD_RELEASE/$DOWNLOAD_ARCH/"
LXC_CACHE_PATH="$LXC_CACHE_PATH/$DOWNLOAD_VARIANT"

View File

@ -1281,7 +1281,8 @@ then
fi
fi
cache_base=@LOCALSTATEDIR@/cache/lxc/fedora/$basearch
# Allow the cache base to be set by environment variable
cache_base=${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc"}/fedora/$basearch
# Let's do something better for the initial root password.
# It's not perfect but it will defeat common scanning brute force

View File

@ -805,6 +805,7 @@ do
-w|--password) forced_password=1; password=$2; shift 2;;
-s|--settings) settings=$2; shift 2;;
-m|--mirror) mirror=$2; shift 2;;
--container-cache) containercache=$2; shift 2;;
--tty) [[ $2 -lt 6 ]] && tty=$2; shift 2;;
--autologin) autologin=1; shift 1;;
--) shift 1; break ;;
@ -812,7 +813,8 @@ do
esac
done
cacheroot="@LOCALSTATEDIR@/cache/lxc/gentoo"
# Allow the cache path to be set by environment variable
cacheroot="${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc"}/gentoo"
portage_cache="${cacheroot}/portage.tbz"
cachefs="${cacheroot}/rootfs-${arch}-${variant}"

View File

@ -42,7 +42,8 @@ export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
#Configurations
#distro=cooker
hostarch=$(uname -m)
cache_base=@LOCALSTATEDIR@/cache/lxc/openmandriva/$arch
# Allow the cache base to be set by environment variable
cache_base="${LXC_CACHE_PATH:-@LOCALSTATEDIR@/cache/lxc/openmandriva/$arch}"
default_path=@LXCPATH@
default_profile=default
root_password=root

View File

@ -227,7 +227,8 @@ copy_opensuse()
install_opensuse()
{
cache="@LOCALSTATEDIR@/cache/lxc/opensuse/$DISTRO"
# Allow the cache base to be set by environment variable
cache="${LXC_CACHE_PATH:-@LOCALSTATEDIR@/cache/lxc/opensuse/$DISTRO}"
rootfs=$1
mkdir -p @LOCALSTATEDIR@/lock/subsys/
(
@ -350,7 +351,7 @@ EOF
clean()
{
cache="@LOCALSTATEDIR@/cache/lxc/opensuse"
cache="${LXC_CACHE_PATH:-@LOCALSTATEDIR@/cache/lxc/opensuse}"
if [ ! -e $cache ]; then
exit 0

View File

@ -274,10 +274,11 @@ type wget
# determine the url, tarball, and directory names
# download if needed
cache="$STATE_DIR/cache/lxc/cloud-$release"
# Allow the cache base to be set by environment variable
cache=${LXC_CACHE_PATH:-"$STATE_DIR/cache/lxc"}/cloud-$release
if [ $in_userns -eq 1 ]; then
STATE_DIR="$HOME/.cache/lxc/"
cache="$HOME/.cache/lxc/cloud-$release"
STATE_DIR="$HOME/.cache/lxc"
cache=${LXC_CACHE_PATH:-"$STATE_DIR"}/cloud-$release
fi
mkdir -p $cache

View File

@ -41,6 +41,8 @@ set -e
LOCALSTATEDIR="@LOCALSTATEDIR@"
LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
# Allows the lxc-cache directory to be set by environment variable
LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc"}
if [ -r /etc/default/lxc ]; then
. /etc/default/lxc
@ -423,7 +425,7 @@ install_ubuntu()
rootfs=$1
release=$2
flushcache=$3
cache="$LOCALSTATEDIR/cache/lxc/$release"
cache="$4/$release"
mkdir -p $LOCALSTATEDIR/lock/subsys/
(
@ -703,6 +705,7 @@ flushcache=0
packages=""
user="ubuntu"
password="ubuntu"
while true
do
case "$1" in
@ -787,7 +790,7 @@ if [ -z "$rootfs" ]; then
fi
fi
install_ubuntu $rootfs $release $flushcache
install_ubuntu $rootfs $release $flushcache $LXC_CACHE_PATH
if [ $? -ne 0 ]; then
echo "failed to install ubuntu $release"
exit 1