Skip to content

Commit

Permalink
Adding Support For Onyx OS on Salt
Browse files Browse the repository at this point in the history
Signed-off-by: Anas Badaha <anasb@mellanox.com>
  • Loading branch information
Anas Badaha committed Oct 7, 2018
1 parent 0396331 commit 49bc71f
Show file tree
Hide file tree
Showing 4 changed files with 1,096 additions and 0 deletions.
42 changes: 42 additions & 0 deletions salt/grains/onyx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
'''
Grains for Onyx OS Switches Proxy minions
.. versionadded: Neon
For documentation on setting up the onyx proxy minion look in the documentation
for :mod:`salt.proxy.onyx<salt.proxy.onyx>`.
'''
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals

# Import Salt Libs
import logging
import salt.utils.platform
import salt.modules.onyx

log = logging.getLogger(__name__)

__proxyenabled__ = ['onyx']
__virtualname__ = 'onyx'


def __virtual__():
try:
if salt.utils.platform.is_proxy() and __opts__['proxy']['proxytype'] == 'onyx':
return __virtualname__
except KeyError:
pass

return False


def proxy_functions(proxy=None):
'''
Proxy Initialization
'''
if proxy is None:
return {}
if proxy['onyx.initialized']() is False:
return {}
return {'onyx': proxy['onyx.grains']()}
66 changes: 66 additions & 0 deletions salt/modules/onyx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
'''
Execution module for Onyx OS Switches Proxy minions
.. versionadded:: Neon
For documentation on setting up the onyx proxy minion look in the documentation
for :mod:`salt.proxy.onyx <salt.proxy.onyx>`.
'''
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals

# Import Salt libs
import salt.utils.platform

__proxyenabled__ = ['onyx']
__virtualname__ = 'onyx'


def __virtual__():
if salt.utils.platform.is_proxy():
return __virtualname__
return (False, 'The onyx execution module failed to load: '
'only available on proxy minions.')


def system_info():
'''
Return system information for grains of the Onyx OS proxy minion
.. code-block:: bash
salt '*' onyx.system_info
'''
return cmd('system_info')


def cmd(command, *args, **kwargs):
'''
run commands from __proxy__
:mod:`salt.proxy.onyx<salt.proxy.onyx>`
command
function from `salt.proxy.onyx` to run
args
positional args to pass to `command` function
kwargs
key word arguments to pass to `command` function
.. code-block:: bash
salt '*' onyx.cmd sendline 'show ver'
salt '*' onyx.cmd show_run
salt '*' onyx.cmd check_password username=admin
password='$5$lkjsdfoi$blahblahblah' encrypted=True
'''
proxy_prefix = __opts__['proxy']['proxytype']
proxy_cmd = '.'.join([proxy_prefix, command])
if proxy_cmd not in __proxy__:
return False
for k in list(kwargs):
if k.startswith('__pub_'):
kwargs.pop(k)
return __proxy__[proxy_cmd](*args, **kwargs)
Loading

0 comments on commit 49bc71f

Please sign in to comment.