From 4f300ca63268f73a63e01f5528ecdc5e6f46d67e Mon Sep 17 00:00:00 2001 From: Leif Johansson Date: Wed, 22 Oct 2014 14:28:05 +0200 Subject: [PATCH] simple kvm builder using cloud images --- apt | 1 + .../etc/cosmos/apt}/bootstrap-cosmos.sh | 0 .../etc/cosmos/apt}/cosmos_1.2-2_all.deb | Bin global/overlay/usr/local/sbin/cosmos_vm | 124 ++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 120000 apt rename {apt => global/overlay/etc/cosmos/apt}/bootstrap-cosmos.sh (100%) rename {apt => global/overlay/etc/cosmos/apt}/cosmos_1.2-2_all.deb (100%) create mode 100755 global/overlay/usr/local/sbin/cosmos_vm diff --git a/apt b/apt new file mode 120000 index 0000000..fb02c87 --- /dev/null +++ b/apt @@ -0,0 +1 @@ +global/overlay/etc/cosmos/apt \ No newline at end of file diff --git a/apt/bootstrap-cosmos.sh b/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh similarity index 100% rename from apt/bootstrap-cosmos.sh rename to global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh diff --git a/apt/cosmos_1.2-2_all.deb b/global/overlay/etc/cosmos/apt/cosmos_1.2-2_all.deb similarity index 100% rename from apt/cosmos_1.2-2_all.deb rename to global/overlay/etc/cosmos/apt/cosmos_1.2-2_all.deb diff --git a/global/overlay/usr/local/sbin/cosmos_vm b/global/overlay/usr/local/sbin/cosmos_vm new file mode 100755 index 0000000..bf27576 --- /dev/null +++ b/global/overlay/usr/local/sbin/cosmos_vm @@ -0,0 +1,124 @@ +#!/bin/bash + +set -- $(getopt h?H:D?s:B:M:C:R:i:g:n:I:G:N: "$@") + +src_image="" +size="1G" +dhcp="no" +hostname="default" +bridge="br0" +cpus="1" +mem="1024" +repo="git://code.mnt.se/mnt-cosmos.git" +tag="eduid-cosmos" +ip="" +gateway="" +netmask="" +resolver="" +ip6="" +gateway6="" +netmask6="64" + +while [ $# -gt 0 ]; do + case "$1" in + (-h) echo "Usage: $0 [-h] [-H hostname] [-M ] [-C <#cpus>] [-B ] [-D (dhcp)] [-i/-I ] [-n/-N ] [-g/-G ] [-R ] [-s ]"; exit 0;; + (-H) hostname="$2"; shift;; + (-s) src_image="$2"; shift;; + (-D) dhcp="yes" ;; + (-S) size="$2"; shift;; + (-B) bridge="$2"; shift;; + (-M) mem="$2"; shift;; + (-C) cpus="$2"; shift;; + (-R) resolver="$2"; shift;; + (-i) ip="$2"; shift;; + (-g) gateway="$2"; shift;; + (-n) netmask="$2"; shift;; + (-I) ip6="$2"; shift;; + (-G) gateway6="$2"; shift;; + (-N) netmask6="$2"; shift;; + (--) shift; break;; + (-*) echo "Unknown option $1\nUsage: $0 [-h] [-H hostname] [-M ] [-C <#cpus>] [-B ] [-D (dhcp)] [-i/-I ] [-n/-N ] [-g/-G ] [-R ] [-s ]"; exit 1;; + (*) break;; + esac + shift +done + +id=$(uuidgen) + +seed=${id}_seed.img +disk=${id}.img + +rm -f ${seed} +truncate --size 2M ${seed} +mkfs.vfat -n cidata ${seed} 2>/dev/null + +user_data=$(mktemp) +cat > ${user_data} < ${meta_data} <> ${meta_data} <> ${meta_data} <> ${meta_data} </dev/null +mcopy -i ${seed} ${meta_data} ::meta-data 2>/dev/null +mcopy -i ${seed} /etc/cosmos/apt/bootstrap-cosmos.sh /etc/cosmos/apt/cosmos_1.2-2_all.deb :: +mv ${seed} /var/lib/libvirt/images/ +virsh pool-refresh default + +virsh vol-clone --pool default ${src_image} ${disk} + +virt-install -r ${mem} -n ${hostname} --vcpus=${cpus} --autostart --memballoon virtio --network bridge=${bridge} --boot hd --disk vol=default/${disk},format=qcow2,bus=virtio --disk vol=default/${seed},bus=virtio + +rm -f ${user_data} +rm -f ${meta_data}