diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-02-10 19:43:18 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-02-10 19:43:18 -0500 |
commit | 0435087c48264fda6bd9c3e01998849b2f70f685 (patch) | |
tree | 5b3eb5f8f9e345d7fa6f47620624631429199676 /cloud-init.py | |
parent | fbe3e44bf2bfab041a1d023b9630ff6227d8a7b2 (diff) | |
download | vyos-cloud-init-0435087c48264fda6bd9c3e01998849b2f70f685.tar.gz vyos-cloud-init-0435087c48264fda6bd9c3e01998849b2f70f685.zip |
only set hostname once per instance. (LP: #514492)
LP: #514492
Diffstat (limited to 'cloud-init.py')
-rwxr-xr-x | cloud-init.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/cloud-init.py b/cloud-init.py index b48d4672..501ed4b4 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -35,10 +35,6 @@ def main(): sys.stderr.write("Failed to get instance data") sys.exit(1) - hostname = cloud.get_hostname() - subprocess.Popen(['hostname', hostname]).communicate() - #print "user data is:" + cloud.get_user_data() - # store the metadata cloud.update_cache() @@ -50,6 +46,15 @@ def main(): warn("consuming user data failed!\n") raise + try: + hostname = cloud.get_hostname() + cloud.sem_and_run("set_hostname", "once-per-instance", + set_hostname, [ hostname ], False) + except: + warn("failed to set hostname\n") + + #print "user data is:" + cloud.get_user_data() + # set the defaults (like what ec2-set-defaults.py did) try: cloud.sem_and_run("set_defaults", "once-per-instance", @@ -72,5 +77,11 @@ def apply_locale(locale): util.render_to_file('default-locale', '/etc/default/locale', \ { 'locale' : locale }) +def set_hostname(hostname): + subprocess.Popen(['hostname', hostname]).communicate() + f=open("/etc/hostname","wb") + f.write("%s\n" % hostname) + f.close() + if __name__ == '__main__': main() |