class RawxRebuildCommand(SingleServiceCommandMixin, ServiceRebuildCommand): tool_class = BlobRebuilder columns = ('Chunk', 'Status', 'Errors') def get_parser(self, prog_name): parser = super(RawxRebuildCommand, self).get_parser(prog_name) SingleServiceCommandMixin.patch_parser(self, parser) # common parser.add_argument( '--rdir-fetch-limit', type=int, help='Maximum number of entries returned in each rdir response. ' '(default=%d)' % self.tool_class.DEFAULT_RDIR_FETCH_LIMIT) if not self.distributed: # local parser.add_argument('--dry-run', action='store_true', help='Display actions but do nothing. ' '(default=%s)' % self.tool_class.DEFAULT_DRY_RUN) parser.add_argument( '--delete-faulty-chunks', action='store_true', help='Try to delete faulty chunks after they have been ' 'rebuilt elsewhere. This option is useful if the chunks ' 'you are rebuilding are not actually missing but are ' 'corrupted. ' '(default=%s)' % self.tool_class.DEFAULT_TRY_CHUNK_DELETE) return parser def _take_action(self, parsed_args): # common self.tool_conf['rdir_fetch_limit'] = parsed_args.rdir_fetch_limit if not self.distributed: # local self.tool_conf['dry_run'] = parsed_args.dry_run self.tool_conf['try_chunk_delete'] = \ parsed_args.delete_faulty_chunks self.rebuilder = BlobRebuilder(self.tool_conf, service_id=parsed_args.service, logger=self.logger) if self.distributed: self.rebuilder.prepare_distributed_dispatcher() else: self.rebuilder.prepare_local_dispatcher() for item, _, error in self.rebuilder.run(): if error is None: status = 'OK' else: status = 'error' yield (self.rebuilder.string_from_item(item), status, error) def take_action(self, parsed_args): SingleServiceCommandMixin.check_and_load_parsed_args( self, self.app, parsed_args) return super(RawxRebuildCommand, self).take_action(parsed_args)
class ChunkRebuildCommand(ItemRebuildCommand): tool_class = BlobRebuilder columns = ('Chunk', 'Status', 'Errors') def get_parser(self, prog_name): parser = super(ChunkRebuildCommand, self).get_parser(prog_name) parser.add_argument( '--input-file', help='Read chunks from this file instead of rdir. ' 'Each line should be formatted like ' '"container_id|content_id|short_chunk_id_or_position".') if not self.distributed: # local parser.add_argument('--dry-run', action='store_true', help='Display actions but do nothing. ' '(default=%s)' % self.tool_class.DEFAULT_DRY_RUN) parser.add_argument( '--delete-faulty-chunks', action='store_true', help='Try to delete faulty chunks after they have been ' 'rebuilt elsewhere. This option is useful if the chunks ' 'you are rebuilding are not actually missing but are ' 'corrupted. ' '(default=%s)' % self.tool_class.DEFAULT_TRY_CHUNK_DELETE) return parser def _take_action(self, parsed_args): if not self.distributed: # local self.tool_conf['dry_run'] = parsed_args.dry_run self.tool_conf['try_chunk_delete'] = \ parsed_args.delete_faulty_chunks self.rebuilder = BlobRebuilder(self.tool_conf, input_file=parsed_args.input_file, logger=self.logger) if self.distributed: self.rebuilder.prepare_distributed_dispatcher() else: self.rebuilder.prepare_local_dispatcher() for item, _, error in self.rebuilder.run(): if error is None: status = 'OK' else: status = 'error' yield (self.rebuilder.string_from_item(item), status, error) def take_action(self, parsed_args): if not parsed_args.input_file: raise ValueError('Missing input file') return super(ChunkRebuildCommand, self).take_action(parsed_args)