modify shim to recive tarball ext_mods

This commit is contained in:
Thomas S Hatch 2014-10-14 21:33:22 -06:00
parent 436210424f
commit fc890492e7

View File

@ -13,15 +13,16 @@ import tarfile
import shutil
import sys
import os
import json
import stat
THIN_ARCHIVE = 'salt-thin.tgz'
EXT_ARCHIVE = 'salt-ext_mods.tgz'
# FIXME - it would be ideal if these could be obtained directly from
# salt.exitcodes rather than duplicated.
EX_THIN_DEPLOY = 11
EX_THIN_CHECKSUM = 12
EX_MOD_DEPLOY = 13
class OBJ(object):
@ -80,19 +81,12 @@ def unpack_thin(thin_path):
os.unlink(thin_path)
def get_modules():
glob = ''
while True:
sys.stdout.write('_||ext_mods||_')
sys.stdout.flush()
glob += raw_input()
if glob.endswith('|_E|0|'):
break
ext_mods = json.loads(glob[:-6])
write_modules(ext_mods)
def need_ext():
sys.stdout.write('ext_mods')
sys.exit(EX_MOD_DEPLOY)
def write_modules(ext_mods):
def unpack_ext(ext_path):
modcache = os.path.join(
OPTIONS.saltdir,
'running_data',
@ -100,17 +94,13 @@ def write_modules(ext_mods):
'cache',
'salt',
'extmods')
for mtype in ext_mods:
dest_dir = os.path.join(modcache, mtype)
if not os.path.isdir(dest_dir):
os.makedirs(dest_dir)
chunks = ext_mods.get(mtype)
if not chunks:
continue
for name in chunks:
dest = os.path.join(dest_dir, name)
with open(dest, 'w+') as fp_:
fp_.write(chunks[name].decode('base64'))
tfile = tarfile.TarFile.gzopen(ext_path)
tfile.extractall(path=modcache)
tfile.close()
os.unlink(ext_path)
ver_path = os.path.join(modcache, 'ext_version')
ver_dst = os.path.join(OPTIONS.saltdir, 'ext_version')
shutil.move(ver_path, ver_dst)
def main(argv):
@ -148,8 +138,18 @@ def main(argv):
with open(os.path.join(OPTIONS.saltdir, 'minion'), 'w') as config:
config.write(OPTIONS.config + '\n')
if OPTIONS.get_modules:
get_modules()
if OPTIONS.ext_mods:
ext_path = os.path.join(OPTIONS.saltdir, EXT_ARCHIVE)
if os.path.exists(ext_path):
unpack_ext(ext_path)
else:
version_path = os.path.join(OPTIONS.saltdir, 'ext_version')
if not os.path.exists(version_path) or not os.path.isfile(version_path):
need_ext()
with open(version_path, 'r') as vpo:
cur_version = vpo.readline().strip()
if cur_version != OPTIONS.ext_mods:
need_ext()
#Fix parameter passing issue
if len(ARGS) == 1:
argv_prepared = ARGS[0].split()