From 98cd5491809facf2eb1e58e82c3cb05d95992a1d Mon Sep 17 00:00:00 2001 From: Leif Johansson Date: Fri, 8 May 2015 15:37:07 +0200 Subject: cloud-init --- .../puppet/modules/sunet/manifests/cloudimage.pp | 32 +++++++ .../sunet/templates/cloudimage/mk_cloud_image.erb | 101 +++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 global/overlay/etc/puppet/modules/sunet/manifests/cloudimage.pp create mode 100644 global/overlay/etc/puppet/modules/sunet/templates/cloudimage/mk_cloud_image.erb (limited to 'global/overlay/etc/puppet/modules') 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} < ${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