OpenNebula/one — pull request #15 by asteven (2013-12-12 13:14:28+00:00)
Title: proof of concept implementation of EXTERNAL leases

Implements a new type of virtual network which delegates the allocation
of ip addresses to an external command.

The mac address is generated by opennebula and passed to the external command.
The external command can use this to get a suitable ip address.
It passes the IP address to opennebula by writing it to stdout.

If an IP is no longer used by opennebula it passes it to the external
command which can free it for other uses.

This is a quick and dirty proof of concept implementation.
Id would be nice to open a discussion:
- if this is usefull for other users?
- if it can be added to opennebula?
- how the existing infrastructure (e.g. Mad) could be used to implement this more nicely (e.g. instead of using popen)

I'm neither a C++ programmer nor do I know opennebula internals. I just hacked arround until it did what I wanted.
So if you like the idea, please help me to implement it properly ;-)

Usage looks something like this:
```
cat > /tmp/external.net << DONE
NAME = "external"
TYPE = EXTERNAL
EXTERNAL_COMMAND = "/tmp/external_command"
BRIDGE = test
DONE

cat > /tmp/external_command << DONE
#!/bin/sh

log() {
echo "\$@" >> /tmp/external_command.log
}

case \$1 in
get)
mac="\$2"
log "get \$mac"
echo "127.0.0.42"
;;
release)
ip="\$2"
log "release \$ip"
;;
esac
DONE
chmod +x /tmp/external_command
onevnet create /tmp/external.net

$ vmid=$(onevm create --name "test vm" --memory 128 --cpu 1 --nic external | awk '{print $2}')
$ tail -n 1 /tmp/external_command.log
get 02:00:0a:1c:15:0e
$ onevm show $vmid
...
VM NICS
ID NETWORK VLAN BRIDGE IP MAC
0 external no test 127.0.0.42 02:00:0a:1c:15:0e
fe80::400:aff:fe1c:150e
...

$ onevm delete $vmid
$ tail -n 1 /tmp/external_command.log
release 127.0.0.42
```

Signed-off-by: Steven Armstrong