diff options
author | Leif Johansson <leifj@sunet.se> | 2015-02-24 11:19:10 +0100 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2015-02-24 11:19:10 +0100 |
commit | e2cc0bc80fa8cfab7fecb04677a45a4f51cb561e (patch) | |
tree | 09d540d53a1d9fa49fea52d4b1339d7a51846ac4 /global/overlay/usr | |
parent | c3415f304e2f11bdbf153bdb8e810e89311fc7a4 (diff) | |
parent | 7863ad617033064d6b5758d3d1f4bba32b9cc5dd (diff) |
merge multiversesunet-ops-2015-02-24-v01
Diffstat (limited to 'global/overlay/usr')
-rwxr-xr-x | global/overlay/usr/local/bin/run-cosmos | 2 | ||||
-rwxr-xr-x | global/overlay/usr/local/sbin/cosmos_vm | 124 |
2 files changed, 126 insertions, 0 deletions
diff --git a/global/overlay/usr/local/bin/run-cosmos b/global/overlay/usr/local/bin/run-cosmos index df104b8..a37d49f 100755 --- a/global/overlay/usr/local/bin/run-cosmos +++ b/global/overlay/usr/local/bin/run-cosmos @@ -18,3 +18,5 @@ else fi touch /var/run/last-cosmos-ok.stamp + +find /var/lib/puppet/reports/ -type f -mtime +10 | xargs rm -f 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 <memory>] [-C <#cpus>] [-B <bridge>] [-D (dhcp)] [-i/-I <ip4/6>] [-n/-N <mask4/6>] [-g/-G <gw4/6>] [-R <resolver(s)>] [-s <src image>]"; 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 <memory>] [-C <#cpus>] [-B <bridge>] [-D (dhcp)] [-i/-I <ip4/6>] [-n/-N <mask4/6>] [-g/-G <gw4/6>] [-R <resolver(s)>] [-s <src image>]"; 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} <<EOF +#cloud-config +password: ubuntu +chpasswd: { expire: False } +ssh_pwauth: True +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVvB4gdJ6EWRmx8xUSxrhoUNnWxEf8ZwAqhzC1+7XBY/hSd/cbEotLB9gxgqt0CLW56VU4FPLTw8snD8tgsyZN6KH1Da7UXno8oMk8tJdwLQM0Ggx3aWuztItkDfBc3Lfvq5T07YfphqJO7rcSGbS4QQdflXuOM9JLi6NStVao0ia4aE6Tj68pVVb3++XYvqvbU6NtEICvkTxEY93YpnRSfeAi64hsbaqSTN4kpeltzoSD1Rikz2aQFtFXE03ZC48HtGGhdMFA/Ade6KWBDaXxHGARVQ9/UccfhaR2XSjVxSZ8FBNOzNsH4k9cQIb2ndkEOXZXnjF5ZjdI4ZU0F+t7 leifj+00060AD478D6@sunet.se +runcmd: + - ["mkdir","/tmp/seed"] + - ["mount","/dev/vdb","/tmp/seed"] + - ["cp","/tmp/seed/bootstrap-cosmos.sh","/tmp/seed/cosmos_1.2-2_all.deb","/root"] + - ["cd","/root"] + - "cd /root && /root/bootstrap-cosmos.sh ${hostname} ${repo} ${tag}" + +EOF + +meta_data=$(mktemp) +cat > ${meta_data} <<EOF +#cloud-config +instance-id: iid-${id} +local-hostname: ${hostname} +EOF + +if [ "x${dhcp}" = "xyes" ]; then +cat >> ${meta_data} <<EOF +network-interfaces: | + auto eth0 + iface eth0 inet dhcp +EOF +else + if [ "x${ip}" != "x" ]; then + cat >> ${meta_data} <<EOF +network-interfaces: | + auto eth0 + iface eth0 inet static + address ${ip} + netmask ${netmask} + gateway ${gateway} + dns-nameservers ${resolver} + +EOF + fi + + if [ "x${ip6}" != "x" ]; then + cat >> ${meta_data} <<EOF +network-interfaces: | + auto eth0 + iface eth0 inet6 static + address ${ip6} + netmask ${netmask6} + gateway ${gateway6} + dns-nameservers ${resolver} + +EOF + fi +fi + +mcopy -i ${seed} ${user_data} ::user-data 2>/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} |