From: Jokin Garay Date: Wed, 9 Nov 2016 12:05:53 +0000 (+0100) Subject: Bug 99: get_dhcp_lease.sh with support for LXD DHCP / fix in openvimd.cfg comment X-Git-Tag: v1.0.2~12^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=efc2bfb88058b5e5e40bfa874399b793e3778763;p=osm%2Fopenvim.git Bug 99: get_dhcp_lease.sh with support for LXD DHCP / fix in openvimd.cfg comment Change-Id: I48b9dd73c288a065e8df324526bde868bcabf231 Signed-off-by: Jokin Garay --- diff --git a/openvimd.cfg b/openvimd.cfg index ccc888f..016ea89 100644 --- a/openvimd.cfg +++ b/openvimd.cfg @@ -102,8 +102,9 @@ development_bridge: virbrMan10 #In case some of the previous 'bridge_ifaces' are connected to an EXTERNAL dhcp server, provide # the server parameters to allow openvim getting the allocated IP addresses of virtual machines # connected to the indicated 'bridge_ifaces' and or 'nets'. Openvim will connect to the dhcp server by ssh. -#DHCP server must contain a shell script "./get_dhcp_lease.sh" that accept a mac address as parameter -# and return empty or the allocated IP address. See an example at the end of the file ./openvim/dhcp_thread.py +#DHCP server must contain a shell script "get_dhcp_lease.sh" included in the path, that accepts a mac address as +# parameter and return empty or the allocated IP address. See an example at the end of the file +# ./openvim/dhcp_thread.py #COMMENT all lines in case you do not have a DHCP server in 'normal', 'development' or 'host only' modes. # For 'test' or 'OF only' modes you can leave then uncommented, because in these modes fake IP # address are generated instead of connecting with a real DHCP server. diff --git a/scripts/get_dhcp_lease.sh b/scripts/get_dhcp_lease.sh index 247a675..3262154 100755 --- a/scripts/get_dhcp_lease.sh +++ b/scripts/get_dhcp_lease.sh @@ -19,12 +19,21 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact with: nfvlabs@tid.es ## -awk ' -($1=="lease" && $3=="{"){ lease=$2; active="no"; found="no" } -($1=="binding" && $2=="state" && $3=="active;"){ active="yes" } -($1=="hardware" && $2=="ethernet" && $3==tolower("'$1';")){ found="yes" } -($1=="client-hostname"){ name=$2 } -($1=="}"){ if (active=="yes" && found=="yes"){ target_lease=lease; target_name=name}} -END{printf("%s", target_lease)} #print target_name -' /var/lib/dhcp/dhcpd.leases +if [ -e /var/lib/dhcp/dhcpd.leases ] +then + awk ' + ($1=="lease" && $3=="{"){ lease=$2; active="no"; found="no" } + ($1=="binding" && $2=="state" && $3=="active;"){ active="yes" } + ($1=="hardware" && $2=="ethernet" && $3==tolower("'$1';")){ found="yes" } + ($1=="client-hostname"){ name=$2 } + ($1=="}"){ if (active=="yes" && found=="yes"){ target_lease=lease; target_name=name}} + END{printf("%s", target_lease)} #print target_name + ' /var/lib/dhcp/dhcpd.leases +elif [ -e /var/lib/lxd-bridge/dnsmasq.lxdbr0.leases ] +then + awk ' + ($2=="'$1'"){ lease=$3; name=$4} + END{printf("%s", lease)} + ' /var/lib/lxd-bridge/dnsmasq.lxdbr0.leases +fi