-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New pillar/master_tops saltclass module #42349
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
''' | ||
SaltClass Pillar Module | ||
|
||
.. code-block:: yaml | ||
|
||
ext_pillar: | ||
- saltclass: | ||
- path: /srv/saltclass | ||
|
||
''' | ||
|
||
# import python libs | ||
from __future__ import absolute_import | ||
import salt.utils.saltclass as sc | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def __virtual__(): | ||
''' | ||
This module has no external dependencies | ||
''' | ||
return True | ||
|
||
|
||
def ext_pillar(minion_id, pillar, *args, **kwargs): | ||
''' | ||
Node definitions path will be retrieved from args - or set to default - | ||
then added to 'salt_data' dict that is passed to the 'get_pillars' function. | ||
'salt_data' dict is a convenient way to pass all the required datas to the function | ||
It contains: | ||
- __opts__ | ||
- __salt__ | ||
- __grains__ | ||
- __pillar__ | ||
- minion_id | ||
- path | ||
|
||
If successfull the function will return a pillar dict for minion_id | ||
''' | ||
# If path has not been set, make a default | ||
for i in args: | ||
if 'path' not in i: | ||
path = '/srv/saltclass' | ||
args[i]['path'] = path | ||
log.warning('path variable unset, using default: {0}'.format(path)) | ||
else: | ||
path = i['path'] | ||
|
||
# Create a dict that will contain our salt dicts to pass it to reclass | ||
salt_data = { | ||
'__opts__': __opts__, | ||
'__salt__': __salt__, | ||
'__grains__': __grains__, | ||
'__pillar__': pillar, | ||
'minion_id': minion_id, | ||
'path': path | ||
} | ||
|
||
return sc.get_pillars(minion_id, salt_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
''' | ||
SaltClass master_tops Module | ||
|
||
.. code-block:: yaml | ||
master_tops: | ||
saltclass: | ||
path: /srv/saltclass | ||
''' | ||
|
||
# import python libs | ||
from __future__ import absolute_import | ||
import logging | ||
|
||
import salt.utils.saltclass as sc | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def __virtual__(): | ||
''' | ||
Only run if properly configured | ||
''' | ||
if __opts__['master_tops'].get('saltclass'): | ||
return True | ||
return False | ||
|
||
|
||
def top(**kwargs): | ||
''' | ||
Node definitions path will be retrieved from __opts__ - or set to default - | ||
then added to 'salt_data' dict that is passed to the 'get_tops' function. | ||
'salt_data' dict is a convenient way to pass all the required datas to the function | ||
It contains: | ||
- __opts__ | ||
- empty __salt__ | ||
- __grains__ | ||
- empty __pillar__ | ||
- minion_id | ||
- path | ||
|
||
If successfull the function will return a top dict for minion_id | ||
''' | ||
# If path has not been set, make a default | ||
_opts = __opts__['master_tops']['saltclass'] | ||
if 'path' not in _opts: | ||
path = '/srv/saltclass' | ||
log.warning('path variable unset, using default: {0}'.format(path)) | ||
else: | ||
path = _opts['path'] | ||
|
||
# Create a dict that will contain our salt objects | ||
# to send to get_tops function | ||
if 'id' not in kwargs['opts']: | ||
log.warning('Minion id not found - Returning empty dict') | ||
return {} | ||
else: | ||
minion_id = kwargs['opts']['id'] | ||
|
||
salt_data = { | ||
'__opts__': kwargs['opts'], | ||
'__salt__': {}, | ||
'__grains__': kwargs['grains'], | ||
'__pillar__': {}, | ||
'minion_id': minion_id, | ||
'path': path | ||
} | ||
|
||
return sc.get_tops(minion_id, salt_data) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add some docs here, it does not need to be a lot, but just some info on expected data etc.