def main(self):
        if self.args.get('manifest_url'):
            manifest_url = self.args['manifest_url']
        if self.args.get('task'):
            desc_conv = DescribeConversionTasks.from_other(
                self, ConversionTaskId=[self.args['task']])
            task = desc_conv.main()['conversionTasks'][0]
            assert task['conversionTaskId'] == self.args['task']
            if task.get('importVolume'):
                vol_container = task['importVolume']
            else:
                vol_container = task['importInstance']['volumes'][0]
            manifest_url = vol_container['image']['importManifestUrl']
        _, bucket, key = self.args['s3_service'].resolve_url_to_location(
            manifest_url)
        manifest_s3path = '/'.join((bucket, key))
        manifest = self.__download_manifest(manifest_s3path)

        for part in manifest.image_parts:
            delete_req = DeleteObject.from_other(
                self,
                service=self.args['s3_service'],
                auth=self.args['s3_auth'],
                path='/'.join((bucket, part.key)))
            delete_req.main()
        delete_req = DeleteObject.from_other(self,
                                             service=self.args['s3_service'],
                                             auth=self.args['s3_auth'],
                                             path=manifest_s3path)
        delete_req.main()
Example #2
0
    def main(self):
        if self.args.get("manifest_url"):
            manifest_url = self.args["manifest_url"]
        if self.args.get("task"):
            desc_conv = DescribeConversionTasks.from_other(self, ConversionTaskId=[self.args["task"]])
            task = desc_conv.main()["conversionTasks"][0]
            assert task["conversionTaskId"] == self.args["task"]
            if task.get("importVolume"):
                vol_container = task["importVolume"]
            else:
                vol_container = task["importInstance"]["volumes"][0]
            manifest_url = vol_container["image"]["importManifestUrl"]
        _, bucket, key = self.args["s3_service"].resolve_url_to_location(manifest_url)
        manifest_s3path = "/".join((bucket, key))
        manifest = self.__download_manifest(manifest_s3path)

        for part in manifest.image_parts:
            delete_req = DeleteObject.from_other(
                self, service=self.args["s3_service"], auth=self.args["s3_auth"], path="/".join((bucket, part.key))
            )
            delete_req.main()
        delete_req = DeleteObject.from_other(
            self, service=self.args["s3_service"], auth=self.args["s3_auth"], path=manifest_s3path
        )
        delete_req.main()
Example #3
0
    def main(self):
        if self.args.get('dry_run'):
            return

        if self.args.get('show_progress', False):
            print 'Uploading image for task', self.args['task']

        # Manifest
        desc_conv = DescribeConversionTasks.from_other(
            self, ConversionTaskId=[self.args['task']])
        task = desc_conv.main()['conversionTasks'][0]
        assert task['conversionTaskId'] == self.args['task']

        if task.get('importVolume'):
            vol_container = task['importVolume']
        else:
            vol_container = task['importInstance']['volumes'][0]
        file_size = euca2ools.util.get_filesize(self.args['source'])
        manifest = self.__get_or_create_manifest(vol_container, file_size)
        file_size_from_manifest = manifest.image_parts[-1].end + 1
        if file_size_from_manifest != file_size:
            raise ArgumentError(
                'file "{0}" is not the same size as the file the import '
                'started with (expected: {1}, actual: {2})'
                .format(self.args['source'], file_size_from_manifest,
                        file_size))

        # Now we have a manifest; check to see what parts are already uploaded
        _, bucket, _ = self.args['s3_service'].resolve_url_to_location(
            vol_container['image']['importManifestUrl'])
        pbar_label_template = euca2ools.util.build_progressbar_label_template(
            [os.path.basename(part.key) for part in manifest.image_parts])
        for part in manifest.image_parts:
            part_s3path = '/'.join((bucket, part.key))
            head_req = HeadObject.from_other(
                self, service=self.args['s3_service'],
                auth=self.args['s3_auth'], path=part_s3path)
            try:
                head_req.main()
            except AWSError as err:
                if err.status_code == 404:
                    self.__upload_part(part, part_s3path, pbar_label_template)
                else:
                    raise