Merge pull request #286 from bcoca/hostname_24_compatible
made hostname work with python 2.4
This commit is contained in:
commit
04680ce228
1 changed files with 18 additions and 14 deletions
|
@ -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…
Reference in a new issue