From 3dfad32d4c35b62f60612889e515300479e599ed Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 19 Nov 2012 17:24:01 +0100 Subject: [PATCH] add new type: __localch_kvm_vm Signed-off-by: Nico Schottelius --- cdist/conf/type/__localch_kvm_vm/README | 10 +++ cdist/conf/type/__localch_kvm_vm/manifest | 72 +++++++++++++++++++ .../type/__localch_kvm_vm/parameter/optional | 4 ++ .../type/__localch_kvm_vm/parameter/required | 2 + 4 files changed, 88 insertions(+) create mode 100644 cdist/conf/type/__localch_kvm_vm/README create mode 100644 cdist/conf/type/__localch_kvm_vm/manifest create mode 100644 cdist/conf/type/__localch_kvm_vm/parameter/optional create mode 100644 cdist/conf/type/__localch_kvm_vm/parameter/required diff --git a/cdist/conf/type/__localch_kvm_vm/README b/cdist/conf/type/__localch_kvm_vm/README new file mode 100644 index 00000000..9752aad2 --- /dev/null +++ b/cdist/conf/type/__localch_kvm_vm/README @@ -0,0 +1,10 @@ +To be executed on the Xen Host. +Using "xe" tool from Citrix Xen. + +Todo: + + - Setup DNS -> bind + - via puppet + - move away from puppet to cdist (intrusive) + - Boot VM + - Kickstart diff --git a/cdist/conf/type/__localch_kvm_vm/manifest b/cdist/conf/type/__localch_kvm_vm/manifest new file mode 100644 index 00000000..3e5df044 --- /dev/null +++ b/cdist/conf/type/__localch_kvm_vm/manifest @@ -0,0 +1,72 @@ +################################################################################ +# Default VM parameters +# +cores=4 +memory=$((8*1024*1024*1024)) +system_disk_size=$((50*1024*1024*1024)) + +[ -f "$__object/parameter/memory" ] && memory="$(cat "$__object/parameter/memory")" +[ -f "$__object/parameter/cores" ] && cores="$(cat "$__object/parameter/cores")" +[ -f "$__object/parameter/system-disk-size" ] && system_disk_size="$(cat "$__object/parameter/system-disk-size")" + +# Convert memory to MiB (kvm/qemu requirement) +memory_mebibytes=$(($memory/(1024*1024))) + +################################################################################ +# Required VM parameters +# +nic_pz="$(cat "$__object/parameter/nic-pz")" +nic_fz="$(cat "$__object/parameter/nic-fz")" +vm=$__object_id + +basedir=/opt/local.ch/sys/kvm/vm/$vm +system_disk=$basedir/system-disk +start_on_boot=$basedir/start-on-boot +vnc_socket=unix:$basedir/vnc +pidfile=$basedir/pid +monitor=$basedir/monitor + +mkdir -p "$__object/files" +start_file_source=$__object/files/start +start_file_destination=$basedir/start + +#Base VM directory +__directory $basedir --parents yes \ + --owner root --group root + +cat << eof > "$start_file_source" +#!/bin/sh +# Generated shell script - do not modify +# + +/usr/libexec/qemu-kvm \\ + -name $vm \\ + -enable-kvm \\ + -m $memory_mebibytes \\ + -drive file=${system_disk},if=virtio \\ + -vnc $vnc_socket \\ + -cpu host \\ + -boot order=nc \\ + -pidfile "$pidfile" \\ + -monitor "unix:$monitor,server,nowait" \\ + -net nic,macaddr=$nic_pz,model=virtio,vlan=200 \\ + -net tap,script=/opt/local.ch/sys/kvm/bin/ifup-pz,downscript=/opt/local.ch/sys/kvm/bin/ifdown,vlan=200 \\ + -net nic,macaddr=$nic_fz,model=virtio,vlan=300 \\ + -net tap,script=/opt/local.ch/sys/kvm/bin/ifup-fz,downscript=/opt/local.ch/sys/kvm/bin/ifdown,vlan=300 \\ + -smp $cores +eof + +require="__directory/$basedir" __file $start_file_destination \ + --source $start_file_source --mode 0755 --owner root --group root + +require="__directory/$basedir" __qemu_img "$system_disk" \ + --size "$system_disk_size" + +# Normally, create a flag to start a VM on boot (if not +# explicitly told we should not) +if [ ! -f "$__object/parameter/do-not-start-on-boot" ]; then + require="__directory/$basedir" __file "$start_on_boot" \ + --mode 0600 --owner root --group root +else + __file "$start_on_boot" --state absent +fi diff --git a/cdist/conf/type/__localch_kvm_vm/parameter/optional b/cdist/conf/type/__localch_kvm_vm/parameter/optional new file mode 100644 index 00000000..1b05d9fb --- /dev/null +++ b/cdist/conf/type/__localch_kvm_vm/parameter/optional @@ -0,0 +1,4 @@ +cores +memory +system-disk-size +do-not-start-on-boot diff --git a/cdist/conf/type/__localch_kvm_vm/parameter/required b/cdist/conf/type/__localch_kvm_vm/parameter/required new file mode 100644 index 00000000..01161205 --- /dev/null +++ b/cdist/conf/type/__localch_kvm_vm/parameter/required @@ -0,0 +1,2 @@ +nic-pz +nic-fz