Date Tags ganeti

Now that my infrastructure is up and running I’d love to have a command to create a small cluster of VM for a specific purpose. Up until now to create my VMs I’ve used a simple script calling the following command line.

gnt-instance add -t plain --disk 0:size=10G --disk 1:size=1G -B memory=1024 -o debootstrap+unstable --no-ip-check --no-name-check --iallocator hail cbse4

Then reading the gnt-instance I discovered the batch-create command.

After writing the script I realized I’ve done all this just to satisfy my need of using a json snippet. But I guess my script is not longer and less understandable then before… Ah well. This is a bit from the Dpt of useless optimizations… Anyway there you go.

The gnt-instance man page is a bit low on details about the syntax to use. Looking at the queue directory (/var/lib/ganeti/queue) you can have a look at the json generated by the command line above. From there it’s easy to figure out the various options you can use.

# cat cbse.json 
{
  "cbse1": {
    "template": "plain",
    "iallocator": "hail",
    "os": "debootstrap+unstable",
    "disk_size": ["10G","1G"],
    "backend": {"memory": 1024},
    "ip_check" : false,
    "name_check": false
  }
}

Once you got this bit, we can easily script the creation of multiple instance :

#!/bin/bash

set -x 
name=$1
start=$2
end=$3

tmpfile=`tempfile`

echo "{" > $tmpfile
for i in $(eval echo {$start..$end}); do

cat >> $tmpfile <<EOF
  "$name$i": {
    "template": "plain",
    "iallocator": "hail",
    "os": "debootstrap+unstable",
    "disk_size": ["10G","1G"],
    "backend": {"memory": 1024},
    "ip_check" : false,
    "name_check": false
  }
EOF

if [ $i != $end ]; then
    echo "," >> $tmpfile
fi

done
echo "}" >> $tmpfile

cat $tmpfile
gnt-instance batch-create $tmpfile

Consider that the json snippet above can include a number of other parameters specific to the hypervisor you are using. In my setup, I’ve configured the hypervisor once for all with the following options:

gnt-cluster modify --hypervisor-parameter xen-pvm:root_path='/dev/xvda1'
gnt-cluster modify --hypervisor-parameter xen-pvm:initrd_path='/boot/initrd-2.6-xenU'