|
|
|
@ -321,6 +321,44 @@ class OpenRCStrategy(GenericStrategy):
|
|
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
|
|
|
|
|
|
class OpenBSDStrategy(GenericStrategy):
|
|
|
|
|
"""
|
|
|
|
|
This is a OpenBSD family Hostname manipulation strategy class - it edits
|
|
|
|
|
the /etc/myname file.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
HOSTNAME_FILE = '/etc/myname'
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
|
|
|
|
|
|
class FedoraHostname(Hostname):
|
|
|
|
|
platform = 'Linux'
|
|
|
|
|
distribution = 'Fedora'
|
|
|
|
@ -430,6 +468,11 @@ class ALTLinuxHostname(Hostname):
|
|
|
|
|
distribution = 'Altlinux'
|
|
|
|
|
strategy_class = RedHatStrategy
|
|
|
|
|
|
|
|
|
|
class OpenBSDHostname(Hostname):
|
|
|
|
|
platform = 'OpenBSD'
|
|
|
|
|
distribution = None
|
|
|
|
|
strategy_class = OpenBSDStrategy
|
|
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|