diff --git a/avocado/restclient/cli/actions/server.py b/avocado/restclient/cli/actions/server.py new file mode 100644 index 0000000000000000000000000000000000000000..73be3753d6c7b81af10b78d0bc5ac481935a5e18 --- /dev/null +++ b/avocado/restclient/cli/actions/server.py @@ -0,0 +1,40 @@ +# Copyright: Red Hat Inc. 2015 +# Author: Cleber Rosa + +""" +Module that implements the actions for the CLI App when the job toplevel +command is used +""" + +from avocado.restclient import connection +from avocado.restclient.cli.actions import base + + +@base.action +def status(app): + """ + Shows the server status + """ + data = app.connection.request("version/") + app.view.notify(event="message", + msg="Server version: %s" % data.get('version')) + + +@base.action +def list_brief(app): + """ + Shows the server API list + """ + try: + data = app.connection.get_api_list() + except connection.UnexpectedHttpStatusCode, e: + if e.received == 403: + app.view.notify(event="error", + msg="Error: Access Forbidden") + return False + + app.view.notify(event="message", + msg="Available APIs:") + for name in data: + app.view.notify(event="message", + msg=" * %s" % name) diff --git a/avocado/restclient/cli/args/server.py b/avocado/restclient/cli/args/server.py new file mode 100644 index 0000000000000000000000000000000000000000..8f371433a176366bcad5c1182b7927e8fe15e60d --- /dev/null +++ b/avocado/restclient/cli/args/server.py @@ -0,0 +1,42 @@ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# See LICENSE for more details. +# +# Copyright: Red Hat Inc. 2015 +# Author: Cleber Rosa + +""" +This module has actions for the server command +""" + +from avocado.restclient.cli.args import base + + +__all__ = ['ACTION_STATUS', 'ACTION_ARGUMENTS', 'ARGUMENTS'] + + +# +# Arguments that are treated as actions +# +ACTION_STATUS = (('-s', '--status',), + {'help': 'shows the avocado-server status', + 'action': 'store_true', + 'default': False}) + +# +# Arguments that are treated as actions +# +ACTION_ARGUMENTS = [base.LIST_BRIEF, + ACTION_STATUS] + +# +# Other arguments that will influence action behaviour +# +ARGUMENTS = [] diff --git a/man/avocado-rest-client.rst b/man/avocado-rest-client.rst index 87804e0f179abefdd8bf360f1d3ca4b3799c8337..f4623714b8330624f021f305c4f7958a3998dc0b 100644 --- a/man/avocado-rest-client.rst +++ b/man/avocado-rest-client.rst @@ -36,6 +36,18 @@ on them being loaded:: --username USERNAME Username to authenticate to avocado server --password PASSWORD Password to give to avocado server +Real use of avocado depends on running avocado subcommands. This the current list +of subcommands:: + + server inspects the server status and available functionality + +To get usage instructions for a given subcommand, run it with `--help`. Example:: + + $ avocado-rest-client server --help + + -l, --list-brief list all records briefly + -s, --status shows the avocado-server status + FILES =====