|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | +# |
| 13 | +from cliff import lister |
| 14 | +from oslo_utils import timeutils |
| 15 | + |
| 16 | +from cloudkittyclient import utils |
| 17 | + |
| 18 | + |
| 19 | +class CliReprocessingTasksGet(lister.Lister): |
| 20 | + """Get reprocessing tasks.""" |
| 21 | + |
| 22 | + result_columns = [ |
| 23 | + ('scope_id', 'Scope ID'), |
| 24 | + ('reason', 'Reason'), |
| 25 | + ('start_reprocess_time', 'Start reprocessing time'), |
| 26 | + ('end_reprocess_time', 'End reprocessing time'), |
| 27 | + ('current_reprocess_time', 'Current reprocessing time'), |
| 28 | + ] |
| 29 | + |
| 30 | + def get_parser(self, prog_name): |
| 31 | + parser = super(CliReprocessingTasksGet, self).get_parser(prog_name) |
| 32 | + |
| 33 | + parser.add_argument('--scope-id', type=str, default=[], |
| 34 | + action='append', help='Optional filter on scope ' |
| 35 | + 'IDs. This filter can be ' |
| 36 | + 'used multiple times.') |
| 37 | + |
| 38 | + parser.add_argument('--offset', type=int, default=0, |
| 39 | + help='Index of the first scope. ' |
| 40 | + 'The default value is 0.') |
| 41 | + parser.add_argument('--limit', type=int, default=100, |
| 42 | + help='Maximal number of scopes. ' |
| 43 | + 'The default value is 100.') |
| 44 | + parser.add_argument('--order', type=str, default="DESC", |
| 45 | + help='The order to sort the reprocessing tasks ' |
| 46 | + '(ASC or DESC).') |
| 47 | + |
| 48 | + return parser |
| 49 | + |
| 50 | + def take_action(self, parsed_args): |
| 51 | + resp = utils.get_client_from_osc( |
| 52 | + self).reprocessing.get_reprocessing_tasks( |
| 53 | + scope_ids=parsed_args.scope_id, offset=parsed_args.offset, |
| 54 | + limit=parsed_args.limit, order=parsed_args.order |
| 55 | + ) |
| 56 | + |
| 57 | + values = utils.list_to_cols(resp['results'], self.result_columns) |
| 58 | + return [col[1] for col in self.result_columns], values |
| 59 | + |
| 60 | + |
| 61 | +class CliReprocessingTasksPost(lister.Lister): |
| 62 | + """Create a reprocessing task.""" |
| 63 | + |
| 64 | + def get_parser(self, prog_name): |
| 65 | + parser = super(CliReprocessingTasksPost, self).get_parser(prog_name) |
| 66 | + |
| 67 | + parser.add_argument('--scope-id', type=str, default=[], |
| 68 | + action='append', |
| 69 | + help='The scope IDs to reprocess. This option can ' |
| 70 | + 'be used multiple times to execute the same ' |
| 71 | + 'reprocessing task for different scope IDs.') |
| 72 | + |
| 73 | + parser.add_argument('--start-reprocess-time', |
| 74 | + type=timeutils.parse_isotime, |
| 75 | + help="Start of the period to reprocess in ISO8601 " |
| 76 | + "format. Example: '2022-04-22T00:00:00Z.'") |
| 77 | + |
| 78 | + parser.add_argument('--end-reprocess-time', |
| 79 | + type=timeutils.parse_isotime, |
| 80 | + help="End of the period to reprocess in ISO8601 " |
| 81 | + "format. Example: '2022-04-22T00:00:00Z.'") |
| 82 | + |
| 83 | + parser.add_argument('--reason', type=str, |
| 84 | + help="The reason to create the reprocessing task.") |
| 85 | + |
| 86 | + return parser |
| 87 | + |
| 88 | + def take_action(self, parsed_args): |
| 89 | + return ["Result"], utils.get_client_from_osc( |
| 90 | + self).reprocessing.post_reprocessing_task( |
| 91 | + scope_ids=parsed_args.scope_id, |
| 92 | + start=parsed_args.start_reprocess_time, |
| 93 | + end=parsed_args.end_reprocess_time, |
| 94 | + reason=parsed_args.reason |
| 95 | + ) |
0 commit comments