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

View file

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