From 4f300ca63268f73a63e01f5528ecdc5e6f46d67e Mon Sep 17 00:00:00 2001 From: Leif Johansson Date: Wed, 22 Oct 2014 14:28:05 +0200 Subject: simple kvm builder using cloud images --- apt | 1 + apt/bootstrap-cosmos.sh | 42 ------- apt/cosmos_1.2-2_all.deb | Bin 11724 -> 0 bytes global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh | 42 +++++++ global/overlay/etc/cosmos/apt/cosmos_1.2-2_all.deb | Bin 0 -> 11724 bytes global/overlay/usr/local/sbin/cosmos_vm | 124 +++++++++++++++++++++ 6 files changed, 167 insertions(+), 42 deletions(-) create mode 120000 apt delete mode 100755 apt/bootstrap-cosmos.sh delete mode 100644 apt/cosmos_1.2-2_all.deb create mode 100755 global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh create mode 100644 global/overlay/etc/cosmos/apt/cosmos_1.2-2_all.deb 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/apt/bootstrap-cosmos.sh deleted file mode 100755 index 28cbde0..0000000 --- a/apt/bootstrap-cosmos.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - -set -e - -cmd_hostname="$1" -if test -z "$cmd_hostname"; then - echo "Usage: $0 HOSTNAME REPO TAGPATTERN" - exit 1 -fi - -cmd_repo="$2" -if test -z "$cmd_repo"; then - echo "Usage $0 HOSTNAME REPO TAGPATTERN" - exit 2 -fi - -cmd_tags="$3" -if test -z "$cmd_tags"; then - echo "Usage $0 HOSTNAME REPO TAGPATTERN" - exit 3 -fi - -set -x - -apt-get -y install rsync git-core wget -dpkg -i cosmos_1.2-2_all.deb - -if ! test -d /var/cache/cosmos/repo; then - cosmos clone "$cmd_repo" -fi - -hostname $cmd_hostname - -perl -pi -e "s,#COSMOS_REPO_MODELS=.*,COSMOS_REPO_MODELS=\"\\\$COSMOS_REPO/global/:\\\$COSMOS_REPO/$cmd_hostname/\"," /etc/cosmos/cosmos.conf -perl -pi -e "s,#COSMOS_UPDATE_VERIFY_GIT_TAG_PATTERN=.*,COSMOS_UPDATE_VERIFY_GIT_TAG_PATTERN=\"${cmd_tags}*\"," /etc/cosmos/cosmos.conf - -env COSMOS_BASE=/var/cache/cosmos COSMOS_KEYS=/var/cache/cosmos/repo/global/overlay/etc/cosmos/keys /var/cache/cosmos/repo/global/post-tasks.d/015cosmos-trust - -(date; nohup cosmos -v update && nohup cosmos -v apply; date) 2>&1 | tee /var/log/cosmos.log - - -exit 0 diff --git a/apt/cosmos_1.2-2_all.deb b/apt/cosmos_1.2-2_all.deb deleted file mode 100644 index 9fe4434..0000000 Binary files a/apt/cosmos_1.2-2_all.deb and /dev/null differ diff --git a/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh b/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh new file mode 100755 index 0000000..28cbde0 --- /dev/null +++ b/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +set -e + +cmd_hostname="$1" +if test -z "$cmd_hostname"; then + echo "Usage: $0 HOSTNAME REPO TAGPATTERN" + exit 1 +fi + +cmd_repo="$2" +if test -z "$cmd_repo"; then + echo "Usage $0 HOSTNAME REPO TAGPATTERN" + exit 2 +fi + +cmd_tags="$3" +if test -z "$cmd_tags"; then + echo "Usage $0 HOSTNAME REPO TAGPATTERN" + exit 3 +fi + +set -x + +apt-get -y install rsync git-core wget +dpkg -i cosmos_1.2-2_all.deb + +if ! test -d /var/cache/cosmos/repo; then + cosmos clone "$cmd_repo" +fi + +hostname $cmd_hostname + +perl -pi -e "s,#COSMOS_REPO_MODELS=.*,COSMOS_REPO_MODELS=\"\\\$COSMOS_REPO/global/:\\\$COSMOS_REPO/$cmd_hostname/\"," /etc/cosmos/cosmos.conf +perl -pi -e "s,#COSMOS_UPDATE_VERIFY_GIT_TAG_PATTERN=.*,COSMOS_UPDATE_VERIFY_GIT_TAG_PATTERN=\"${cmd_tags}*\"," /etc/cosmos/cosmos.conf + +env COSMOS_BASE=/var/cache/cosmos COSMOS_KEYS=/var/cache/cosmos/repo/global/overlay/etc/cosmos/keys /var/cache/cosmos/repo/global/post-tasks.d/015cosmos-trust + +(date; nohup cosmos -v update && nohup cosmos -v apply; date) 2>&1 | tee /var/log/cosmos.log + + +exit 0 diff --git a/global/overlay/etc/cosmos/apt/cosmos_1.2-2_all.deb b/global/overlay/etc/cosmos/apt/cosmos_1.2-2_all.deb new file mode 100644 index 0000000..9fe4434 Binary files /dev/null and b/global/overlay/etc/cosmos/apt/cosmos_1.2-2_all.deb differ 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} -- cgit v1.1