From b991a2708b75c781f6bb12db623840e245d0fe99 Mon Sep 17 00:00:00 2001 From: saito-hideki Date: Sat, 25 Jul 2015 21:48:13 +0900 Subject: [PATCH] Add Solaris support in hostname module --- system/hostname.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/system/hostname.py b/system/hostname.py index d9193641eb2..2442f0ad3cc 100644 --- a/system/hostname.py +++ b/system/hostname.py @@ -363,6 +363,41 @@ class OpenBSDStrategy(GenericStrategy): # =========================================== +class SolarisStrategy(GenericStrategy): + """ + This is a Solaris11 or later Hostname manipulation strategy class - it + execute hostname command. + """ + + HOSTNAME_CMD = '/usr/bin/hostname' + + def set_current_hostname(self, name): + cmd_option = '-t' + cmd = [self.HOSTNAME_CMD, cmd_option, name] + rc, out, err = self.module.run_command(cmd) + if rc != 0: + self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % + (rc, out, err)) + + def get_permanent_hostname(self): + fmri = 'svc:/system/identity:node' + pattern = 'config/nodename' + cmd = '/usr/sbin/svccfg -s %s listprop -o value %s' % (fmri, pattern) + rc, out, err = self.module.run_command(cmd, use_unsafe_shell=True) + if rc != 0: + self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % + (rc, out, err)) + return out.strip() + + def set_permanent_hostname(self, name): + cmd = [self.HOSTNAME_CMD, name] + rc, out, err = self.module.run_command(cmd) + if rc != 0: + self.module.fail_json(msg="Command failed rc=%d, out=%s, err=%s" % + (rc, out, err)) + +# =========================================== + class FedoraHostname(Hostname): platform = 'Linux' distribution = 'Fedora' @@ -486,6 +521,11 @@ class OpenBSDHostname(Hostname): distribution = None strategy_class = OpenBSDStrategy +class SolarisHostname(Hostname): + platform = 'SunOS' + distribution = None + strategy_class = SolarisStrategy + # =========================================== def main():