diff options
author | Ben Howard <ben.howard@ubuntu.com> | 2014-01-15 13:02:30 -0700 |
---|---|---|
committer | usd-importer <ubuntu-server@lists.ubuntu.com> | 2014-01-16 00:38:26 +0000 |
commit | 8f9712a0a55531485f0958d67f19bb334c9ed118 (patch) | |
tree | f57f23e3daba5a96a1ad8a193daaef857c541681 | |
parent | 4615d30334acb3e253c809a486a8dee3c7c8064e (diff) | |
download | vyos-walinuxagent-8f9712a0a55531485f0958d67f19bb334c9ed118.tar.gz vyos-walinuxagent-8f9712a0a55531485f0958d67f19bb334c9ed118.zip |
Don't send hostname in dhcp
Gbp-Pq: idns_dhcp.patch.
-rw-r--r-- | waagent | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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.*?(<hostname>|gethostname[(,)])') == None : ReplaceFileContentsAtomic(filepath, "send host-name \"" + name + "\";\n" + "\n".join(filter(lambda a: not a.startswith("send host-name"), GetFileContents(filepath).split('\n')))) |