Bug#796882: hyperv-daemons: include debian specific versions of hv_get* scripts
control: tags -1 +patch
Hi,
On Tue, 25 Aug 2015 14:27:46 +0200 Christoph Martin <martin@uni-mainz.de> wrote:
> hv_kvp_daemon[941]: sh: 1: hv_get_dns_info: not found
> hv_kvp_daemon[941]: sh: 1: hv_get_dhcp_info: not found
> hv_kvp_daemon[941]: sh: 1: hv_get_dns_info: not found
> hv_kvp_daemon[941]: sh: 1: hv_get_dhcp_info: not found
>
> These scripts are missing from the package.
> Debian should include there own disto specific versions of this scripts.
>
> Examples are in the linux-tools source in the directory tools/hv/
patch taken from ubuntu package
--
Hideki Yamane <henrich@debian.or.jp>
diff -urN linux-tools-4.3~rc5/debian/hv_get_dhcp_info linux-tools-4.3~rc5.update/debian/hv_get_dhcp_info
--- linux-tools-4.3~rc5/debian/hv_get_dhcp_info 1970-01-01 09:00:00.000000000 +0900
+++ linux-tools-4.3~rc5.update/debian/hv_get_dhcp_info 2015-11-21 14:05:21.025229857 +0900
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# This example script retrieves the DHCP state of a given interface.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DHCP setting for the specific interface.
+#
+# Input: Name of the interface
+#
+# Output: The script prints the string "Enabled" to stdout to indicate
+# that DHCP is enabled on the interface. If DHCP is not enabled,
+# the script prints the string "Disabled" to stdout.
+
+IF_FILE="/etc/network/interfaces"
+NMCMD="nmcli"
+
+function checknetworkmanager {
+# Assumes if $NMCMD exists, inteface exists and interface is not
+# in $IF_FILE then dhcp is being used by NM
+ if $NMCMD dev status 2>/dev/null | grep -q $1; then
+ echo "Enabled"
+ else
+ echo "Disabled"
+ fi
+}
+
+if [ -z $1 ]; then
+ echo "Disabled"; exit
+fi
+
+
+if grep -v -e "^#" $IF_FILE 2>/dev/null | grep -q $1 ; then
+ #interface exists so
+ if grep -q -e $1\.\*dhcp $IF_FILE; then
+ echo "Enabled"
+ else
+ echo "Disabled"
+ fi
+else
+ checknetworkmanager $1
+fi
diff -urN linux-tools-4.3~rc5/debian/hv_get_dns_info linux-tools-4.3~rc5.update/debian/hv_get_dns_info
--- linux-tools-4.3~rc5/debian/hv_get_dns_info 1970-01-01 09:00:00.000000000 +0900
+++ linux-tools-4.3~rc5.update/debian/hv_get_dns_info 2015-11-21 14:05:21.025229857 +0900
@@ -0,0 +1,2 @@
+#!/bin/sh
+awk '/^nameserver/ { print $2 }' /etc/resolv.conf 2>/dev/null
diff -urN linux-tools-4.3~rc5/debian/hv_set_ifconfig linux-tools-4.3~rc5.update/debian/hv_set_ifconfig
--- linux-tools-4.3~rc5/debian/hv_set_ifconfig 1970-01-01 09:00:00.000000000 +0900
+++ linux-tools-4.3~rc5.update/debian/hv_set_ifconfig 2015-11-21 14:05:21.025229857 +0900
@@ -0,0 +1,242 @@
+#! /usr/bin/env python
+
+# set interfaces in hv_kvp_daemon style
+import fileinput
+import sys
+import errno
+import os
+import shutil
+import tempfile
+import subprocess
+
+if_filename="/etc/network/interfaces"
+
+'''Get quiet'''
+sys.stdout = open(os.devnull, 'w')
+sys.stderr = open(os.devnull, 'w')
+
+try:
+ if_file=open(if_filename,"r+")
+except IOError as e:
+ exit(e.errno)
+else:
+ if_file.close()
+
+
+def kvp_dict(file):
+ return dict(line.strip().split("=") for line in file)
+
+
+#setting the hwaddress to something azure is not expecting is fatal networking
+
+if len(sys.argv) != 2 :
+ exit(errno.EINVAL)
+
+kvp=dict(line.strip().split("=") for line in fileinput.input())
+
+if not "HWADDR" in kvp :
+ exit(errno.EPROTO)
+
+if not "DEVICE" in kvp :
+ exit(1)
+
+output=[]
+basename=kvp["DEVICE"]
+
+if "DHCP" in kvp and kvp["DHCP"]=="yes" :
+ output += ["auto " + basename]
+ output += ["iface " + basename + " inet dhcp"]
+ output += [""]
+else:
+ ''' Matchup the interface specific lines '''
+
+ '''DNS entries will go with the first interface
+ and there can be a max of three'''
+ autolist=[]
+ dns=[]
+ if "DNS1" in kvp :
+ dns+=[kvp["DNS1"]]
+ if "DNS2" in kvp :
+ dns+=[kvp["DNS2"]]
+ if "DNS3" in kvp :
+ dns+=[kvp["DNS3"]]
+
+
+ '''
+ No real max for the number of interface + aliases ...
+ only required is the address (but mate everything up that comes in. '''
+
+ '''ipv4 first'''
+
+ v4names=[name for name in kvp.keys() if name.startswith("IPADDR")]
+ v4names.sort()
+
+ v6names=[name for name in kvp.keys() if name.startswith("IPV6ADDR")]
+ v6names.sort()
+
+ '''IPV6 requires a netmask'''
+ '''If an ipv6 exists, you'll want to turn off /proc/sys/net/ipv6/conf/all/autoconf with
+ up echo 0 > /proc/sys/net/ipv6/conf/all/autoconf'''
+
+ '''Counter needs to increment as soon as any interface is set.'''
+
+
+ if_count=0
+
+ for v4 in v4names:
+ ifname=basename
+ suffix=""
+ if if_count :
+ ifname+=":" + str(if_count)
+ suffix="_"+str(if_count)
+ if not ifname in autolist:
+ autolist += [ifname]
+ output += [ "iface " + ifname + " inet static"]
+ output += [ "\t" + "address " + kvp[v4]]
+ if "NETMASK"+suffix in kvp.keys():
+ output += ["\tnetmask " + kvp["NETMASK"+suffix]]
+ if "GATEWAY"+suffix in kvp.keys():
+ output += ["\tgateway " + kvp["GATEWAY"+suffix]]
+ if not if_count :
+ output += ["\tdns-nameservers " + ' '.join(dns)]
+ output += [""]
+ if_count+=1
+
+ if6_count=0
+ if6_used=0
+ for v6 in v6names:
+ ifname=basename
+ suffix=""
+ if if6_used :
+ ifname+=":" + str(if6_used)
+ if if6_count :
+ suffix="_" + str(if6_count)
+ if not ifname in autolist:
+ autolist += [ifname]
+ if "IPV6NETMASK"+suffix in kvp.keys():
+ output += [ "iface " + ifname + " inet6 static"]
+ output += [ "\taddress " + kvp[v6]]
+ output += [ "\tnetmask " + kvp["IPV6NETMASK"+suffix]]
+ if "IPV6_DEFAULTGW"+suffix in kvp.keys():
+ output += [ "\tgateway " + kvp["IPV6_DEFAULTGW"+suffix] ]
+ if not if_count :
+ output += ["\tdns-nameservers " + ' '.join(dns)]
+ output += [""]
+ if_count += 1
+ if6_used += 1
+ if6_count += 1
+
+ output = ["auto "+" ".join(autolist)] + output
+print "==================================="
+print output
+print "==================================="
+
+
+''' Time to clean out the existing interface file'''
+
+# Markers.
+start_mark = "# The following stanza(s) added by hv_set_ifconfig"
+end_mark = "#End of hv_set_ifconfig stanzas"
+
+f=open(if_filename,"r")
+flines=f.readlines()
+f.close()
+newfile=[]
+pitchstanza=0
+inastanza=0
+stanza=[]
+prev_line=None
+for line in flines:
+ if line.startswith("auto"):
+ if inastanza:
+ if not pitchstanza:
+ newfile.extend(stanza)
+ stanza=[]
+ inastanza=0
+ newline=""
+ autoline=line.strip().split(" ")
+ for word in autoline:
+ if (not word == basename) and (not word.startswith(basename+":")):
+ newline+=word + " "
+ newline = newline.strip()
+ if not newline == "auto":
+ newfile += [newline.strip()]
+ elif line.startswith(("iface","mapping","source")):
+ '''Read a stanza'''
+ '''A Stanza can also start with allow- ie allow-hotplug'''
+ if inastanza:
+ if not pitchstanza:
+ newfile.extend(stanza)
+ stanza=[]
+ inastanza=1
+ pitchstanza=0
+ autoline=line.strip().split(" ")
+ for word in autoline:
+ if (word == basename) or (word.startswith(basename+":")):
+ pitchstanza=1
+ if not pitchstanza:
+ stanza+=[line.strip()]
+ elif line.strip() in (start_mark, end_mark):
+ if inastanza:
+ if not pitchstanza:
+ newfile.extend(stanza)
+ stanza=[]
+ inastanza = 0
+ pitchstanza = 0
+ # Deduplicate markers.
+ if line != prev_line:
+ newfile += [line.strip()]
+ else:
+ if inastanza:
+ if not pitchstanza:
+ stanza+=[line.strip()]
+ else:
+ if not pitchstanza:
+ newfile += [line.strip()]
+ prev_line=line
+
+
+
+def emit(line):
+ print(line)
+ os.write(fd, line + "\n")
+
+# Insert the new output at the end and inside the existing markers if found.
+emitted = False
+fd, path = tempfile.mkstemp()
+for line in newfile:
+ if line == end_mark:
+ emit("\n".join(output))
+ emitted = True
+ emit(line)
+if not emitted:
+ emit(start_mark)
+ emit("\n".join(output))
+ emit(end_mark)
+os.close(fd)
+
+shutil.copy(path,if_filename)
+os.chmod(if_filename,0644)
+#print "TMPFILE is at: " + path
+#print "Copied file is at: " + if_filename
+
+
+try:
+ retcode = subprocess.call("ifdown "+basename , shell=True)
+ if retcode < 0:
+ print >>sys.stderr, "Child was terminated by signal", -retcode
+ else:
+ print >>sys.stderr, "Child returned", retcode
+except OSError as e:
+ print >>sys.stderr, "Execution failed:", e
+
+try:
+ retcode = subprocess.call("ifup "+basename , shell=True)
+ if retcode < 0:
+ print >>sys.stderr, "Child was terminated by signal", -retcode
+ else:
+ print >>sys.stderr, "Child returned", retcode
+except OSError as e:
+ print >>sys.stderr, "Execution failed:", e
+
+
diff -urN linux-tools-4.3~rc5/debian/templates/control.main.in linux-tools-4.3~rc5.update/debian/templates/control.main.in
--- linux-tools-4.3~rc5/debian/templates/control.main.in 2015-10-07 07:57:20.000000000 +0900
+++ linux-tools-4.3~rc5.update/debian/templates/control.main.in 2015-11-21 14:15:12.534363783 +0900
@@ -55,7 +55,7 @@
Package: hyperv-daemons
Architecture: i386 amd64 x32
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: ${shlibs:Depends}, ${misc:Depends}, gawk, python
Section: admin
Description: Support daemons for Linux running on Hyper-V
Suite of daemons for Linux guests running on Hyper-V, consisting of
Reply to: