From 3afe6b44b9915753117bc950becf86c71704dcbf Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos Date: Mon, 27 May 2013 13:08:51 +0300 Subject: [PATCH 1/1] Share the md5sum and meta file if image is public If the image gets registered as public allow anyone to read the metadata and the md5sum file. --- image_creator/dialog_main.py | 6 +++--- image_creator/dialog_menu.py | 5 +++++ image_creator/dialog_util.py | 4 ++-- image_creator/dialog_wizard.py | 8 ++++++++ image_creator/disk.py | 2 +- image_creator/kamaki_wrapper.py | 5 +++++ image_creator/main.py | 8 ++++++++ image_creator/output/__init__.py | 2 +- 8 files changed, 33 insertions(+), 7 deletions(-) diff --git a/image_creator/dialog_main.py b/image_creator/dialog_main.py index 7e6b33d..024c37f 100644 --- a/image_creator/dialog_main.py +++ b/image_creator/dialog_main.py @@ -72,7 +72,7 @@ def create_image(d, media, out, tmp): snapshot = disk.snapshot() image = disk.get_image(snapshot) - out.output("Collecting image metadata...") + out.output("Collecting image metadata ...") metadata = {} for (key, value) in image.meta.items(): metadata[str(key)] = str(value) @@ -217,12 +217,12 @@ def main(): while 1: try: out = CompositeOutput([log]) - out.output("Starting %s v%s..." % + out.output("Starting %s v%s ..." % (parser.get_prog_name(), version)) ret = create_image(d, media, out, options.tmp) sys.exit(ret) except Reset: - log.output("Resetting everything...") + log.output("Resetting everything ...") continue finally: if logfile is not None: diff --git a/image_creator/dialog_menu.py b/image_creator/dialog_menu.py index a167d73..b6d3162 100644 --- a/image_creator/dialog_menu.py +++ b/image_creator/dialog_menu.py @@ -255,6 +255,11 @@ def register_image(session): size=len(metastring), remote_path="%s.meta" % session['upload']) out.success("done") + if is_public: + out.output("Sharing metadata and md5sum files...") + kamaki.share("%s.meta" % session['upload']) + kamaki.share("%s.md5sum" % session['upload']) + out.success('done') except ClientError as e: d.msgbox("Error in pithos+ client: %s" % e.message) return False diff --git a/image_creator/dialog_util.py b/image_creator/dialog_util.py index e18fb89..046ee3e 100644 --- a/image_creator/dialog_util.py +++ b/image_creator/dialog_util.py @@ -146,13 +146,13 @@ def extract_image(session): image.dump(path) # Extract metadata file - out.output("Extracting metadata file...") + out.output("Extracting metadata file ...") with open('%s.meta' % path, 'w') as f: f.write(extract_metadata_string(session)) out.success('done') # Extract md5sum file - out.output("Extracting md5sum file...") + out.output("Extracting md5sum file ...") md5str = "%s %s\n" % (session['checksum'], name) with open('%s.md5sum' % path, 'w') as f: f.write(md5str) diff --git a/image_creator/dialog_wizard.py b/image_creator/dialog_wizard.py index 260a5bd..30dc7c6 100644 --- a/image_creator/dialog_wizard.py +++ b/image_creator/dialog_wizard.py @@ -325,6 +325,14 @@ def create_image(session): kamaki.register(wizard['ImageName'], pithos_file, metadata, is_public) out.success('done') + if is_public: + out.output("Sharing md5sum file ...", False) + kamaki.share("%s.md5sum" % name) + out.success('done') + out.output("Sharing metadata file ...", False) + kamaki.share("%s.meta" % name) + out.success('done') + out.output() except ClientError as e: diff --git a/image_creator/disk.py b/image_creator/disk.py index b4311f8..38372c5 100644 --- a/image_creator/disk.py +++ b/image_creator/disk.py @@ -158,7 +158,7 @@ class Disk(object): self.out.success('looks like a block device') # Take a snapshot and return it to the user - self.out.output("Snapshotting media source...", False) + self.out.output("Snapshotting media source ...", False) size = blockdev('--getsz', sourcedev) cowfd, cow = tempfile.mkstemp(dir=self.tmp) os.close(cowfd) diff --git a/image_creator/kamaki_wrapper.py b/image_creator/kamaki_wrapper.py index a722c7b..e2012d2 100644 --- a/image_creator/kamaki_wrapper.py +++ b/image_creator/kamaki_wrapper.py @@ -117,6 +117,11 @@ class Kamaki(object): params = {'is_public': is_public, 'disk_format': 'diskdump'} self.image_client.register(name, location, params, str_metadata) + def share(self, location): + """Share this file with all the users""" + + self.pithos_client.set_object_sharing(location, "*") + def object_exists(self, location): """Check if an object exists in pythos""" diff --git a/image_creator/main.py b/image_creator/main.py index 99a35e3..10fc0b5 100644 --- a/image_creator/main.py +++ b/image_creator/main.py @@ -313,6 +313,14 @@ def image_creator(): size=len(metastring), remote_path="%s.%s" % (options.upload, 'meta')) out.success('done') + if options.public: + out.output("Sharing md5sum file ...", False) + kamaki.share("%s.md5sum" % options.upload) + out.success('done') + out.output("Sharing metadata file ...", False) + kamaki.share("%s.meta" % options.upload) + out.success('done') + out.output() except ClientError as e: raise FatalError("Pithos client: %d %s" % (e.status, e.message)) diff --git a/image_creator/output/__init__.py b/image_creator/output/__init__.py index 7beceac..e421c75 100644 --- a/image_creator/output/__init__.py +++ b/image_creator/output/__init__.py @@ -71,7 +71,7 @@ class Output(object): def __init__(self, size, title, bar_type='default'): self.size = size self.bar_type = bar_type - self.output.output("%s..." % title, False) + self.output.output("%s ..." % title, False) def goto(self, dest): """Move progress to a specific position""" -- 1.7.10.4