From 09258822b2c23dfd78b2c774623c18251859bf65 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Sat, 7 Dec 2013 07:42:19 +1100 Subject: [PATCH] Script to upload old logs to swift Change-Id: I07ea7d0394bde0e2508d87b22ce64d2822f02649 --- tools/push_to_cloudfiles.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 tools/push_to_cloudfiles.py diff --git a/tools/push_to_cloudfiles.py b/tools/push_to_cloudfiles.py new file mode 100755 index 0000000..cef60ca --- /dev/null +++ b/tools/push_to_cloudfiles.py @@ -0,0 +1,33 @@ +#!/usr/bin/python + +import json +import os +import pyrax +import sys + + +def copy_dir(topdir, path, container): + for ent in os.listdir(path): + fullpath = os.path.join(path, ent) + shortpath = fullpath.replace(topdir + '/', '') + if os.path.isdir(fullpath): + copy_dir(topdir, fullpath, container) + else: + print shortpath + container.upload_file(fullpath, obj_name=shortpath) + + +def push(topdir, region, container_name): + pyrax.set_setting('identity_type', 'rackspace') + with open(os.path.expanduser('~/.cloudfiles'), 'r') as f: + conf = json.loads(f.read()) + pyrax.set_credentials(conf['access_key'], + conf['secret_key'], + region=region) + conn = pyrax.connect_to_cloudfiles(region=region.upper(), public=False) + container = conn.create_container(container_name) + copy_dir(topdir, topdir, container) + + +if __name__ == '__main__': + push(sys.argv[1], sys.argv[2], sys.argv[3])