mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #12731 from ranl/salt_mine_module
mine: extracted mine.get runner to a different python module for reuse
This commit is contained in:
commit
de0b23b0a9
@ -2,17 +2,13 @@
|
||||
'''
|
||||
A runner to access data from the salt mine
|
||||
'''
|
||||
# Import python libs
|
||||
import os
|
||||
|
||||
# Import salt libs
|
||||
import salt.payload
|
||||
import salt.utils.minions
|
||||
import salt.utils
|
||||
import salt.output
|
||||
|
||||
|
||||
def get(tgt, fun, tgt_type='glob'):
|
||||
def get(tgt, fun, tgt_type='glob', output='yaml'):
|
||||
'''
|
||||
Gathers the data from the specified minions' mine, pass in the target,
|
||||
function to look up and the target type
|
||||
@ -21,24 +17,6 @@ def get(tgt, fun, tgt_type='glob'):
|
||||
|
||||
salt-run mine.get '*' network.interfaces
|
||||
'''
|
||||
ret = {}
|
||||
serial = salt.payload.Serial(__opts__)
|
||||
checker = salt.utils.minions.CkMinions(__opts__)
|
||||
minions = checker.check_minions(
|
||||
tgt,
|
||||
tgt_type)
|
||||
for minion in minions:
|
||||
mine = os.path.join(
|
||||
__opts__['cachedir'],
|
||||
'minions',
|
||||
minion,
|
||||
'mine.p')
|
||||
try:
|
||||
with salt.utils.fopen(mine, 'rb') as fp_:
|
||||
fdata = serial.load(fp_).get(fun)
|
||||
if fdata:
|
||||
ret[minion] = fdata
|
||||
except Exception:
|
||||
continue
|
||||
salt.output.display_output(ret, 'yaml', __opts__)
|
||||
ret = salt.utils.minions.mine_get(tgt, fun, tgt_type, __opts__)
|
||||
salt.output.display_output(ret, output, __opts__)
|
||||
return ret
|
||||
|
@ -689,3 +689,30 @@ class CkMinions(object):
|
||||
if self.match_check(regex, fun):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def mine_get(tgt, fun, tgt_type='glob', opts=None):
|
||||
'''
|
||||
Gathers the data from the specified minions' mine, pass in the target,
|
||||
function to look up and the target type
|
||||
'''
|
||||
ret = {}
|
||||
serial = salt.payload.Serial(opts)
|
||||
checker = salt.utils.minions.CkMinions(opts)
|
||||
minions = checker.check_minions(
|
||||
tgt,
|
||||
tgt_type)
|
||||
for minion in minions:
|
||||
mine = os.path.join(
|
||||
opts['cachedir'],
|
||||
'minions',
|
||||
minion,
|
||||
'mine.p')
|
||||
try:
|
||||
with salt.utils.fopen(mine, 'rb') as fp_:
|
||||
fdata = serial.load(fp_).get(fun)
|
||||
if fdata:
|
||||
ret[minion] = fdata
|
||||
except Exception:
|
||||
continue
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user