Illustration fix for issue lp#665667. Tested to work at Amazon. Leaves the temp file behind so sha1sum can be run on it. May make euca2ools incompatible with Eucalyptus (although not likely). Not to be applied upstream as-is! diff -urp -X dontdiff.eu euca2ools-1.3.1/bin/euca-bundle-image euca2ools-1.3.1-p3/bin/euca-bundle-image --- euca2ools-1.3.1/bin/euca-bundle-image 2010-09-04 11:57:30.000000000 -0600 +++ euca2ools-1.3.1-p3/bin/euca-bundle-image 2010-12-08 23:56:45.000275997 -0700 @@ -223,12 +224,11 @@ def main(): print 'Invalid ec2cert' sys.exit(1) - (image_size, sha_image_digest) = euca.check_image(image_path, - destination_path) + image_size = euca.check_image_1(image_path, destination_path) if not prefix: prefix = euca.get_relative_filename(image_path) try: - tgz_file = euca.tarzip_image(prefix, image_path, + (tgz_file, sha_tar_digest) = euca.tarzip_image_2(prefix, image_path, destination_path) except NotFoundError: sys.exit(1) @@ -258,7 +258,7 @@ def main(): target_arch, image_size, bundled_size, - sha_image_digest, + sha_tar_digest, user, kernel, ramdisk, diff -urp -X dontdiff.eu euca2ools-1.3.1/euca2ools/euca2ools/__init__.py euca2ools-1.3.1-p3/euca2ools/euca2ools/__init__.py --- euca2ools-1.3.1/euca2ools/euca2ools/__init__.py 2010-09-04 11:57:30.000000000 -0600 +++ euca2ools-1.3.1-p3/euca2ools/euca2ools/__init__.py 2010-12-09 00:09:30.215275990 -0700 @@ -598,16 +598,13 @@ class Euca2ool: else: self.ec2_url = self.ec2_url.replace('http://', '') self.is_secure = False - self.host = self.ec2_url - url_parts = self.ec2_url.split(':') + url_parts = self.ec2_url.split('/', 1) if len(url_parts) > 1: - self.host = url_parts[0] - path_parts = url_parts[1].split('/', 1) - if len(path_parts) > 1: - self.port = int(path_parts[0]) - self.service_path = self.service_path + path_parts[1] - else: - self.port = int(url_parts[1]) + self.service_path = '/' + url_parts[1] + host_parts = url_parts[0].split(':') + if len(host_parts) > 1: + self.port = int(host_parts[1]) + self.host = host_parts[0] if not self.is_s3: return EC2Connection( @@ -720,9 +717,18 @@ class Euca2ool: buf = in_file.read(IMAGE_IO_CHUNK) if not buf: break - sha_image.update(buf) + sha_image.update(buf) return (image_size, hexlify(sha_image.digest())) + def check_image_1(self, image_file, path): + print 'Checking image' + if not os.path.exists(path): + os.makedirs(path) + image_size = os.path.getsize(image_file) + if self.debug: + print 'Image Size:', image_size, 'bytes' + return image_size + def tarzip_image( self, prefix, @@ -751,6 +757,54 @@ class Euca2ool: raise CommandFailed return tar_file + def tarzip_image_2( + self, + prefix, + file, + path, + ): + Util().check_prerequisite_command('tar') + + tmp_file = '%s.tar' % os.path.join(path, prefix) + + print 'Tarring image' + tmpfile = open(tmp_file, 'wb') + file_path = self.get_file_path(file) + tar_cmd = ['tar', 'c', '-S'] + if file_path: + tar_cmd.append('-C') + tar_cmd.append(file_path) + tar_cmd.append(self.get_relative_filename(file)) + else: + tar_cmd.append(file) + p1 = Popen(tar_cmd, stdout=tmpfile) + p1.communicate() + tmpfile.close() + + print 'Digesting image' + tmpfile = open(tmp_file, 'rb') + sha_image = sha() + while 1: + buf = tmpfile.read(IMAGE_IO_CHUNK) + if not buf: + break + sha_image.update(buf) + tmpfile.close() + print 'digest', hexlify(sha_image.digest()) + + print 'Compressing image' + tmpfile = open(tmp_file, 'rb') + tar_file = '%s.tar.gz' % os.path.join(path, prefix) + outfile = open(tar_file, 'wb') + p2 = Popen(['gzip'], stdin=tmpfile, stdout=outfile) + p2.communicate() + tmpfile.close() + outfile.close() + if os.path.getsize(tar_file) <= 0: + print 'Could not tar image' + raise CommandFailed + return (tar_file, hexlify(sha_image.digest())) + def hexToBytes(self, hexString): bytes = [] hexString = ''.join(hexString.split(' '))