made hostname work with python 2.4

reviewable/pr18780/r1
Brian Coca 10 years ago
parent 2970b339eb
commit e4b6968901

@ -298,31 +298,35 @@ class OpenRCStrategy(GenericStrategy):
def get_permanent_hostname(self): def get_permanent_hostname(self):
try: try:
with open(self.HOSTNAME_FILE, 'r') as f: f = open(self.HOSTNAME_FILE, 'r')
for line in f: for line in f:
line = line.strip() line = line.strip()
if line.startswith('hostname='): if line.startswith('hostname='):
return line[10:].strip('"') return line[10:].strip('"')
return None
except Exception, err: except Exception, err:
self.module.fail_json(msg="failed to read hostname: %s" % self.module.fail_json(msg="failed to read hostname: %s" % str(err))
str(err)) finally:
f.close()
return None
def set_permanent_hostname(self, name): def set_permanent_hostname(self, name):
try: try:
with open(self.HOSTNAME_FILE, 'r') as f: f = open(self.HOSTNAME_FILE, 'r')
lines = [x.strip() for x in f] lines = [x.strip() for x in f]
for i, line in enumerate(lines): for i, line in enumerate(lines):
if line.startswith('hostname='): if line.startswith('hostname='):
lines[i] = 'hostname="%s"' % name lines[i] = 'hostname="%s"' % name
break break
f.close()
with open(self.HOSTNAME_FILE, 'w') as f: f = open(self.HOSTNAME_FILE, 'w')
f.write('\n'.join(lines) + '\n') f.write('\n'.join(lines) + '\n')
except Exception, err: except Exception, err:
self.module.fail_json(msg="failed to update hostname: %s" % self.module.fail_json(msg="failed to update hostname: %s" % str(err))
str(err)) finally:
f.close()
# =========================================== # ===========================================

Loading…
Cancel
Save