+ image.dump(options.outfile)
+
+ out.output('Dumping metadata file ...', False)
+ with open('%s.%s' % (options.outfile, 'meta'), 'w') as f:
+ f.write(metastring)
+ out.success('done')
+
+ out.output('Dumping md5sum file ...', False)
+ with open('%s.%s' % (options.outfile, 'md5sum'), 'w') as f:
+ f.write('%s %s\n' % (checksum,
+ os.path.basename(options.outfile)))
+ out.success('done')
+
+ # Destroy the image instance. We only need the snapshot from now on
+ disk.destroy_image(image)
+
+ out.output()
+ try:
+ uploaded_obj = ""
+ if options.upload:
+ out.output("Uploading image to pithos:")
+ kamaki = Kamaki(account, out)
+ with open(snapshot, 'rb') as f:
+ uploaded_obj = kamaki.upload(
+ f, size, options.upload,
+ "(1/4) Calculating block hashes",
+ "(2/4) Uploading missing blocks")
+
+ out.output("(3/4) Uploading metadata file ...", False)
+ kamaki.upload(StringIO.StringIO(metastring),
+ size=len(metastring),
+ remote_path="%s.%s" % (options.upload, 'meta'))
+ out.success('done')
+ out.output("(4/4) Uploading md5sum file ...", False)
+ md5sumstr = '%s %s\n' % (checksum,
+ os.path.basename(options.upload))
+ kamaki.upload(StringIO.StringIO(md5sumstr),
+ size=len(md5sumstr),
+ remote_path="%s.%s" % (options.upload, 'md5sum'))
+ out.success('done')
+ out.output()
+
+ if options.register:
+ img_type = 'public' if options.public else 'private'
+ out.output('Registering %s image with ~okeanos ...' % img_type,
+ False)
+ kamaki.register(options.register, uploaded_obj, metadata,
+ options.public)
+ out.success('done')
+ out.output()
+ except ClientError as e:
+ raise FatalError("Pithos client: %d %s" % (e.status, e.message))
+