added support for sles 10 & 11

This commit is contained in:
Joao Carreira 2016-03-02 12:33:15 +00:00 committed by Matt Clay
parent 1fd5989b9d
commit 92d76e8828

View file

@ -185,6 +185,42 @@ class DebianStrategy(GenericStrategy):
self.module.fail_json(msg="failed to update hostname: %s" % self.module.fail_json(msg="failed to update hostname: %s" %
str(err)) 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() distribution_version = get_distribution_version()
if distribution_version and LooseVersion(distribution_version) >= LooseVersion("12"): if distribution_version and LooseVersion(distribution_version) >= LooseVersion("12"):
strategy_class = SystemdStrategy strategy_class = SystemdStrategy
elif distribution_version and LooseVersion("10") <= LooseVersion(distribution_version) <= LooseVersion("12"):
strategy_class = SLESStrategy
else: else:
strategy_class = UnimplementedStrategy strategy_class = UnimplementedStrategy