
This is a foundation for CLI work, still has rough spots but works for two PoC commands - rack-list and rack-show (communicates with Tuskar, prints). There's remaining stuff to be solved: * Allow arbitrary formatting of attributes (bug #1213056) * Add help support for subcommands (bug #1213050) * Allow finding resources by name (bug #1213053) * Allow auth with pre-existing token and Keystone URL (bug #1213052) Fixes bug #1211826 Change-Id: I9364be37c7111c85ef46be82b157782a14743004
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from tuskarclient.common import utils
|
|
from tuskarclient import exc
|
|
|
|
|
|
# TODO(jistr): This is PoC, not final implementation
|
|
@utils.arg('id', metavar="<NAME or ID>", help="Name or ID of rack to show.")
|
|
def do_rack_show(tuskar, args):
|
|
try:
|
|
rack = utils.find_resource(tuskar.racks, args.id)
|
|
except exc.HTTPNotFound:
|
|
raise exc.CommandError("Rack not found: %s" % args.id)
|
|
|
|
utils.print_dict(rack.to_dict())
|
|
|
|
|
|
# TODO(jistr): This is PoC, not final implementation
|
|
def do_rack_list(tuskar, args):
|
|
racks = tuskar.racks.list()
|
|
fields = ['name', 'subnet', 'state', 'nodes']
|
|
labels = ["Name", "Subnet", "State", "Nodes"]
|
|
formatters = {'nodes': lambda rack: len(rack.nodes)}
|
|
|
|
utils.print_list(racks, fields, labels, formatters, 0)
|