diff options
author | Leif Johansson <leifj@sunet.se> | 2015-05-08 15:37:07 +0200 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2015-05-08 15:37:07 +0200 |
commit | 98cd5491809facf2eb1e58e82c3cb05d95992a1d (patch) | |
tree | 04aa5dffc2e94e5d364b7984cefa3e089ed0f852 /global | |
parent | 2f4e4812443b7ea9ecced5707ba4ab41844f2e7e (diff) |
cloud-initsunet-ops-2015-05-08-v02
Diffstat (limited to 'global')
3 files changed, 144 insertions, 0 deletions
diff --git a/global/overlay/etc/puppet/manifests/cosmos-site.pp b/global/overlay/etc/puppet/manifests/cosmos-site.pp index c17f704..3f487c9 100644 --- a/global/overlay/etc/puppet/manifests/cosmos-site.pp +++ b/global/overlay/etc/puppet/manifests/cosmos-site.pp @@ -277,6 +277,17 @@ node 'sto-tug-kvm-lab1.swamid.se' { cpus => '1', memory => '1024', } + + sunet::cloudimage { 'test.sunet.se': + dhcp => false, + repo => 'git://git.nordu.net/sunet-ops.git', + tag => 'sunet-ops', + cpus => '1', + memory => '1024', + ip => '130.242.125.88', + netmask => '255.255.255.192', + gateway => '130.242.125.65' + } } class sunet-dhcp-hosts { diff --git a/global/overlay/etc/puppet/modules/sunet/manifests/cloudimage.pp b/global/overlay/etc/puppet/modules/sunet/manifests/cloudimage.pp new file mode 100644 index 0000000..788fa41 --- /dev/null +++ b/global/overlay/etc/puppet/modules/sunet/manifests/cloudimage.pp @@ -0,0 +1,32 @@ +define sunet::cloudimage ( + $src_image = undef, + $dhcp = true, + $size = "1G", + $bridge = "br0", + $mem = "1024", + $cpus = "1", + $resolver = undef, + $ip = undef, + $netmask = undef, + $gateway = undef, + $ip6 = undef, + $netmask6 = "64", + $gateway6 = undef, + $tag = undef, + $repo = undef +) +{ + package {'mtools': require => latest } + package {'libvirt-bin': require => latest } + package {'uuid-runtime': require => latest } + + file { "/var/lib/libvirt/cloud-init": + ensure => directory + } + file { "/var/lib/libvirt/cloud-init/${name}.sh": + content => template("cloudimage/mk_cloud_image.erb") + } -> + exec { "/var/lib/libvirt/cloud-init/${name}.sh": + refreshonly => true + } +} diff --git a/global/overlay/etc/puppet/modules/sunet/templates/cloudimage/mk_cloud_image.erb b/global/overlay/etc/puppet/modules/sunet/templates/cloudimage/mk_cloud_image.erb new file mode 100644 index 0000000..16c8381 --- /dev/null +++ b/global/overlay/etc/puppet/modules/sunet/templates/cloudimage/mk_cloud_image.erb @@ -0,0 +1,101 @@ +#!/bin/bash + +src_image="<%= @src_image %>" +size="<%= @size %>" +dhcp="<%= @dhcp ? 'yes' : 'no' %>" +hostname="<%= @name %>" +bridge="<%= @bridge %>" +cpus="<%= @cpus %>" +mem="<%= @mem %>" +repo="<%= @repo %>" +tag="<%= @tag %>" +ip="<%= @ip %>" +gateway="<%= @gateway %>" +netmask="<%= @netmask %>" +resolver="<%= @resolver %>" +ip6="<%= @ip6 %>" +gateway6="<%= @gateway6 %>" +netmask6="<%= @netmask6 %>" + + +cd /var/lib/libvirt/cloudinit + +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} |