Share the md5sum and meta file if image is public
authorNikos Skalkotos <skalkoto@grnet.gr>
Mon, 27 May 2013 10:08:51 +0000 (13:08 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Mon, 27 May 2013 10:08:51 +0000 (13:08 +0300)
If the image gets registered as public allow anyone to read the
metadata and the md5sum file.

image_creator/dialog_main.py
image_creator/dialog_menu.py
image_creator/dialog_util.py
image_creator/dialog_wizard.py
image_creator/disk.py
image_creator/kamaki_wrapper.py
image_creator/main.py
image_creator/output/__init__.py

index 7e6b33d..024c37f 100644 (file)
@@ -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:
index a167d73..b6d3162 100644 (file)
@@ -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
index e18fb89..046ee3e 100644 (file)
@@ -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)
index 260a5bd..30dc7c6 100644 (file)
@@ -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:
index b4311f8..38372c5 100644 (file)
@@ -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)
index a722c7b..e2012d2 100644 (file)
@@ -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"""
 
index 99a35e3..10fc0b5 100644 (file)
@@ -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))
index 7beceac..e421c75 100644 (file)
@@ -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"""