+ try:
+ out.output("Uploading image to the cloud:")
+ account = Kamaki.get_account(wizard['Cloud'])
+ assert account, "Cloud: %s is not valid" % wizard['Cloud']
+ kamaki = Kamaki(account, out)
+
+ name = "%s-%s.diskdump" % (wizard['ImageName'],
+ time.strftime("%Y%m%d%H%M"))
+ pithos_file = ""
+ with open(image.device, 'rb') as f:
+ pithos_file = kamaki.upload(f, size, name,
+ "(1/3) Calculating block hashes",
+ "(2/3) Uploading missing blocks")
+
+ out.output("(3/3) Uploading md5sum file ...", False)
+ md5sumstr = '%s %s\n' % (session['checksum'], name)
+ kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr),
+ remote_path="%s.%s" % (name, 'md5sum'))
+ out.success('done')
+ out.output()
+
+ is_public = True if wizard['ImageRegistration'] == "Public" else \
+ False
+ out.output('Registering %s image with the cloud ...' %
+ wizard['ImageRegistration'].lower(), False)
+ result = kamaki.register(wizard['ImageName'], pithos_file,
+ metadata, is_public)
+ out.success('done')
+ out.output("Uploading metadata file ...", False)
+ metastring = unicode(json.dumps(result, ensure_ascii=False))
+ kamaki.upload(StringIO.StringIO(metastring), size=len(metastring),
+ remote_path="%s.%s" % (name, 'meta'))
+ 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:
+ raise FatalError("Storage service client: %d %s" %
+ (e.status, e.message))
+ finally:
+ out.remove(with_progress)
+
+ text = "The %s image was successfully uploaded to the storage service " \
+ "and registered with the compute service of %s. Would you like " \
+ "to keep a local copy?" % \
+ (wizard['Cloud'], wizard['ImageRegistration'].lower())
+
+ if not d.yesno(text, width=PAGE_WIDTH):
+ extract_image(session)