From 8f9712a0a55531485f0958d67f19bb334c9ed118 Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Wed, 15 Jan 2014 13:02:30 -0700 Subject: Don't send hostname in dhcp Gbp-Pq: idns_dhcp.patch. --- waagent | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/waagent b/waagent index f0855d8..2584f01 100644 --- a/waagent +++ b/waagent @@ -211,6 +211,21 @@ def GetLineStartingWith(prefix, filepath): return line return None +def FindStringInFile(fname,matchs): + """ + Return match object if found in file. + """ + try: + ms=re.compile(matchs) + for l in (open(fname,'r')).readlines(): + m=re.search(ms,l) + if m: + return m + except: + raise + + return None + def Run(cmd,chk_err=True): retcode,out=RunGetOutput(cmd,chk_err) return retcode @@ -1435,7 +1450,7 @@ def UpdateAndPublishHostNameCommon(name): SetFileContents("/etc/hostname", name) for filepath in EtcDhcpClientConfFiles: - if os.path.isfile(filepath): + if os.path.isfile(filepath) and FindStringInFile(filepath,r'^[^#]*?send\s*host-name.*?(|gethostname[(,)])') == None : ReplaceFileContentsAtomic(filepath, "send host-name \"" + name + "\";\n" + "\n".join(filter(lambda a: not a.startswith("send host-name"), GetFileContents(filepath).split('\n')))) -- cgit v1.2.3