Creating virtual machines with Xen Cloud Control System and Xen Cloud Platform


One of the things that people dipping their toes into Xen Cloud Platform for the first time seem to have trouble with is creating new virtual machines from the command line, assuming they don’t want to run a nice front end like my Xen Cloud Control System :). Here’s a brief tutorial of the steps to create an XCP virtual machine from the command line, along with the XCCS virtual machine creator scripts.

Vern
Xen Cloud Control System
http://www.xencloudcontrol.com

Xen Cloud Control System Programming Notes

Modules centos.cgi, ubuntu.cgi, and debian.cgi are the Linux virtual
machine creators for XCCS. The program steps listed below apply to
all three except where noted.

Program steps:

1. Convert the disk capacity passed from the form from GB to bytes.

2. Convert the memory size passed from the form from GB to bytes.

3. Set the disk size in the template for this Linux type. The template
is set by the XCCS configuration utility and read from the config file.

4. Read in the user profile information from the user file and build
the name label for the VM. The name label is day of the year, year,
hour, minute, second.

5. Install the virtual machine.

6. Build the name description for the virtual machine. The name
description is the user’s user ID and group ID.

7. Set the name description on the new virtual machine.

8. Get the network UUIDs for the first and second Ethernet bridges to
use. The bridges are set by the XCCS configuration utility and read
from the config file.

9. Attach virtual interfaces between the bridges and the virtual
machine. The first virtual interface is eth0 on the virtual machine,
etc.

10. If the kickstart server information is configured and enabled, set
the kickstart parameters in the virtual machine (CentOS, Oracle, and
Red Hat only).

11. Set the memory in the virtual machine.

12. Set the number of vCPUs in the virtual machine.

13. Set the installation respository URL to install the OS over the
network (CentOS and Debian only).

13a. Set the installation repository URL based on whether server load
or desktop load was selected (Ubuntu only).

14. Set the XCCS virtual machine watchdog and activate.

15. Start the new virtual machine on the pool master.

#! /bin/sh
# This software is authored and copyright by Vern Burke (vburke@skow.net)
# and released for public use in accordance with the terms of the
# GNU General Public License, v2 or higher. Any redistribution of original
# or modified versions of this software must contain this copyright notice.
# centos.cgi, ver 0.11
# Input variables are vmtype, memory, label, vCPU
# read variables from cloud.cfg
HOST=$(grep HOST ./cloud.cfg | cut -d” ” -f2)
USER=$(grep USER ./cloud.cfg | cut -d” ” -f2)
PASS=$(grep PASS ./cloud.cfg | cut -d” ” -f2)
ENABLE_KS=$(grep ENABLE_KS cloud.cfg | cut -d” ” -f2)
SR_UUID=$(grep SRUUID cloud.cfg | cut -d” ” -f2)
INSTREP=$(grep RH_REPO cloud.cfg | cut -d” ” -f2)
KSSRV=$(grep KSSRV cloud.cfg | cut -d” ” -f2)
KSDEV=$(grep KSDEV cloud.cfg | cut -d” ” -f2)
RH_TEMP_UUID=$(grep RH_TEMP_UUID cloud.cfg | cut -d” ” -f2)
NETBRIDGE1=$(grep BRIDGE1 cloud.cfg | cut -d” ” -f2)
NETBRIDGE2=$(grep BRIDGE2 cloud.cfg | cut -d” ” -f2)
USEALTPM=$(grep USEALTPM ./cloud.cfg | cut -d” ” -f2)
ALTPMNAME=$(grep ALTPMNAME ./cloud.cfg | cut -d” ” -f2)
# check to see if we’re running from the alternate pool master
if [ “$USEALTPM” = “YES” ]
then
HOST=$ALTPMNAME
fi
# html header
echo ‘Content-type: text/html’
echo
echo ”
echo ”
echo ‘Xen Cloud Control System
echo ”
echo ”
echo ”
# check for no permission
REQ_USER_PERM=$(sh ./user-get-perm.sh $REMOTE_USER)
if [ “$REQ_USER_PERM” != “All” ]
then
echo “Sorry, you do not have permission to execute this action!”
exit
fi
cat ./xccs-header.html
echo ‘


# set actual disk size value
DSK=$(echo “scale=2;$WWW_disk*1073741824” | bc)
# set actual memory size value
MEM=$(echo “scale=2;$WWW_memory*1073741824″ | bc)
# set disk size
echo ‘setting disk size …’
xe template-param-set -s $HOST -pw $PASS -u $USER uuid=$RH_TEMP_UUID other-config:disks=””
# build name-label and name description for the new VM
USER_NAME=$REMOTE_USER
USER_PERM=$(sh ./user-get-perm.sh $USER_NAME)
USER_ID=$(sh ./user-get-user-id.sh $USER_NAME)
GRP_ID=$(sh ./user-get-group-id.sh $USER_NAME)
# build new label
echo ‘Building name label …

VM_LABEL=$(date +%j%Y%H%M%S)
# install VM
echo ‘Installing VM …

VM=$(xe vm-install -s $HOST -pw $PASS -u $USER template=”$RH_TEMP_UUID” new-name-label=$VM_LABEL sr-uuid=$SR_UUID)
# build new description
VM_DESCR=$(echo $USER_ID’-‘$GRP_ID’-1′)
# set new description
echo ‘Setting description …

xe vm-param-set -s $HOST -pw $PASS -u $USER uuid=$VM name-description=$VM_DESCR
# get network UUIDs for first and second Ethernet bridges
NETWORK1=$(xe network-list -s $HOST -pw $PASS -u $USER bridge=$NETBRIDGE1 params=uuid –minimal)
NETWORK2=$(xe network-list -s $HOST -pw $PASS -u $USER bridge=$NETBRIDGE2 params=uuid –minimal)
# create VM vif0 and vif1
echo ‘Creating network interfaces …

VIF0=$(xe vif-create -s $HOST -pw $PASS -u $USER vm-uuid=$VM network-uuid=$NETWORK1 mac=random device=0)
VIF1=$(xe vif-create -s $HOST -pw $PASS -u $USER vm-uuid=$VM network-uuid=$NETWORK2 mac=random device=1)
# set kickstart file
if [ “$ENABLE_KS” = “YES” ]
then
echo ‘Setting kickstart …

xe vm-param-set -s $HOST -pw $PASS -u $USER uuid=$VM PV-args=”ks=$KSSRV ksdevice=$KSDEV”
fi
# set memory maximum
echo ‘Setting memory …

xe vm-param-set -s $HOST -pw $PASS -u $USER uuid=$VM memory-dynamic-max=$MEM
xe vm-param-set -s $HOST -pw $PASS -u $USER uuid=$VM memory-static-max=$MEM
# set number of vCPUs
echo ‘Setting vCPUs …

xe vm-param-set -s $HOST -pw $PASS -u $USER uuid=$VM VPUs-max=$WWW_vCPU
# set install repository to local install server
echo ‘Setting install repository …

xe vm-param-set -s $HOST -pw $PASS -u $USER uuid=$VM other-config:install-repository=”$INSTREP”
# set watchdog priority 3 on this vm
echo ‘Setting watchdog …

xe vm-param-set -s $HOST -pw $PASS -u $USER uuid=$VM ha-restart-priority=3
xe vm-param-set -s $HOST -pw $PASS -u $USER uuid=$VM ha-always-run=true
# get the pool master UUID
PM=$(xe pool-list -s $HOST -pw $PASS -u $USER params=master –minimal)
# start the VM on the pool master
echo ‘Starting the VM …

VM_START=$(xe vm-start -s $HOST -pw $PASS -u $USER uuid=$VM on=$PM)
echo ‘Virtual machine ‘ $WWW_label ‘is complete!’
echo ‘


echo ”
echo ”

Advertisements

One response to “Creating virtual machines with Xen Cloud Control System and Xen Cloud Platform

  1. Surely, in the spirit of devops, the approach should be to automate this process and then put the creation script under version control, so that you can guarantee to cookie cut the configuration between distro releases 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s