Enable fileserver backends for extension module pushes in salt-ssh

This commit is contained in:
Thomas S Hatch 2014-09-29 22:18:26 -06:00
parent 8a01d88815
commit 742f0a527e
3 changed files with 41 additions and 12 deletions

View File

@ -223,7 +223,7 @@ class SSH(object):
self.serial = salt.payload.Serial(opts)
self.returners = salt.loader.returners(self.opts, {})
self.fsclient = salt.fileclient.FSClient(self.opts)
self.mods = mod_data(self.opts)
self.mods = mod_data(self.fsclient)
def get_pubkey(self):
'''
@ -953,7 +953,7 @@ def salt_refs(data):
return ret
def mod_data(opts):
def mod_data(fsclient):
'''
Generate the module arguments for the shim data
'''
@ -966,21 +966,28 @@ def mod_data(opts):
'returners',
]
ret = {}
for env in opts['file_roots']:
for path in opts['file_roots'][env]:
for ref in sync_refs:
mod_str = ''
pl_dir = os.path.join(path, '_{0}'.format(ref))
if os.path.isdir(pl_dir):
for fn_ in os.listdir(pl_dir):
mod_path = os.path.join(pl_dir, fn_)
envs = fsclient.envs()
for env in envs:
files = fsclient.file_list(env)
for ref in sync_refs:
mod_str = ''
pref = '_{0}'.format(ref)
for fn_ in files:
if fn_.startswith(pref):
if fn_.endswith(('.py', '.so', '.pyx')):
mod_path = fsclient.cache_file(fn_, env)
if not os.path.isfile(mod_path):
continue
with open(mod_path) as fp_:
code_str = fp_.read().encode('base64')
mod_str += '{0}|{1},'.format(fn_, code_str)
mod_str = mod_str.rstrip(',')
ret[ref] = mod_str
if mod_str:
if ref in ret:
ret[ref] += mod_str
else:
ret[ref] = mod_str
for ref in ret:
ret[ref] = ret[ref].rstrip(',')
return ret

View File

@ -868,6 +868,15 @@ class LocalClient(Client):
'''
return self.opts
def envs(self):
'''
Return the available environments
'''
ret = []
for saltenv in self.opts['file_roots']:
ret.append(saltenv)
return ret
def ext_nodes(self):
'''
Originally returned information via the external_nodes subsystem.
@ -1174,6 +1183,17 @@ class RemoteClient(Client):
except SaltReqTimeoutError:
return ''
def envs(self):
'''
Return a list of available environments
'''
load = {'cmd': '_file_envs'}
try:
channel = self._get_channel()
return channel.send(load)
except SaltReqTimeoutError:
return ''
def master_opts(self):
'''
Return the master opts data

View File

@ -563,6 +563,8 @@ class FSChan(object):
cmd = load['cmd'].lstrip('_')
if cmd in self.cmd_stub:
return self.cmd_stub[cmd]
if cmd == 'file_envs':
cmd = 'envs'
if not hasattr(self.fs, cmd):
log.error('Malformed request, invalid cmd: {0}'.format(load))
return {}