Commit 3afe6b44 authored by Nikos Skalkotos's avatar Nikos Skalkotos

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.
parent 03eb7dc8
......@@ -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:
......
......@@ -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
......
......@@ -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)
......
......@@ -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:
......
......@@ -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)
......
......@@ -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"""
......
......@@ -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))
......
......@@ -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"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment