update build lxc/kvm variables to GUEST instead of CONTAINER

This commit is contained in:
Jesse Andrews 2011-10-22 20:56:23 -07:00
parent ccc11c9d18
commit 82040df0da
3 changed files with 39 additions and 40 deletions

View file

@ -46,19 +46,19 @@ DIST_NAME=${DIST_NAME:-natty}
IMAGE_FNAME=$DIST_NAME.raw
# Name of our instance, used by libvirt
CONTAINER_NAME=${CONTAINER_NAME:-kvmstack}
GUEST_NAME=${GUEST_NAME:-kvmstack}
# Original version of built image
BASE_IMAGE=$KVMSTACK_DIR/images/$DIST_NAME.raw
# Copy of base image, which we pre-install with tasty treats
VM_IMAGE=$IMAGES_DIR/$DIST_NAME.$CONTAINER_NAME.raw
VM_IMAGE=$IMAGES_DIR/$DIST_NAME.$GUEST_NAME.raw
# Mop up after previous runs
virsh destroy $CONTAINER_NAME
virsh destroy $GUEST_NAME
# Where this vm is stored
VM_DIR=$KVMSTACK_DIR/instances/$CONTAINER_NAME
VM_DIR=$KVMSTACK_DIR/instances/$GUEST_NAME
# Create vm dir
mkdir -p $VM_DIR
@ -156,21 +156,20 @@ cd $TOP_DIR
# Network configuration variables
BRIDGE=${BRIDGE:-br0}
CONTAINER=${CONTAINER:-STACK}
CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
CONTAINER_MAC=${CONTAINER_MAC:-"02:16:3e:07:69:`printf '%02X' $(echo $CONTAINER_IP | sed "s/.*\.//")`"}
CONTAINER_RAM=${CONTAINER_RAM:-1524288}
CONTAINER_CORES=${CONTAINER_CORES:-1}
GUEST_IP=${GUEST_IP:-192.168.1.50}
GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24}
GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0}
GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.1.1}
GUEST_MAC=${GUEST_MAC:-"02:16:3e:07:69:`printf '%02X' $(echo $GUEST_IP | sed "s/.*\.//")`"}
GUEST_RAM=${GUEST_RAM:-1524288}
GUEST_CORES=${GUEST_CORES:-1}
# libvirt.xml configuration
LIBVIRT_XML=$VM_DIR/libvirt.xml
cat > $LIBVIRT_XML <<EOF
<domain type='kvm'>
<name>$CONTAINER_NAME</name>
<memory>$CONTAINER_RAM</memory>
<name>$GUEST_NAME</name>
<memory>$GUEST_RAM</memory>
<os>
<type>hvm</type>
<bootmenu enable='yes'/>
@ -178,7 +177,7 @@ cat > $LIBVIRT_XML <<EOF
<features>
<acpi/>
</features>
<vcpu>$CONTAINER_CORES</vcpu>
<vcpu>$GUEST_CORES</vcpu>
<devices>
<disk type='file'>
<driver type='qcow2'/>
@ -188,7 +187,7 @@ cat > $LIBVIRT_XML <<EOF
<interface type='bridge'>
<source bridge='$BRIDGE'/>
<mac address='$CONTAINER_MAC'/>
<mac address='$GUEST_MAC'/>
</interface>
<!-- The order is significant here. File must be defined first -->
@ -250,9 +249,9 @@ iface lo inet loopback
auto eth0
iface eth0 inet static
address $CONTAINER_IP
netmask $CONTAINER_NETMASK
gateway $CONTAINER_GATEWAY
address $GUEST_IP
netmask $GUEST_NETMASK
gateway $GUEST_GATEWAY
EOF
# User configuration for the instance

View file

@ -27,11 +27,11 @@ CWD=`pwd`
# Configurable params
BRIDGE=${BRIDGE:-br0}
CONTAINER_NAME=${CONTAINER_NAME:-STACK}
CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
GUEST_NAME=${GUEST_NAME:-STACK}
GUEST_IP=${GUEST_IP:-192.168.1.50}
GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24}
GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0}
GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.1.1}
NAMESERVER=${NAMESERVER:-`cat /etc/resolv.conf | grep nameserver | head -1 | cut -d " " -f2`}
COPYENV=${COPYENV:-1}
DEST=${DEST:-/opt/stack}
@ -60,22 +60,22 @@ if ! which cgdelete | grep -q cgdelete; then
fi
# Create lxc configuration
LXC_CONF=/tmp/$CONTAINER_NAME.conf
LXC_CONF=/tmp/$GUEST_NAME.conf
cat > $LXC_CONF <<EOF
lxc.network.type = veth
lxc.network.link = $BRIDGE
lxc.network.flags = up
lxc.network.ipv4 = $CONTAINER_CIDR
lxc.network.ipv4 = $GUEST_CIDR
# allow tap/tun devices
lxc.cgroup.devices.allow = c 10:200 rwm
EOF
# Shutdown any existing container
lxc-stop -n $CONTAINER_NAME
lxc-stop -n $GUEST_NAME
# This kills zombie containers
if [ -d /cgroup/$CONTAINER_NAME ]; then
cgdelete -r cpu,net_cls:$CONTAINER_NAME
if [ -d /cgroup/$GUEST_NAME ]; then
cgdelete -r cpu,net_cls:$GUEST_NAME
fi
# git clone only if directory doesn't exist already. Since ``DEST`` might not
@ -95,9 +95,9 @@ function git_clone {
# Helper to create the container
function create_lxc {
if [ "natty" = "$UBUNTU_VERSION" ]; then
lxc-create -n $CONTAINER_NAME -t natty -f $LXC_CONF
lxc-create -n $GUEST_NAME -t natty -f $LXC_CONF
else
lxc-create -n $CONTAINER_NAME -t ubuntu -f $LXC_CONF
lxc-create -n $GUEST_NAME -t ubuntu -f $LXC_CONF
fi
}
@ -117,7 +117,7 @@ fi
if [ ! -f $CACHEDIR/bootstrapped ]; then
# by deleting the container, we force lxc-create to re-bootstrap (lxc is
# lazy and doesn't do anything if a container already exists)
lxc-destroy -n $CONTAINER_NAME
lxc-destroy -n $GUEST_NAME
# trigger the initial debootstrap
create_lxc
touch $CACHEDIR/bootstrapped
@ -153,7 +153,7 @@ if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
fi
# Destroy the old container
lxc-destroy -n $CONTAINER_NAME
lxc-destroy -n $GUEST_NAME
# If this call is to TERMINATE the container then exit
if [ "$TERMINATE" = "1" ]; then
@ -164,7 +164,7 @@ fi
create_lxc
# Specify where our container rootfs lives
ROOTFS=/var/lib/lxc/$CONTAINER_NAME/rootfs/
ROOTFS=/var/lib/lxc/$GUEST_NAME/rootfs/
# Create a stack user that is a member of the libvirtd group so that stack
# is able to interact with libvirt.
@ -214,9 +214,9 @@ iface lo inet loopback
auto eth0
iface eth0 inet static
address $CONTAINER_IP
netmask $CONTAINER_NETMASK
gateway $CONTAINER_GATEWAY
address $GUEST_IP
netmask $GUEST_NETMASK
gateway $GUEST_GATEWAY
EOF
# Configure the runner
@ -227,7 +227,7 @@ cat > $RUN_SH <<EOF
echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0
# Make there is a default route - needed for natty
if ! route | grep -q default; then
sudo ip route add default via $CONTAINER_GATEWAY
sudo ip route add default via $GUEST_GATEWAY
fi
sleep 1
@ -265,7 +265,7 @@ if ! mount | grep -q cgroup; then
fi
# Start our container
lxc-start -d -n $CONTAINER_NAME
lxc-start -d -n $GUEST_NAME
if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
# Done creating the container, let's tail the log

View file

@ -18,7 +18,7 @@ COMMON_VARS="MYSQL_HOST=$HEAD_HOST RABBIT_HOST=$HEAD_HOST GLANCE_HOSTPORT=$HEAD_
# Helper to launch containers
function run_lxc {
# For some reason container names with periods can cause issues :/
CONTAINER_NAME=$1 CONTAINER_IP=$2 CONTAINER_NETMASK=$NETMASK CONTAINER_GATEWAY=$GATEWAY NAMESERVER=$NAMESERVER TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $3" ./build_lxc.sh
GUEST_NAME=$1 GUEST_IP=$2 GUEST_NETMASK=$NETMASK GUEST_GATEWAY=$GATEWAY NAMESERVER=$NAMESERVER TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $3" ./build_lxc.sh
}
# Launch the head node - headnode uses a non-ip domain name,