Merge pull request #45251 from forksaber/salt-ssh-pydsl

Fix #23454 : make pydsl work with salt-ssh
This commit is contained in:
Nicole Thomas 2018-01-04 16:33:09 -05:00 committed by GitHub
commit e715eb603f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 2 deletions

View File

@ -72,6 +72,12 @@ class SSHHighState(salt.state.BaseHighState):
self.matcher = salt.minion.Matcher(self.opts)
self.tops = salt.loader.tops(self.opts)
self._pydsl_all_decls = {}
self._pydsl_render_stack = []
def push_active(self):
salt.state.HighState.stack.append(self)
def load_dynamic(self, matches):
'''
Stub out load_dynamic

View File

@ -87,6 +87,28 @@ def _merge_extra_filerefs(*args):
return ','.join(ret)
def _cleanup_slsmod_low_data(low_data):
'''
Set "slsmod" keys to None to make
low_data JSON serializable
'''
for i in low_data:
if 'slsmod' in i:
i['slsmod'] = None
def _cleanup_slsmod_high_data(high_data):
'''
Set "slsmod" keys to None to make
high_data JSON serializable
'''
for i in six.itervalues(high_data):
if 'stateconf' in i:
stateconf_data = i['stateconf'][1]
if 'slsmod' in stateconf_data:
stateconf_data['slsmod'] = None
def sls(mods, saltenv='base', test=None, exclude=None, **kwargs):
'''
Create the seed file for a state.sls run
@ -99,6 +121,7 @@ def sls(mods, saltenv='base', test=None, exclude=None, **kwargs):
__pillar__,
__salt__,
__context__['fileclient'])
st_.push_active()
if isinstance(mods, str):
mods = mods.split(',')
high_data, errors = st_.render_highstate({saltenv: mods})
@ -130,6 +153,7 @@ def sls(mods, saltenv='base', test=None, exclude=None, **kwargs):
)
)
# Create the tar containing the state pkg and relevant files.
_cleanup_slsmod_low_data(chunks)
trans_tar = salt.client.ssh.state.prep_trans_tar(
__opts__,
__context__['fileclient'],
@ -371,6 +395,7 @@ def high(data, **kwargs):
__pillar__,
__salt__,
__context__['fileclient'])
st_.push_active()
chunks = st_.state.compile_high_data(data)
file_refs = salt.client.ssh.state.lowstate_file_refs(
chunks,
@ -380,6 +405,7 @@ def high(data, **kwargs):
)
)
# Create the tar containing the state pkg and relevant files.
_cleanup_slsmod_low_data(chunks)
trans_tar = salt.client.ssh.state.prep_trans_tar(
__opts__,
__context__['fileclient'],
@ -600,6 +626,7 @@ def highstate(test=None, **kwargs):
__pillar__,
__salt__,
__context__['fileclient'])
st_.push_active()
chunks = st_.compile_low_chunks()
file_refs = salt.client.ssh.state.lowstate_file_refs(
chunks,
@ -614,6 +641,7 @@ def highstate(test=None, **kwargs):
__context__['retcode'] = 1
return chunks
# Create the tar containing the state pkg and relevant files.
_cleanup_slsmod_low_data(chunks)
trans_tar = salt.client.ssh.state.prep_trans_tar(
__opts__,
__context__['fileclient'],
@ -680,6 +708,7 @@ def top(topfn, test=None, **kwargs):
__salt__,
__context__['fileclient'])
st_.opts['state_top'] = os.path.join('salt://', topfn)
st_.push_active()
chunks = st_.compile_low_chunks()
file_refs = salt.client.ssh.state.lowstate_file_refs(
chunks,
@ -689,6 +718,7 @@ def top(topfn, test=None, **kwargs):
)
)
# Create the tar containing the state pkg and relevant files.
_cleanup_slsmod_low_data(chunks)
trans_tar = salt.client.ssh.state.prep_trans_tar(
__opts__,
__context__['fileclient'],
@ -746,7 +776,10 @@ def show_highstate():
__pillar__,
__salt__,
__context__['fileclient'])
return st_.compile_highstate()
st_.push_active()
chunks = st_.compile_highstate()
_cleanup_slsmod_high_data(chunks)
return chunks
def show_lowstate():
@ -765,7 +798,10 @@ def show_lowstate():
__pillar__,
__salt__,
__context__['fileclient'])
return st_.compile_low_chunks()
st_.push_active()
chunks = st_.compile_low_chunks()
_cleanup_slsmod_low_data(chunks)
return chunks
def sls_id(id_, mods, test=None, queue=False, **kwargs):
@ -884,6 +920,7 @@ def show_sls(mods, saltenv='base', test=None, **kwargs):
__pillar__,
__salt__,
__context__['fileclient'])
st_.push_active()
if isinstance(mods, string_types):
mods = mods.split(',')
high_data, errors = st_.render_highstate({saltenv: mods})
@ -898,6 +935,7 @@ def show_sls(mods, saltenv='base', test=None, **kwargs):
# Verify that the high data is structurally sound
if errors:
return errors
_cleanup_slsmod_high_data(high_data)
return high_data
@ -927,6 +965,7 @@ def show_low_sls(mods, saltenv='base', test=None, **kwargs):
__pillar__,
__salt__,
__context__['fileclient'])
st_.push_active()
if isinstance(mods, string_types):
mods = mods.split(',')
high_data, errors = st_.render_highstate({saltenv: mods})
@ -942,6 +981,7 @@ def show_low_sls(mods, saltenv='base', test=None, **kwargs):
if errors:
return errors
ret = st_.state.compile_high_data(high_data)
_cleanup_slsmod_low_data(ret)
return ret