From 98a6ffd9b67bcd06dc6b18a930ffbbf3e28aba4f Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 15 Oct 2021 16:16:11 -0400 Subject: [PATCH] Update more profiles with the APPENDONCE support --- .../profiles/default/scripts/syncfileclient | 21 ++++++++++++++++++- .../profiles/default/scripts/syncfileclient | 21 ++++++++++++++++++- .../profiles/hpc/scripts/syncfileclient | 21 ++++++++++++++++++- .../profiles/default/scripts/syncfileclient | 21 ++++++++++++++++++- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/syncfileclient b/confluent_osdeploy/el8-diskless/profiles/default/scripts/syncfileclient index 5638244d..3fdd1f08 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/syncfileclient +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/syncfileclient @@ -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__': diff --git a/confluent_osdeploy/genesis/profiles/default/scripts/syncfileclient b/confluent_osdeploy/genesis/profiles/default/scripts/syncfileclient index 5638244d..3fdd1f08 100644 --- a/confluent_osdeploy/genesis/profiles/default/scripts/syncfileclient +++ b/confluent_osdeploy/genesis/profiles/default/scripts/syncfileclient @@ -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__': diff --git a/confluent_osdeploy/suse15/profiles/hpc/scripts/syncfileclient b/confluent_osdeploy/suse15/profiles/hpc/scripts/syncfileclient index 5638244d..3fdd1f08 100644 --- a/confluent_osdeploy/suse15/profiles/hpc/scripts/syncfileclient +++ b/confluent_osdeploy/suse15/profiles/hpc/scripts/syncfileclient @@ -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__': diff --git a/confluent_osdeploy/ubuntu20.04/profiles/default/scripts/syncfileclient b/confluent_osdeploy/ubuntu20.04/profiles/default/scripts/syncfileclient index 5638244d..3fdd1f08 100644 --- a/confluent_osdeploy/ubuntu20.04/profiles/default/scripts/syncfileclient +++ b/confluent_osdeploy/ubuntu20.04/profiles/default/scripts/syncfileclient @@ -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__':