--- /dev/null
+#### All ###
+
+# bridge:
+cat > /etc/qemu/bridge.conf <<EOF
+allow virbr0 br0
+EOF
+
+# nat (will edit iptables rules):
+virsh net-create network-nat.xml
+
+
+#### Debian ####
+
+apt-get install libvirt-bin
+# apt-get install virt-manager virt-top
+
+# for bridge:
+cat >> /etc/network/interfaces <<EOF
+auto lo br0
+
+iface lo inet loopback
+iface eth0 inet manual
+iface eth1 inet manual
+
+iface br0 inet dhcp
+ bridge_fd 0
+ bridge_maxwait 0
+ bridge_ports eth0 eth1
+ #bridge_ports regex eth*
+ bridge_stp off
+EOF
+
+
+### RedHat ####
+
+yum install libvirt qemu-system-x86 libvirt-daemon-kvm
+# yum install virt-manager virt-top
+systemctl start libvirtd
+
+cat > /etc/sysconfig/network-scripts/ifcfg-br0 << EOF
+DEVICE=br0
+BOOTPROTO=dhcp
+NAME="Bridge"
+ONBOOT=yes
+TYPE=Bridge
+IPV4_FAILURE_FATAL=no
+ONBOOT=yes
+#DOMAIN=zcu.cz
+#PEERDNS=no
+#PEERROUTES=yes
+#DNS1=2001:718:1801:4010::1:15
+EOF
+
+cat > /etc/sysconfig/network-scripts/ifcfg-em1 << EOF
+TYPE=Ethernet
+#BOOTPROTO=dhcp
+DEFROUTE=yes
+NAME="Ethernet"
+ONBOOT=yes
+HWADDR=9C:B6:54:A5:59:1E
+BRIDGE=br0
+EOF
+
+==========
+
+# KVM
+parallel --jobs 6 "rsync -av . root@hador{}:~/KVM/" ::: `seq 20 24`
+parallel --jobs 6 "ssh -K root@hador{} 'cd ~/KVM; ./kvm.sh hador{}-1.sh'" ::: `seq 20 24`
+
+# puppet master
+for i in `seq 20 24`; do puppet cert clean hador${i}-1.ics.muni.cz; done
+vim /etc/puppet/hiera/cluster-bench.yaml
+
+# domU
+#+=myriad7 a rozkopírovat puppet.conf
+vim /opt/puppet3-omnibus/embedded/etc/puppet/puppet.conf
+for i in `seq 21 24`; do scp -p /opt/puppet3-omnibus/embedded/etc/puppet/puppet.conf hador${i}-1.ics.muni.cz:/opt/puppet3-omnibus/embedded/etc/puppet/; done
+#zmazat stará data
+for i in `seq 20 24`; do scp -p /home/valtri/HADOOP/INSTALACE+PROVOZ/clean2.sh root@hador${i}-1.ics.muni.cz:/tmp/; done
+parallel --jobs 6 "ssh root@hador{}-1.ics.muni.cz 'bash -xe /tmp/clean2.sh'" ::: `seq 20 24`
+#keytabs
+...
+#puppet
+parallel --jobs 6 "ssh root@hador{}-1.ics.muni.cz '/opt/puppet3-omnibus/bin/puppet agent --test'" ::: 20 21 22 23 24
--- /dev/null
+#!/bin/sh -e
+
+if [ -z $1 ]; then
+ echo "Usage:"
+ echo
+ echo "$0 cfg_hostname.sh [image | setup | xml | define | start]"
+ echo "$0 cfg_hostname.sh [undefine | delete]"
+ exit 1
+fi
+. ./$1 || exit 1
+
+IMAGE_POOL=/var/lib/libvirt/images
+
+IMAGE_FILE=${IMAGE_POOL}/${FACTER_hostname}.img
+IMAGE_SOURCE=imlach.ics.muni.cz:/images/debian7_x86_64_hadoop/
+SWAP_FILE=${IMAGE_POOL}/${FACTER_hostname}-swap.img
+
+if [ -z $FACTER_fqdn ]; then
+ echo "ERROR: no facter fqdn settings found"
+ exit 1
+fi
+if [ -z $FACTER_hostname ]; then
+ echo "ERROR: no facter hostname settings found"
+ exit 1
+fi
+
+
+image() {
+ if [ -f ${IMAGE_FILE} ]; then
+ echo "ERROR: image ${IMAGE_FILE} already exists"
+ exit 1
+ fi
+
+ if [ -f ${SWAP_FILE} ]; then
+ echo "ERROR: image ${SWAP_FILE} already exists"
+ exit 1
+ fi
+
+ dd if=/dev/zero of=${IMAGE_FILE} bs=1 count=0 seek=${SIZE_ROOTFS}
+ mkfs.xfs ${IMAGE_FILE}
+
+ if [ -n "${SIZE_SWAP}" -a "x${SIZE_SWAP}" != "x0" ]; then
+ dd if=/dev/zero of=${SWAP_FILE} bs=1 count=0 seek=${SIZE_SWAP}
+ mkswap ${SWAP_FILE}
+ fi
+
+ mkdir -p /mnt/target 2>/dev/null || :
+ mount -o loop ${IMAGE_FILE} /mnt/target || exit 1
+ cd /mnt/target || exit 1
+ rsync -a ${IMAGE_SOURCE} --numeric-ids /mnt/target
+ mkdir -p ${IMAGE_POOL}/${FACTER_hostname} 2>/dev/null || :
+ scp -p ${IMAGE_SOURCE}boot/vmlinuz* ${IMAGE_SOURCE}boot/initrd* ${IMAGE_POOL}/${FACTER_hostname}
+
+ cd /mnt
+ umount /mnt/target
+}
+
+
+setup() {
+ mkdir -p /mnt/target 2>/dev/null || :
+ mount -o loop ${IMAGE_FILE} /mnt/target || exit 1
+ cd /mnt/target || exit 1
+
+ #mount -o bind /proc proc
+ #mount -o bind /dev dev
+ #mount -o bind /sys sys
+ cp -v /etc/resolv.conf etc
+ #cp -vr /etc/apt etc
+ #chroot .
+ #apt-get update
+ #yes | aptitude install puppet xfsprogs git
+
+ echo "${FACTER_hostname}" > etc/hostname
+
+ cat << __EOF__ > etc/network/interfaces
+# This file describes the network interfaces available on your system
+# and how to activate them. For more information, see interfaces(5).
+
+# The loopback network interface
+auto lo
+iface lo inet loopback
+
+__EOF__
+ if [ -n "${FACTER_ipaddress}" ]; then
+ if [ "${FACTER_ipaddress}" = 'dhcp' ]; then
+ cat << __EOF__ >> etc/network/interfaces
+auto eth0
+iface eth0 inet dhcp
+
+__EOF__
+ else
+ cat << __EOF__ >> etc/network/interfaces
+auto eth0
+iface eth0 inet static
+ address $FACTER_ipaddress
+ netmask $FACTER_netmask
+ gateway $FACTER_gw
+
+__EOF__
+ fi
+ fi
+ if [ -n "${FACTER_ipaddress6}" ]; then
+ cat << __EOF__ >> etc/network/interfaces
+iface eth0 inet6 static
+ address ${FACTER_ipaddress6}
+ netmask ${FACTER_netmask6}
+ gateway ${FACTER_gw6}
+
+__EOF__
+ fi
+
+ if [ ! -d root/.ssh ]; then
+ mkdir -p root/.ssh
+ fi
+ if [ ! -f root/.ssh/authorized_keys -a -f /root/.ssh/authorized_keys ]; then
+ cp -v /root/.ssh/authorized_keys root/.ssh
+ fi
+
+ disk='b'
+ cat << __EOF__ > etc/fstab
+# /etc/fstab: static file system information.
+#
+# Use 'blkid' to print the universally unique identifier for a
+# device; this may be used with UUID= as a more robust way to name devices
+# that works even if disks are added and removed. See fstab(5).
+#
+# <file system> <mount point> <type> <options> <dump> <pass>
+/dev/vda / xfs defaults 0 1
+__EOF__
+ if [ -n "${SIZE_SWAP}" -a "x${SIZE_SWAP}" != "x0" ]; then
+ cat << __EOF__ >> etc/fstab
+/dev/vdb none swap sw 0 0
+__EOF__
+ disk='c'
+ fi
+ i=1
+ for d in ${DISKS}; do
+ mkdir -vp data/${i} || :
+ echo "/dev/vd${disk}1 /data/${i} xfs defaults,usrquota,noatime 0 2" >> etc/fstab
+ disk=`echo ${disk} | tr '0-9a-z' '1-9a-z_'`
+ i=$((i+1))
+ done
+
+ sed -e 's/^#T\(0\)/T\1/' -i etc/inittab
+
+ cat >> root/.k5login << __EOF__
+dexter@ADMIN.META
+mulac@ADMIN.META
+salvet@ADMIN.META
+valtri@ADMIN.META
+xparak@ADMIN.META
+__EOF__
+
+ #umount proc dev sys
+ cd /mnt
+ umount target
+}
+
+
+xml() {
+ disk='b'
+ if [ -n "${SIZE_SWAP}" -a "x${SIZE_SWAP}" != "x0" ]; then
+ XML_SWAP="
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source file='${SWAP_FILE}'/>
+ <target dev='sdj' bus='virtio'/>
+ </disk>
+
+"
+ disk='c'
+ fi
+ i=1
+ for d in ${DISKS}; do
+ XML_DISK="${XML_DISK}
+ <disk type='block' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source dev='${d}'/>
+ <target dev='vd${disk}' bus='virtio'/>
+ <alias name='virtio-data${i}'/>
+ </disk>"
+ i=$((i+1))
+ disk=`echo ${disk} | tr '0-9a-z' '1-9a-z_'`
+ done
+ if [ -n "${XENBR}" ]; then
+ XML_NET="
+ <interface type='bridge'>
+ <source bridge='${XENBR}'/>
+ <mac address='${FACTER_macaddress}'/>
+ <model type='virtio'/>
+ </interface>
+
+"
+ else
+ XML_NET="
+ <interface type='network'>
+ <source network='default'/>
+ <mac address='${FACTER_macaddress}'/>
+ <model type='virtio'/>
+ </interface>
+
+"
+ fi
+ cat << __EOF__ > /tmp/machine.xml
+<domain type='kvm'>
+ <name>${FACTER_hostname}</name>
+ <currentMemory unit='MiB'>${SIZE_MEM}</currentMemory>
+ <memory unit='MiB'>${SIZE_MEM}</memory>
+ <vcpu>${SIZE_CPU}</vcpu>
+ <os>
+ <kernel>`ls -1 ${IMAGE_POOL}/${FACTER_hostname}/vmlinuz-* | sort -r | head -n 1`</kernel>
+ <initrd>`ls -1 ${IMAGE_POOL}/${FACTER_hostname}/initramfs-* ${IMAGE_POOL}/${FACTER_hostname}/initrd* 2>/dev/null | grep -v plymouth | grep -v old-dkms | sort -r | head -n 1`</initrd>
+ <cmdline>root=/dev/vda ro rootflags=usrquota</cmdline>
+ <type arch='x86_64'>hvm</type>
+ </os>
+
+ <devices>
+
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source file='${IMAGE_FILE}'/>
+ <target dev='vda' bus='virtio'/>
+ </disk>${XML_SWAP}${XML_DISK}
+${XML_NET} <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
+ <listen type='address' address='127.0.0.1'/>
+ </graphics>
+
+ <serial type='pty'>
+ <target port='0'/>
+ </serial>
+
+ <console type='pty'>
+ <target type='serial' port='0'/>
+ </console>
+
+ </devices>
+</domain>
+__EOF__
+}
+
+shift
+actions="$@"
+
+if [ -z "${actions}" ]; then
+ actions='image setup xml define start'
+fi
+
+for action in ${actions}; do case ${action} in
+image) image ;;
+setup) setup ;;
+xml) xml ;;
+define)
+ virsh define /tmp/machine.xml
+ ;;
+start)
+ virsh start ${FACTER_hostname}
+ echo "INFO: ${FACTER_hostname} started"
+ ;;
+stop)
+ virsh destroy ${FACTER_hostname}
+ echo "INFO: ${FACTER_hostname} destroyed"
+ ;;
+undefine)
+ virsh undefine ${FACTER_hostname}
+ ;;
+delete)
+ virsh undefine ${FACTER_hostname} || :
+ rm -fvr ${IMAGE_POOL}/${FACTER_hostname}
+ rm -fv ${IMAGE_POOL}/${FACTER_hostname}.img
+ rm -fv ${IMAGE_POOL}/${FACTER_hostname}-swap.img
+ ;;
+esac
+done
+
+echo "INFO: $0 done"