Merge pull request #3168 from jdicarreira/hostname_sles10_11
Change hostname SLES 10 & 11
This commit is contained in:
commit
6a7dac5bdc
1 changed files with 38 additions and 0 deletions
|
@ -185,6 +185,42 @@ class DebianStrategy(GenericStrategy):
|
|||
self.module.fail_json(msg="failed to update hostname: %s" %
|
||||
str(err))
|
||||
|
||||
# ===========================================
|
||||
|
||||
class SLESStrategy(GenericStrategy):
|
||||
"""
|
||||
This is a SLES Hostname strategy class - it edits the
|
||||
/etc/HOSTNAME file.
|
||||
"""
|
||||
HOSTNAME_FILE = '/etc/HOSTNAME'
|
||||
|
||||
def get_permanent_hostname(self):
|
||||
if not os.path.isfile(self.HOSTNAME_FILE):
|
||||
try:
|
||||
open(self.HOSTNAME_FILE, "a").write("")
|
||||
except IOError, err:
|
||||
self.module.fail_json(msg="failed to write file: %s" %
|
||||
str(err))
|
||||
try:
|
||||
f = open(self.HOSTNAME_FILE)
|
||||
try:
|
||||
return f.read().strip()
|
||||
finally:
|
||||
f.close()
|
||||
except Exception, err:
|
||||
self.module.fail_json(msg="failed to read hostname: %s" %
|
||||
str(err))
|
||||
|
||||
def set_permanent_hostname(self, name):
|
||||
try:
|
||||
f = open(self.HOSTNAME_FILE, 'w+')
|
||||
try:
|
||||
f.write("%s\n" % name)
|
||||
finally:
|
||||
f.close()
|
||||
except Exception, err:
|
||||
self.module.fail_json(msg="failed to update hostname: %s" %
|
||||
str(err))
|
||||
|
||||
# ===========================================
|
||||
|
||||
|
@ -462,6 +498,8 @@ class SLESHostname(Hostname):
|
|||
distribution_version = get_distribution_version()
|
||||
if distribution_version and LooseVersion(distribution_version) >= LooseVersion("12"):
|
||||
strategy_class = SystemdStrategy
|
||||
elif distribution_version and LooseVersion("10") <= LooseVersion(distribution_version) <= LooseVersion("12"):
|
||||
strategy_class = SLESStrategy
|
||||
else:
|
||||
strategy_class = UnimplementedStrategy
|
||||
|
||||
|
|
Loading…
Reference in a new issue