- outfile = options.outfile
- f = open('%s.%s' % (options.outfile, 'meta'), 'w')
- try:
- for key in metadata.keys():
- f.write("%s=%s\n" % (key, metadata[key]))
- finally:
- f.close()
- else:
- outfd, outfile = tmpfile.mkstemp()
- os.close(outfd)
-
- dd('if=%s' % dev.device,
- 'of=%s' % outfile,
- 'bs=4M', 'count=%d' % ((size + 1) // 2 ** 22))
+ dev.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 device. We only need the snapshot from now on
+ disk.destroy_device(dev)
+
+ out.output()
+ try:
+ uploaded_obj = ""
+ if options.upload:
+ out.output("Uploading image to pithos:")
+ kamaki = Kamaki(options.account, options.token, 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:
+ out.output('Registering image with ~okeanos...', False)
+ kamaki.register(options.register, uploaded_obj, metadata)
+ out.success('done')
+ out.output()
+ except ClientError as e:
+ raise FatalError("Pithos client: %d %s" % (e.status, e.message))