Commit ae07c9e8 authored by Maria Matejka's avatar Maria Matejka

Random control IPs and MACs

parent 7640a123
img/*
iso/*
run/*
nfs/*
bin/socat
#!/usr/bin/env python
import pypureomapi
import sys
keyname = "dhcp_key"
#secret = "6Qsf2UG4cvSli+Fup3bHI/4lCGO4i3SO6hl6WWBr042vUHktQ/1KiQwI 3MQrNrGs7c7EMDr/fho2Fzr3y1EP/Q=="
secret = "3MQrNrGs7c7EMDr/fho2Fzr3y1EP/Q=="
server = "127.0.0.1"
port = 7911
try:
oma = pypureomapi.Omapi(server, port, keyname, secret, debug=False)
except pypureomapi.OmapiError, err:
print "OMAPI error: %s" % (err,)
sys.exit(1)
if sys.argv[1] == "add":
oma.add_host(sys.argv[3], sys.argv[2])
elif sys.argv[1] == "del":
oma.del_host(sys.argv[2])
else:
print("Usage: omapi (add MAC IP|del MAC)")
......@@ -18,3 +18,5 @@ iptables -A FORWARD -i eth0 -o $VIRTCTRL -m state --state RELATED,ESTABLISHED -j
iptables -A FORWARD -i eth0 -o $VIRTCTRL -j ACCEPT
iptables -A FORWARD -i $VIRTCTRL -o eth0 -j ACCEPT
iptables -A FORWARD -o eth0 -j REJECT
dhcpd -cf $ROOT/etc/dhcpd.conf -pf $ROOT/run/dhcpd.pid $VIRTCTRL
#!/bin/bash
. $(dirname $(readlink -f $0))/virt-lib
egrep -i '^\s*Network' <$VIRTUALS | sed -r 's/.*[Nn][Ee][Tt][Ww][Oo][Rr][Kk]\s+(.*)\s+(.*)\s+(.*)$/host \1 { hardware ethernet \2; fixed-address \3; }/' >$ROOT/etc/dhcpd-hosts.conf
[ -f $ROOT/run/dhcpd.pid ] && kill $(cat $ROOT/run/dhcpd.pid)
dhcpd -cf $ROOT/etc/dhcpd.conf -pf $ROOT/run/dhcpd.pid $VIRTCTRL
......@@ -35,6 +35,8 @@ fi
#echo -e "IP4:\t\t$HOSTIP4"
#echo -e "TAP:\t\t$HOSTTAP"
$ROOT/bin/omapi add $HOSTMAC $HOSTIP4
qemu-system-$HOSTARCH -enable-kvm -m $HOSTMEMORY ${HOSTCDROM:+-cdrom $ROOT/iso/$HOSTCDROM -boot d} -hda $ROOT/img/$HOSTIMAGE $HOSTCOW -display none ${HOSTVNCID:+-vnc 10.0.0.11:$HOSTVNCID} -netdev tap,id=ctl,ifname=$HOSTTAP,script=no -device e1000,netdev=ctl,mac=$HOSTMAC -pidfile $ROOT/run/$NAME.pid -monitor unix:$ROOT/run/$NAME.sock,server,nowait -daemonize "$@"
#-runas $VIRTUSER
......
......@@ -7,7 +7,13 @@ seen[dhcpd]=1
for S in `find $ROOT/run -name '*.sock'`; do
S=$(basename $S)
gethost ${S%%.sock}
echo "${S%%.sock} running, IPv4 $HOSTIP4, monitor $S"
if ping -nc1 $HOSTIP4 >/dev/null; then
PING="(ping ok)"
else
PING="(ping FAIL)"
fi
echo "${S%%.sock} running, IPv4 $HOSTIP4 $PING, monitor $S"
seen["${S%%.sock}"]=1
done
......
......@@ -13,7 +13,7 @@ function ok() {
echo
rm -f $ROOT/run/$NAME.sock $ROOT/run/$NAME.pid
if gethost $NAME; then
vsctl del-port $VIRTBR $HOSTTAP
$ROOT/bin/omapi del $HOSTMAC
else
echo "Warning: Config not found for this host"
fi
......
......@@ -84,7 +84,6 @@ function gethost() {
function hostdefaults() {
if [ -z "$HOSTIMAGE" ]; then echo "Error: Image not set"; return 1; fi
if [ -z "$HOSTNETWORK" ]; then echo "Error: No control network set"; return 1; fi
if [ -z "$HOSTARCH" ]; then HOSTARCH=x86_64; fi
if [ -z "$HOSTMEMORY" ]; then HOSTMEMORY=64M; fi
if [ "${HOSTCOW^^}" = "YES" ]; then HOSTCOW=-snapshot; else HOSTCOW= ; fi
......@@ -94,7 +93,15 @@ function hostdefaults() {
NICMAC=${NIC##* }
done
read HOSTTAP HOSTMAC HOSTIP4 <<<"$HOSTNETWORK"
if [ -z "$HOSTNETWORK" ]; then
local SHA=$(sha1sum <<<"$HOSTNAME" | head -c 12)
HOSTTAP=vc-$SHA
HOSTMAC=02:$(sed -r 's/^.*(..)(..)(..)(..)(..)$/\1:\2:\3:\4:\5/'<<<"$SHA")
HOSTIP4=192.168.$((193+((0x$SHA / 254) % 63))).$((0x$SHA % 254))
else
read HOSTTAP HOSTMAC HOSTIP4 <<<"$HOSTNETWORK"
fi
return 0
}
......
host tci-freebsd10 { hardware ethernet 00:11:22:00:05:01; fixed-address 192.168.197.1; }
host tci-debian8 { hardware ethernet 00:11:22:00:01:01; fixed-address 192.168.193.1; }
host tci-debian5 { hardware ethernet 00:11:22:00:01:02; fixed-address 192.168.193.2; }
host tci-fb10-1 { hardware ethernet 00:11:22:00:15:01; fixed-address 192.168.200.1; }
host tci-fb10-2 { hardware ethernet 00:11:22:00:15:02; fixed-address 192.168.200.2; }
host tcd8-1 { hardware ethernet 00:11:22:00:11:01; fixed-address 192.168.210.1; }
host tcd8-2 { hardware ethernet 00:11:22:00:11:11; fixed-address 192.168.210.2; }
host tcd8-3 { hardware ethernet 00:11:22:00:11:21; fixed-address 192.168.210.3; }
......@@ -14,4 +14,13 @@ subnet 192.168.192.0 netmask 255.255.192.0 {
default-lease-time 15555555;
}
include "/var/lib/virt/etc/dhcpd-hosts.conf";
key dhcp_key {
algorithm HMAC-MD5;
secret "3MQrNrGs7c7EMDr/fho2Fzr3y1EP/Q==";
}
#6Qsf2UG4cvSli+Fup3bHI/4lCGO4i3SO6hl6WWBr042vUHktQ/1KiQwI
omapi-port 7911;
omapi-key dhcp_key;
#include "/var/lib/virt/etc/dhcpd-hosts.conf";
Host freebsd10-install
Image freebsd10
Network tci-freebsd10 00:11:22:00:05:01 192.168.197.1
Memory 512M
# Cdrom freebsd10.iso
VNC 51
Type freebsd
Host freebsd10
Image freebsd10
Memory 512M
Type freebsd
Cow yes
Host debian8-install
Image debian8
Network tci-debian8 00:11:22:00:01:01 192.168.193.1
Memory 512M
# Cdrom debian8.iso
VNC 11
Type linux
Host debian5-install
Image debian5
Network tci-debian5 00:11:22:00:01:02 192.168.193.2
Memory 512M
# Cdrom debian5.iso
VNC 12
Type linux
Host fb10-1
Image freebsd10
Network tci-fb10-1 00:11:22:00:15:01 192.168.200.1
Memory 128M
VNC 101
Cow yes
Type freebsd
Host fb10-2
Image freebsd10
Network tci-fb10-2 00:11:22:00:15:02 192.168.200.2
Memory 2G
Cow yes
Type freebsd
Host d8-1
Host debian8
Image debian8
Network tcd8-1 00:11:22:00:11:01 192.168.210.1
Memory 128M
Memory 512M
Type linux
Cow yes
Host d8-2
Image debian8
Network tcd8-2 00:11:22:00:11:11 192.168.210.2
Memory 128M
Host debian5-install
Image debian5
Memory 512M
VNC 12
Type linux
Cow yes
Host d8-3
Image debian8
Network tcd8-3 00:11:22:00:11:21 192.168.210.3
Memory 128M
Host debian5
Image debian5
Memory 512M
Type linux
Cow yes
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment