From c6efcd1fc216559710e082ae9dbf728916c1c253 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Mon, 23 Jul 2018 14:00:46 -0400 Subject: [PATCH] Add the beginnings of a new status subcommand. (cherry picked from commit 9eafc60fa08a1a5c6f7b6d63650aba499e29a125) --- src/composer/cli/__init__.py | 4 +++- src/composer/cli/help.py | 6 ++++- src/composer/cli/status.py | 45 ++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/composer/cli/status.py diff --git a/src/composer/cli/__init__.py b/src/composer/cli/__init__.py index eab53828..7e399252 100644 --- a/src/composer/cli/__init__.py +++ b/src/composer/cli/__init__.py @@ -24,13 +24,15 @@ from composer.cli.modules import modules_cmd from composer.cli.projects import projects_cmd from composer.cli.compose import compose_cmd from composer.cli.sources import sources_cmd +from composer.cli.status import status_cmd command_map = { "blueprints": blueprints_cmd, "modules": modules_cmd, "projects": projects_cmd, "compose": compose_cmd, - "sources": sources_cmd + "sources": sources_cmd, + "status": status_cmd } diff --git a/src/composer/cli/help.py b/src/composer/cli/help.py index 03e9adb9..1f34dcdf 100644 --- a/src/composer/cli/help.py +++ b/src/composer/cli/help.py @@ -126,4 +126,8 @@ sources delete Delete a package source. """ -epilog = compose_help + blueprints_help + modules_help + projects_help + sources_help +status_help = """ +status show Show API server status. +""" + +epilog = compose_help + blueprints_help + modules_help + projects_help + sources_help + status_help diff --git a/src/composer/cli/status.py b/src/composer/cli/status.py new file mode 100644 index 00000000..b74e6237 --- /dev/null +++ b/src/composer/cli/status.py @@ -0,0 +1,45 @@ +# +# Copyright (C) 2018 Red Hat, Inc. +# +# 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 the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +import logging +log = logging.getLogger("composer-cli") + +import json + +from composer import http_client as client +from composer.cli.help import status_help + +def status_cmd(opts): + """Process status commands + + :param opts: Cmdline arguments + :type opts: argparse.Namespace + :returns: Value to return from sys.exit() + :rtype: int + """ + if opts.args[1] == "help" or opts.args[1] == "--help": + print(status_help) + return 0 + elif opts.args[1] != "show": + log.error("Unknown status command: %s", opts.args[1]) + return 1 + + result = client.get_url_json(opts.socket, "/api/status") + if opts.json: + print(json.dumps(result, indent=4)) + return 0 + + return 0