|
| 1 | +# Copyright 2013 Nebula Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +# |
| 15 | + |
| 16 | +"""Container v1 action implementations""" |
| 17 | + |
| 18 | + |
| 19 | +import logging |
| 20 | + |
| 21 | +from cliff import lister |
| 22 | + |
| 23 | +from openstackclient.common import utils |
| 24 | +from openstackclient.object.v1.lib import container as lib_container |
| 25 | + |
| 26 | + |
| 27 | +class ListContainer(lister.Lister): |
| 28 | + """List containers""" |
| 29 | + |
| 30 | + log = logging.getLogger(__name__ + '.ListContainer') |
| 31 | + |
| 32 | + def get_parser(self, prog_name): |
| 33 | + parser = super(ListContainer, self).get_parser(prog_name) |
| 34 | + parser.add_argument( |
| 35 | + "--prefix", |
| 36 | + metavar="<prefix>", |
| 37 | + help="Filter list using <prefix>", |
| 38 | + ) |
| 39 | + parser.add_argument( |
| 40 | + "--marker", |
| 41 | + metavar="<marker>", |
| 42 | + help="Anchor for paging", |
| 43 | + ) |
| 44 | + parser.add_argument( |
| 45 | + "--end-marker", |
| 46 | + metavar="<end-marker>", |
| 47 | + help="End anchor for paging", |
| 48 | + ) |
| 49 | + parser.add_argument( |
| 50 | + "--limit", |
| 51 | + metavar="<limit>", |
| 52 | + type=int, |
| 53 | + help="Limit the number of containers returned", |
| 54 | + ) |
| 55 | + parser.add_argument( |
| 56 | + '--long', |
| 57 | + action='store_true', |
| 58 | + default=False, |
| 59 | + help='List additional fields in output', |
| 60 | + ) |
| 61 | + parser.add_argument( |
| 62 | + '--all', |
| 63 | + action='store_true', |
| 64 | + default=False, |
| 65 | + help='List all containers (default is 10000)', |
| 66 | + ) |
| 67 | + return parser |
| 68 | + |
| 69 | + def take_action(self, parsed_args): |
| 70 | + self.log.debug('take_action(%s)' % parsed_args) |
| 71 | + |
| 72 | + if parsed_args.long: |
| 73 | + columns = ('Name', 'Bytes', 'Count') |
| 74 | + else: |
| 75 | + columns = ('Name',) |
| 76 | + |
| 77 | + kwargs = {} |
| 78 | + if parsed_args.prefix: |
| 79 | + kwargs['prefix'] = parsed_args.prefix |
| 80 | + if parsed_args.marker: |
| 81 | + kwargs['marker'] = parsed_args.marker |
| 82 | + if parsed_args.end_marker: |
| 83 | + kwargs['end_marker'] = parsed_args.end_marker |
| 84 | + if parsed_args.limit: |
| 85 | + kwargs['limit'] = parsed_args.limit |
| 86 | + if parsed_args.all: |
| 87 | + kwargs['full_listing'] = True |
| 88 | + |
| 89 | + data = lib_container.list_containers( |
| 90 | + self.app.restapi, |
| 91 | + self.app.client_manager.object.endpoint, |
| 92 | + **kwargs |
| 93 | + ) |
| 94 | + #print "data: %s" % data |
| 95 | + |
| 96 | + return (columns, |
| 97 | + (utils.get_dict_properties( |
| 98 | + s, columns, |
| 99 | + formatters={}, |
| 100 | + ) for s in data)) |
0 commit comments