- metadata['size'] = str(size // 2 ** 20)
- dd('if=%s' % dev.device,
- 'of=%s/%s.%s' % (options.outdir, options.name, 'diskdump'),
- 'bs=4M', 'count=%d' % ((size + 1) // 2 ** 22))
-
- f = open('%s/%s.%s' % (options.outdir, options.name, 'meta'), 'w')
- for key in metadata.keys():
- f.write("%s=%s\n" % (key, metadata[key]))
- f.close()
+ metadata['SIZE'] = str(size // 2 ** 20)
+
+ checksum = md5(snapshot, size)
+
+ metastring = "\n".join(
+ ['%s=%s' % (key, value) for (key, value) in metadata.items()])
+
+ if options.outfile is not None:
+ dev.dump(options.outfile)
+
+ output('Dumping metadata file...', False)
+ with open('%s.%s' % (options.outfile, 'meta'), 'w') as f:
+ f.write(metastring)
+ success('done')
+
+ output('Dumping md5sum file...', False)
+ with open('%s.%s' % (options.outfile, 'md5sum'), 'w') as f:
+ f.write('%s %s' % (
+ checksum, os.path.basename(options.outfile)))
+ success('done')
+
+ # Destroy the device. We only need the snapshot from now on
+ disk.destroy_device(dev)
+
+ output()
+
+ uploaded_obj = ""
+ if options.upload:
+ output("Uploading image to pithos:")
+ kamaki = Kamaki(options.account, options.token)
+ with open(snapshot) as f:
+ uploaded_obj = kamaki.upload(f, size, options.upload,
+ "(1/4) Calculating block hashes",
+ "(2/4) Uploading missing blocks")
+
+ output("(3/4) Uploading metadata file...", False)
+ kamaki.upload(StringIO.StringIO(metastring), size=len(metastring),
+ remote_path="%s.%s" % (options.upload, 'meta'))
+ success('done')
+ output("(4/4) Uploading md5sum file...", False)
+ md5sumstr = '%s %s' % (checksum, os.path.basename(options.upload))
+ kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr),
+ remote_path="%s.%s" % (options.upload, 'md5sum'))
+ success('done')
+ output()
+
+ if options.register:
+ output('Registring image to ~okeanos...', False)
+ kamaki.register(options.register, uploaded_obj, metadata)
+ success('done')
+ output()
+