mirror of
https://github.com/xcat2/confluent.git
synced 2025-02-04 13:02:25 +00:00
Add 'APPENDONCE:' section to syncfiles
This will APPEND if the target file doesn't already have the entire source contents in a contiguous location already. This makes it more safe to rerun without negative consequence.
This commit is contained in:
parent
f33ed9b4d9
commit
2e7b315f29
@ -192,11 +192,26 @@ class CredMerger:
|
||||
continue
|
||||
shadout.write(name + ':!::\n')
|
||||
|
||||
def appendonce(basepath, filename):
|
||||
with open(filename, 'rb') as filehdl:
|
||||
thedata = filehdl.read()
|
||||
targname = filename.replace(basepath, '')
|
||||
try:
|
||||
with open(targname, 'rb') as filehdl:
|
||||
targdata = filehdl.read()
|
||||
except IOError:
|
||||
targdata = b''
|
||||
if thedata in targdata:
|
||||
return
|
||||
with open(targname, 'ab') as targhdl:
|
||||
targhdl.write(thedata)
|
||||
|
||||
def synchronize():
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
appendoncedir = tempfile.mkdtemp()
|
||||
try:
|
||||
ac = apiclient.HTTPSClient()
|
||||
data = json.dumps({'merge': tmpdir})
|
||||
data = json.dumps({'merge': tmpdir, 'appendonce': appendoncedir})
|
||||
status, rsp = ac.grab_url_with_status('/confluent-api/self/remotesyncfiles', data)
|
||||
if status == 202:
|
||||
lastrsp = ''
|
||||
@ -224,6 +239,9 @@ def synchronize():
|
||||
cm.read_source(pendhosts)
|
||||
cm.read_target('/etc/hosts')
|
||||
cm.write_out('/etc/hosts')
|
||||
for dirn in os.walk(appendoncedir):
|
||||
for filen in dirn[2]:
|
||||
appendonce(appendoncedir, os.path.join(dirn[0], filen))
|
||||
if lastrsp:
|
||||
lastrsp = json.loads(lastrsp)
|
||||
opts = lastrsp.get('options', {})
|
||||
@ -247,6 +265,7 @@ def synchronize():
|
||||
os.chown(fname, uid, gid)
|
||||
finally:
|
||||
shutil.rmtree(tmpdir)
|
||||
shutil.rmtree(appendoncedir)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -37,6 +37,7 @@ class SyncList(object):
|
||||
slist = None
|
||||
self.replacemap = {}
|
||||
self.appendmap = {}
|
||||
self.appendoncemap = {}
|
||||
self.mergemap = {}
|
||||
self.optmap = {}
|
||||
with open(filename, 'r') as slfile:
|
||||
@ -59,6 +60,8 @@ class SyncList(object):
|
||||
if ent[-1] == ':':
|
||||
if ent == 'MERGE:':
|
||||
currmap = self.mergemap
|
||||
elif ent == 'APPENDONCE:':
|
||||
currmap = self.appendoncemap
|
||||
else:
|
||||
raise Exception(
|
||||
'Section "{}" is not currently supported in syncfiles'.format(ent[:-1]))
|
||||
@ -132,6 +135,12 @@ def sync_list_to_node(sl, node, suffixes):
|
||||
for ent in sl.mergemap:
|
||||
stage_ent(sl.mergemap, ent,
|
||||
os.path.join(targdir, suffixes['merge']), True)
|
||||
if 'appendonce' in suffixes:
|
||||
while suffixes['appendonce'] and suffixes['appendonce'][0] == '/':
|
||||
suffixes['appendonce'] = suffixes['appendonce'][1:]
|
||||
for ent in sl.appendoncemap:
|
||||
stage_ent(sl.appendoncemap, ent,
|
||||
os.path.join(targdir, suffixes['appendonce']), True)
|
||||
sshutil.prep_ssh_key('/etc/confluent/ssh/automation')
|
||||
output = subprocess.check_output(
|
||||
['rsync', '-rvLD', targdir + '/', 'root@{}:/'.format(node)], timeout=86400)
|
||||
|
Loading…
x
Reference in New Issue
Block a user