From d1e9a7c0807fa2291b82544db230a9b2ef5a4b7e Mon Sep 17 00:00:00 2001 From: Damian Myerscough Date: Thu, 23 Oct 2014 19:33:51 -0700 Subject: [PATCH] Initial drac management --- salt/modules/drac.py | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 salt/modules/drac.py diff --git a/salt/modules/drac.py b/salt/modules/drac.py new file mode 100644 index 0000000000..ccb546df1a --- /dev/null +++ b/salt/modules/drac.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +''' +Manage Dell DRAC +''' + +import salt.utils + +import logging + +log = logging.getLogger(__name__) + + +def __virtual__(): + ''' + + ''' + if salt.utils.which('racadm'): + return True + + return False + + +def __parse_drac(output): + ''' + Parse Dell DRAC output + ''' + drac = {} + section = '' + + for i in output.splitlines(): + if len(i.rstrip()) > 0 and '=' in i: + if section in drac: + drac[section].update(dict( + [[prop.strip() for prop in i.split('=')]] + )) + else: + section = i.strip()[:-1] + if section not in drac and section: + drac[section] = {} + + return drac + + +def getsysinfo(): + ''' + Return System information + + CLI Example: + + .. code-block:: bash + + salt dell drac.getsysinfo + ''' + drac = {} + section = '' + + cmd = __salt__['cmd.run_all']('racadm getsysinfo') + + if cmd['retcode'] != 0: + log.warn('racadm return an exit code \'{0}\'.'.format(cmd['retcode'])) + + return __parse_drac(cmd['stdout']) + + +def getniccfg(): + ''' + Return Network Configuration + + CLI Example: + + .. code-block:: bash + + salt salt drac.getniccfg + ''' + + cmd = __salt__['cmd.run_all']('racadm getniccfg') + + if cmd['retcode'] != 0: + log.warn('racadm return an exit code \'{0}\'.'.format(cmd['retcode'])) + + return __parse_drac(cmd['stdout'])