def main(self): services = { 's3': { 'service': self.service, 'auth': self.auth }, 'ec2': { 'service': self.args['ec2_service'], 'auth': self.args['ec2_auth'] } } unpacked_image = tempfile.TemporaryFile() with ImagePack.open(self.args['pack_filename']) as pack: if self.args['profile'] not in pack.image_md.profiles: raise ValueError( 'no such profile: "{0}" (choose from {1})'.format( self.args['profile'], ', '.join(pack.image_md.profiles.keys()))) with pack.open_image() as image: # We could technically hand the image file object # directly to the installation process and calculate # checksums on fly, but that would mean we error out # only after everything finishes and force people to # clean up after if the checksum happens to be bad. # We thus do this in two steps instead. digest = hashlib.sha256() bytes_written = 0 pbar = self.get_progressbar(label='Decompressing', maxval=pack.pack_md.image_size) pbar.start() while True: chunk = image.read(euca2ools.BUFSIZE) if not chunk: break digest.update(chunk) unpacked_image.write(chunk) bytes_written += len(chunk) pbar.update(bytes_written) pbar.finish() if digest.hexdigest() != pack.pack_md.image_sha256sum: raise RuntimeError( 'image appears to be corrupt ' '(expected SHA256: {0}, actual: {1})', pack.pack_md.image_sha256sum, digest.hexdigest()) unpacked_image.seek(0) image_id = pack.image_md.install_profile(self.args['profile'], services, unpacked_image, pack.pack_md.image_size, self.args) unpacked_image.close() return image_id
def main(self): services = {'s3': {'service': self.service, 'auth': self.auth}, 'ec2': {'service': self.args['ec2_service'], 'auth': self.args['ec2_auth']}} unpacked_image = tempfile.TemporaryFile() with ImagePack.open(self.args['pack_filename']) as pack: if self.args['profile'] not in pack.image_md.profiles: raise ValueError( 'no such profile: "{0}" (choose from {1})'.format( self.args['profile'], ', '.join(pack.image_md.profiles.keys()))) with pack.open_image() as image: # We could technically hand the image file object # directly to the installation process and calculate # checksums on fly, but that would mean we error out # only after everything finishes and force people to # clean up after if the checksum happens to be bad. # We thus do this in two steps instead. digest = hashlib.sha256() bytes_written = 0 pbar = self.get_progressbar(label='Decompressing', maxval=pack.pack_md.image_size) pbar.start() while True: chunk = image.read(euca2ools.BUFSIZE) if not chunk: break digest.update(chunk) unpacked_image.write(chunk) bytes_written += len(chunk) pbar.update(bytes_written) pbar.finish() if digest.hexdigest() != pack.pack_md.image_sha256sum: raise RuntimeError('image appears to be corrupt ' '(expected SHA256: {0}, actual: {1})', pack.pack_md.image_sha256sum, digest.hexdigest()) unpacked_image.seek(0) image_id = pack.image_md.install_profile( self.args['profile'], services, unpacked_image, pack.pack_md.image_size, self.args) unpacked_image.close() return image_id
def main(self): return ImagePack.open(self.args['pack_filename'])