|
19 | 19 | import logging |
20 | 20 | import six |
21 | 21 |
|
| 22 | +from cliff import command |
22 | 23 | from cliff import lister |
23 | 24 | from cliff import show |
24 | 25 |
|
25 | 26 | from openstackclient.common import utils |
26 | 27 | from openstackclient.object.v1.lib import object as lib_object |
27 | 28 |
|
28 | 29 |
|
| 30 | +class CreateObject(show.ShowOne): |
| 31 | + """Upload an object to a container""" |
| 32 | + |
| 33 | + log = logging.getLogger(__name__ + '.CreateObject') |
| 34 | + |
| 35 | + def get_parser(self, prog_name): |
| 36 | + parser = super(CreateObject, self).get_parser(prog_name) |
| 37 | + parser.add_argument( |
| 38 | + 'container', |
| 39 | + metavar='<container>', |
| 40 | + help='Container to store new object', |
| 41 | + ) |
| 42 | + parser.add_argument( |
| 43 | + 'object', |
| 44 | + metavar='<object-name>', |
| 45 | + help='Local path of object to upload', |
| 46 | + ) |
| 47 | + return parser |
| 48 | + |
| 49 | + def take_action(self, parsed_args): |
| 50 | + self.log.debug('take_action(%s)', parsed_args) |
| 51 | + |
| 52 | + data = lib_object.create_object( |
| 53 | + self.app.restapi, |
| 54 | + self.app.client_manager.object_store.endpoint, |
| 55 | + parsed_args.container, |
| 56 | + parsed_args.object, |
| 57 | + ) |
| 58 | + |
| 59 | + return zip(*sorted(six.iteritems(data))) |
| 60 | + |
| 61 | + |
| 62 | +class DeleteObject(command.Command): |
| 63 | + """Delete an object within a container""" |
| 64 | + |
| 65 | + log = logging.getLogger(__name__ + '.DeleteObject') |
| 66 | + |
| 67 | + def get_parser(self, prog_name): |
| 68 | + parser = super(DeleteObject, self).get_parser(prog_name) |
| 69 | + parser.add_argument( |
| 70 | + 'container', |
| 71 | + metavar='<container>', |
| 72 | + help='Container that stores the object to delete', |
| 73 | + ) |
| 74 | + parser.add_argument( |
| 75 | + 'object', |
| 76 | + metavar='<object-name>', |
| 77 | + help='Object to delete', |
| 78 | + ) |
| 79 | + return parser |
| 80 | + |
| 81 | + def take_action(self, parsed_args): |
| 82 | + self.log.debug('take_action(%s)', parsed_args) |
| 83 | + |
| 84 | + lib_object.delete_object( |
| 85 | + self.app.restapi, |
| 86 | + self.app.client_manager.object_store.endpoint, |
| 87 | + parsed_args.container, |
| 88 | + parsed_args.object, |
| 89 | + ) |
| 90 | + |
| 91 | + |
29 | 92 | class ListObject(lister.Lister): |
30 | 93 | """List objects""" |
31 | 94 |
|
|
0 commit comments