diff options
| author | Krzysztof A. Adamski <krzysztofa@gmail.com> | 2008-08-21 18:11:04 +0200 |
|---|---|---|
| committer | Krzysztof A. Adamski <krzysztofa@gmail.com> | 2008-08-23 14:40:28 +0200 |
| commit | 41f53ee4a0edb6899b8377dabbdba525cb6d1844 (patch) | |
| tree | 817fbd1d26bbab6802a709ece045e8f69ef86f4d /func | |
| parent | a07ef03e52427fa26f8990031705a86fdd7c9291 (diff) | |
Create simple copyfile overlord module that is able to send big files.
Diffstat (limited to 'func')
| -rw-r--r-- | func/minion/modules/copyfile.py | 41 | ||||
| -rw-r--r-- | func/overlord/cmd_modules/copyfile.py | 16 | ||||
| -rw-r--r-- | func/overlord/modules/copyfile.py | 27 |
3 files changed, 69 insertions, 15 deletions
diff --git a/func/minion/modules/copyfile.py b/func/minion/modules/copyfile.py index 150af88..8ae3351 100644 --- a/func/minion/modules/copyfile.py +++ b/func/minion/modules/copyfile.py @@ -46,6 +46,47 @@ class CopyFile(func_module.FuncModule): return thissum.hexdigest() + def open(self, filepath, mode=None, uid=-1, gid=-1): + dirpath = os.path.dirname(filepath) + if not os.path.exists(dirpath): + os.makedirs(dirpath) + + # Create empty file + try: + fo = open(filepath, 'w') + fo.close() + del fo + except (IOError, OSError), e: + # XXX logger output here + return -1 + + try: + # we could intify the mode here if it's a string + if mode: + os.chmod(filepath, mode) + if uid != -1 or gid != -1: + os.chown(filepath, uid, gid) + except (IOError, OSError), e: + return -1 + + return filepath + + def append(self, filepath, filebuf): + if not os.path.exists(filepath): + # file disaperead + return -1 + + try: + fo = open(filepath, 'a') + fo.write(filebuf.data) + fo.close() + del fo + except (IOError, OSError), e: + # XXX logger output here + return -1 + + return 1 + def copyfile(self, filepath, filebuf, mode=0644, uid=0, gid=0, force=None): # -1 = problem file was not copied diff --git a/func/overlord/cmd_modules/copyfile.py b/func/overlord/cmd_modules/copyfile.py index c8bc7e8..711c4dd 100644 --- a/func/overlord/cmd_modules/copyfile.py +++ b/func/overlord/cmd_modules/copyfile.py @@ -49,19 +49,5 @@ class CopyFile(base_command.BaseCommand): self.server_spec = self.parentCommand.server_spec self.getOverlord() - - try: - fb = open(self.options.filename, "r").read() - except IOError, e: - sys.stderr.write("Unable to open file: %s: %s\n" % (self.options.filename, e)) - return - - st = os.stat(self.options.filename) - mode = stat.S_IMODE(st.st_mode) - uid = st.st_uid - gid = st.st_gid - - data = xmlrpclib.Binary(fb) - results = self.overlord_obj.run("copyfile", "copyfile", [self.options.remotepath, data, - mode, uid, gid]) + return self.overlord_obj.local.copyfile.send(self.options.filename, self.options.remotepath) diff --git a/func/overlord/modules/copyfile.py b/func/overlord/modules/copyfile.py new file mode 100644 index 0000000..2954462 --- /dev/null +++ b/func/overlord/modules/copyfile.py @@ -0,0 +1,27 @@ +from func.overlord import overlord_module +import os +import stat +import xmlrpclib + +class copyfile(overlord_module.BaseModule): + def send(self, localpath, remotepath, bufsize=60000): + try: + f = open(localpath, "r") + except IOError, e: + sys.stderr.write("Unable to open file: %s: %s\n" % (self.options.filename, e)) + return + + st = os.stat(localpath) + mode = stat.S_IMODE(st.st_mode) + uid = st.st_uid + gid = st.st_gid + + self.parent.run("copyfile", "open", [remotepath, mode, uid, gid]) + + while True: + data=f.read(bufsize) + if data: + self.parent.run("copyfile", "append", [remotepath, xmlrpclib.Binary(data)]) + else: + break + |
