def main(self): if not self.source_dir: self.source_dir = self.get_file_path(self.manifest_path) if not self.private_key_path: self.private_key_path = self.get_environ('EC2_PRIVATE_KEY') if not os.path.isfile(self.private_key_path): msg = 'Private Key not found: %s' % self.private_key_path self.display_error_and_exit(msg) bundler = euca2ools.bundler.Bundler(self) (parts, encrypted_key, encrypted_iv) = \ bundler.parse_manifest(self.manifest_path) image = bundler.assemble_parts(self.source_dir, self.destination_dir, self.manifest_path, parts) print('Decrypting image') decrypted_image = bundler.decrypt_image(image, encrypted_key, encrypted_iv, self.private_key_path) os.remove(image) print('Uncompressing image') try: bundler.untarzip_image(self.destination_dir, decrypted_image) except NotFoundError: sys.exit(1) except CommandFailed: sys.exit(1) os.remove(decrypted_image)
def main(self): if not self.source_dir: self.source_dir = self.get_file_path(self.manifest_path) if not self.private_key_path: self.private_key_path = self.get_environ('EC2_PRIVATE_KEY') if not os.path.isfile(self.private_key_path): msg = 'Private Key not found: %s' % self.private_key_path self.display_error_and_exit(msg) bundler = euca2ools.bundler.Bundler(self) (parts, encrypted_key, encrypted_iv) = \ bundler.parse_manifest(self.manifest_path) image = bundler.assemble_parts(self.source_dir, self.destination_dir, self.manifest_path, parts) print 'Decrypting image' decrypted_image = bundler.decrypt_image(image, encrypted_key, encrypted_iv, self.private_key_path) os.remove(image) print 'Uncompressing image' try: bundler.untarzip_image(self.destination_dir, decrypted_image) except NotFoundError: sys.exit(1) except CommandFailed: sys.exit(1) os.remove(decrypted_image)
def bundleAll(self, file, image): print "Unwrapping tarball" bundler = euca2ools.bundler.Bundler(self) names = bundler.untarzip_image(self.destination, file) kernel_dir = self.cli_options.kernel_type + '-kernel' #iterate, and install kernel/ramdisk first, store the ids kernel_id = self.cli_options.kernel ramdisk_id = self.cli_options.ramdisk if kernel_id == None: for path in names: if path.find(kernel_dir) > -1: name = os.path.basename(path) if not name.startswith('.'): if name.startswith('vmlin'): print "Bundling/uploading kernel" kernel_id = self.bundleFile( path, name, image, 'true', None) print kernel_id elif name.startswith('initrd'): print "Bundling/uploading ramdisk" ramdisk_id = self.bundleFile( path, name, image, None, 'true') print ramdisk_id #now, install the image, referencing the kernel/ramdisk for path in names: name = os.path.basename(path) if not name.startswith('.'): if name.endswith('.img'): print "Bundling/uploading image" name = name[:-len('.img')] id = self.bundleFile(path, name, image, kernel_id, ramdisk_id) return id
def bundleAll(self, file, image): print "Unwrapping tarball" bundler = euca2ools.bundler.Bundler(self) names = bundler.untarzip_image(self.destination, file) kernel_dir = self.cli_options.kernel_type+'-kernel' #iterate, and install kernel/ramdisk first, store the ids kernel_id=self.cli_options.kernel ramdisk_id=self.cli_options.ramdisk if kernel_id==None: for path in names: if path.find(kernel_dir) > -1: name = os.path.basename(path) if not name.startswith('.'): if name.startswith('vmlin'): print "Bundling/uploading kernel" kernel_id = self.bundleFile(path, name, image, 'true', None) print kernel_id elif name.startswith('initrd'): print "Bundling/uploading ramdisk" ramdisk_id = self.bundleFile(path, name, image, None, 'true') print ramdisk_id #now, install the image, referencing the kernel/ramdisk for path in names: name = os.path.basename(path) if not name.startswith('.'): if name.endswith('.img'): print "Bundling/uploading image" name = name[:-len('.img')] id = self.bundleFile(path, name, image, kernel_id, ramdisk_id) return id
def bundleAll(self, file, prefix, description, arch): print "Unbundling image" bundler = euca2ools.bundler.Bundler(self) try: names = bundler.untarzip_image(self.destination, file) except OSError: print "Error: cannot unbundle image, possibly corrupted file" sys.exit(-1) except IOError: print "Error: cannot unbundle image, possibly corrupted file" sys.exit(-1) kernel_dir = None if not (self.cli_options.kernel_type == None): kernel_dir = self.cli_options.kernel_type + '-kernel' print "going to look for kernel dir : " + kernel_dir #iterate, and install kernel/ramdisk first, store the ids kernel_id = self.cli_options.kernel ramdisk_id = self.cli_options.ramdisk kernel_found = False if kernel_id == None: for i in [0, 1]: tar_root = os.path.commonprefix(names) for path in names: if (kernel_dir == None or path.find(kernel_dir) > -1): name = os.path.basename(path) if not (kernel_dir) and (os.path.dirname(path) != tar_root): continue if not name.startswith('.'): # Note that vmlinuz is not always at the beginning of the filename if name.find('vmlinu') != -1: print "Bundling/uploading kernel" if prefix: name = prefix + name kernel_id = self.bundleFile( path, name, description, arch, 'true', None) kernel_found = True print kernel_id elif re.match(".*(initr(d|amfs)|loader).*", name): print "Bundling/uploading ramdisk" if prefix: name = prefix + name ramdisk_id = self.bundleFile( path, name, description, arch, None, 'true') print ramdisk_id if not (kernel_found): if not (kernel_dir): print "Error: couldn't find kernel. Check your parameters or specify an existing kernel/ramdisk" sys.exit(-1) elif i == 0: print "Error: couldn't find kernel. Check your parameters or specify an existing kernel/ramdisk" sys.exit(-1) else: break #now, install the image, referencing the kernel/ramdisk for path in names: name = os.path.basename(path) if not name.startswith('.'): if name.endswith('.img'): print "Bundling/uploading image" if prefix: name = prefix else: name = name[:-len('.img')] id = self.bundleFile(path, name, description, arch, kernel_id, ramdisk_id) return id
def bundleAll(self, file, prefix, description, arch): print "Unbundling image" bundler = euca2ools.bundler.Bundler(self) try: names = bundler.untarzip_image(self.destination, file) except OSError: print >> sys.stderr, "Error: cannot unbundle image, possibly corrupted file" sys.exit(-1) except IOError: print >> sys.stderr, "Error: cannot unbundle image, possibly corrupted file" sys.exit(-1) kernel_dir=None if not(self.cli_options.kernel_type==None): kernel_dir = self.cli_options.kernel_type+'-kernel' print "going to look for kernel dir : "+kernel_dir #iterate, and install kernel/ramdisk first, store the ids kernel_id=self.cli_options.kernel ramdisk_id=self.cli_options.ramdisk kernel_found = False if kernel_id==None: for i in [0, 1]: tar_root = os.path.commonprefix(names) for path in names: if (kernel_dir==None or path.find(kernel_dir) > -1): name = os.path.basename(path) if not(kernel_dir) and (os.path.dirname(path) != tar_root): continue; if not name.startswith('.'): # Note that vmlinuz is not always at the beginning of the filename if name.find('vmlinu') != -1: print "Bundling/uploading kernel" if prefix: name = prefix+name kernel_id = self.bundleFile(path, name, description, arch, 'true', None) kernel_found = True print kernel_id elif re.match(".*(initr(d|amfs)|loader).*", name): print "Bundling/uploading ramdisk" if prefix: name = prefix+name ramdisk_id = self.bundleFile(path, name, description, arch, None, 'true') print ramdisk_id if not(kernel_found): if not(kernel_dir): print >> sys.stderr, "Error: couldn't find kernel. Check your parameters or specify an existing kernel/ramdisk" sys.exit(-1); elif i==0: print >> sys.stderr, "Error: couldn't find kernel. Check your parameters or specify an existing kernel/ramdisk" sys.exit(-1); else: break #now, install the image, referencing the kernel/ramdisk for path in names: name = os.path.basename(path) if not name.startswith('.'): if name.endswith('.img'): print "Bundling/uploading image" if prefix: name = prefix else: name = name[:-len('.img')] id = self.bundleFile(path, name, description, arch, kernel_id, ramdisk_id) return id