meta-data support, working
authorvarac <varacanero@zeromail.org>
Tue, 16 Oct 2012 12:00:03 +0000 (14:00 +0200)
committervarac <varacanero@zeromail.org>
Tue, 16 Oct 2012 12:00:03 +0000 (14:00 +0200)
create-guest-with-cloudinit

index ee275d0..ad1e26f 100755 (executable)
@@ -11,6 +11,7 @@ CONFIG="$ETC/cloudinit.cfg"
 VARDIR='/var/lib/libvirt/cloudinit'
 SCRIPTDIR='/usr/local/bin/leap_cloudadmin'
 KVM_URI='qemu:///system'
+SEED='cloudinit_seed.img'
 
 # overwrite defaults
 [ -e $CONFIG ] && . $CONFIG
@@ -30,6 +31,7 @@ usage() {
 Usage: ${0##*/} -s ..  guest_name
 
   Creates a new guest VM using cloud-init to utilize nocloud.
+  Uses $ETC/<guest_name>.cfg as meta- und user-data file  
 
   options:
     -h             show usage
@@ -68,15 +70,14 @@ echo "mtools_skip_check=1">~/.mtoolsrc
 
 
 vmname=$1
-userdata="$ETC/$vmname-user-data"
-
+cfg="$ETC/$vmname.cfg"
 
 [ -e /dev/$VG/$vmname ] && fail "/dev/$VG/$vmname exists - please delete it or choose another guest name"
 
-[ -e $userdata ] ||  fail "please provide userdata in $userdata"
+[ -e $cfg ] ||  fail "please provide config file in $cfg"
 
 echo
-echo "Creating guest VM $vmname with size: $size GB, using $userdata for cloud-init"
+echo "Creating guest VM $vmname with size: $size GB, using $cfg for cloud-init"
 echo "OK ? <Ctrl-C> to abort, <enter> to resume."
 read enter
 
@@ -91,11 +92,18 @@ virt-clone --connect $KVM_URI -o leap-baseimage-wheezy -n $vmname -f /dev/$VG/$v
 # resize second (root) partition
 echo ",+," | sfdisk  -N2  /dev/$VG/$vmname > /dev/null
 
-$SCRIPTDIR/libvirt-make-seed-disk $VARDIR/$vmname-user-data.img $userdata
-$SCRIPTDIR/libvirt-write-disk-attach-xml $VARDIR/$vmname-user-data.img > $VARDIR/$vmname-disk-attach.xml
+
+# create cloudinit seed disk
+
+csplit --prefix "$VARDIR/$vmname" $cfg '/#cloud-config/'
+metadata="$VARDIR/${vmname}00"
+userdata="$VARDIR/${vmname}01"
+
+$SCRIPTDIR/libvirt-make-seed-disk $VARDIR/$vmname-$SEED $userdata $metadata
+$SCRIPTDIR/libvirt-write-disk-attach-xml $VARDIR/$vmname-$SEED > $VARDIR/$vmname-disk-attach.xml
 
 echo
-echo "Attached userdata-disk is at $VARDIR/$vmname-user-data.img"
+echo "Attached cloudinit-seeddisk is at $VARDIR/$vmname-$SEED"
 echo
 echo "Finished creating guest $vmname. Enjoy."
 echo