summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-10-06 18:19:48 +0200
committerroot2016-10-06 18:19:48 +0200
commit51c5f7cbd618fc2e67cb96fb0a31c3cae44090d1 (patch)
tree6b69dbcb89d083b1f7334b755cd771b52f997f58
parent[vmware] 12.5.0 (diff)
downloadtm-scripts-51c5f7cbd618fc2e67cb96fb0a31c3cae44090d1.tar.gz
tm-scripts-51c5f7cbd618fc2e67cb96fb0a31c3cae44090d1.tar.xz
tm-scripts-51c5f7cbd618fc2e67cb96fb0a31c3cae44090d1.zip
[run-virt/udhcpc] Fix passing on domain suffix and search domains to VMs via nat1
-rwxr-xr-xremote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx41
-rwxr-xr-xremote/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env18
-rw-r--r--remote/modules/run-virt/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf5
3 files changed, 40 insertions, 24 deletions
diff --git a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx
index dd8cd8ba..776f3f3b 100755
--- a/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx
+++ b/remote/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx
@@ -87,16 +87,29 @@ case "$1" in
# Update resolver configuration file
CONF=""
+ # Own domain suffix
if [ -n "$domain" ]; then
- printf -v CONF "${CONF}domain $domain\n"
+ :
elif [ -n "$dns_fqdn" ]; then
domain="${dns_fqdn#*.}"
- printf -v CONF "${CONF}domain $domain\n"
elif [ -n "$SLX_NET_DOMAIN" ]; then
domain="$SLX_NET_DOMAIN"
- printf -v CONF "${CONF}domain $domain\n"
fi
+ if [ -n "$domain" ]; then
+ printf -v CONF "${CONF}domain ${domain%% *}\n"
+ fi
+ # Add domain to list of search domains if not in there yet
+ if [ -n "$domain" ] && [ -n "$search" ]; then
+ FOUND=no
+ for sd in $search; do
+ [ "x$sd" = "x$domain" ] && FOUND=yes
+ done
+ [ "$FOUND" = "no" ] && search="$domain $search"
+ elif [ -n "$domain" ]; then
+ search="$domain"
+ fi
+ # Search domains
if [ -n "$search" ]; then
printf -v CONF "${CONF}search $search\n"
elif [ -n "$SLX_SEARCH_DOMAIN" ]; then
@@ -125,6 +138,15 @@ case "$1" in
if [ "$interface" == "br0" ]; then
# Update IP
sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config
+ # Write DOMAIN and SEARCH to /opt/openslx/config if empty
+ if [ -z "$SLX_NET_DOMAIN" ] && [ -n "$domain" ]; then
+ sed -i "/^SLX_NET_DOMAIN=/d" /opt/openslx/config
+ echo "SLX_NET_DOMAIN='$domain'" >> /opt/openslx/config
+ fi
+ if [ -z "$SLX_NET_SEARCH" ] && [ -n "$search" ]; then
+ sed -i "/^SLX_NET_SEARCH=/d" /opt/openslx/config
+ echo "SLX_NET_SEARCH='$search'" >> /opt/openslx/config
+ fi
# Only if network is not ready yet
if [ ! -e "/run/network/network-ready" ]; then
@@ -150,16 +172,6 @@ case "$1" in
fi
fi
- # if domain is given from dhcp, save it to openslx config for later use in VMs
- if [ -n "$domain" ]; then
- # check if SLX_NET_DOMAIN is in the config at all
- if grep '^SLX_NET_DOMAIN=' /opt/openslx/config 2>/dev/null; then
- sed -i "s/^\(SLX_NET_DOMAIN=\).*$/\1'$domain'/" /opt/openslx/config
- else
- # not set, add it
- echo "SLX_NET_DOMAIN='$domain'" >> /opt/openslx/config
- fi
- fi
# Update /etc/issue for proper spacing
/opt/openslx/scripts/openslx-create_issue
touch "/run/network/network-ready"
@@ -200,9 +212,6 @@ case "$1" in
# "default route exists" target
if [ -n "$router" ] && [ ! -e "/run/network/gateway-ready" ]; then
touch "/run/network/gateway-ready"
- # Write to openslx-config
- echo "# Config written by openslx-dhcp-script (3)" >> /opt/openslx/config
- echo "SLX_DNS='$dns'" >> /opt/openslx/config
systemctl start network-gateway.target &
fi
diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env b/remote/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env
index ba3122a1..506c4fff 100755
--- a/remote/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env
+++ b/remote/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env
@@ -168,17 +168,23 @@ echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding 2>/dev/null
### iptables -t nat -A POSTROUTING -o br0 -s 192.168.0.0/16 -j MASQUERADE
for wait in 1 1 2 2 3 end; do
- grep '^SLX_DNS' "/opt/openslx/config" > /dev/null && break
- [ "$wait" == "end" ] && echo "No DNS config found, using google dns" && break
- echo "Waiting for DNS config.."
+ [ -n "$SLX_DNS" ] && [ -n "$SLX_NET_SEARCH" ] && break
+ if [ "$wait" == "end" ]; then
+ echo "No DNS config found, using google dns"
+ break
+ fi
+ echo "Waiting for DNS & search-domain config.."
sleep "$wait"
+ . /opt/openslx/config
done
# read the DNS configuration and configure the udhcpd
-[ -z "${SLX_DNS}" ] && SLX_DNS="8.8.8.8"
-sed -i "s,DNSSERVER,${SLX_DNS},;s,DOMAIN,${SLX_NET_DOMAIN}," \
- "${DHCP_NAT_CONF}"
+[ -z "${SLX_DNS}" ] && SLX_DNS="8.8.8.8 8.8.4.4"
+[ -z "${SLX_NET_DOMAIN}" ] && SLX_NET_DOMAIN="virtual.site"
+[ -z "${SLX_NET_SEARCH}" ] && SLX_NET_SEARCH="virtual.site"
+sed -i "s#%DNSSERVER%#${SLX_DNS}#;s#%DOMAIN%#${SLX_NET_DOMAIN}#;s#%SEARCH%#${SLX_NET_SEARCH}#" "${DHCP_NAT_CONF}"
+# Make sure the primary vm running (we most likely never run more than one at a time anyways) always gets the same ip
echo "static_lease $(echo "$macaddrprefix:$macaddrsuffix" | sed 's/%VMID%/01/') 192.168.101.20" >> "${DHCP_NAT_CONF}"
mkdir -p /var/lib/udhcpd
diff --git a/remote/modules/run-virt/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf b/remote/modules/run-virt/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf
index bca1397c..95d8ebc0 100644
--- a/remote/modules/run-virt/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf
+++ b/remote/modules/run-virt/data/opt/openslx/vmchooser/config/udhcpd-nat1.conf
@@ -31,11 +31,12 @@ lease_file /var/lib/udhcpd/udhcpd-nat1.leases
# location of the pid file
pidfile /var/run/udhcpd-nat1.pid
-option dns DNSSERVER
+option dns %DNSSERVER%
option subnet 255.255.255.0
option router 192.168.101.1
option wins 192.168.101.10
-option domain DOMAIN virtual.site
+option domain %DOMAIN%
+option search %SEARCH%
option lprsrv 192.168.101.1
#option ntpsrv NTPSERVER