From 1cac841c3365f31a6021a63407f2001cfc69c04d Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Mon, 10 Aug 2009 21:07:51 +0200 Subject: Stop mangling /etc/hosts. EC2 provides a functional DNS. Replace use of os.system with a call to subprocess.Popen. --- ec2-set-hostname.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'ec2-set-hostname.py') diff --git a/ec2-set-hostname.py b/ec2-set-hostname.py index 48aad89b..cc22f046 100755 --- a/ec2-set-hostname.py +++ b/ec2-set-hostname.py @@ -1,10 +1,11 @@ #!/usr/bin/python # -# Fetch login credentials for EC2 +# Set instance hostname to the localhostname defined by the EC2 meta-data +# service # Copyright (C) 2008-2009 Canonical Ltd. # -# Author: Chuck Short -# Soren Hansen +# Authors: Chuck Short +# Soren Hansen # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, as @@ -18,7 +19,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -from Cheetah.Template import Template +import subprocess import ec2init @@ -26,16 +27,7 @@ def main(): ec2 = ec2init.EC2Init() hostname = ec2.get_hostname() - - subprocess.Popen(['hostname', hostname']).communicate() - - # replace the ubuntu hostname in /etc/hosts - mp = {'hostname': hostname} - t = Template(file="/etc/ec2-init/templates/hosts.tmpl", searchList=[mp]) - - f = open("/etc/hosts", "w") - f.write(t.respond()) - f.close() + subprocess.Popen(['hostname', hostname]).communicate() if __name__ == '__main__': main() -- cgit v1.2.3