Add support for sources to composer-cli
This adds the sources command which can be used to list, add, change,
and delete sources using the TOML formatted source file.
(cherry picked from commit 6f6ce410c0
)
This commit is contained in:
parent
693dc9a6f6
commit
0314cbd0e8
@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# composer-cli
|
||||
#
|
||||
@ -24,12 +23,14 @@ from composer.cli.blueprints import blueprints_cmd
|
||||
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
|
||||
|
||||
command_map = {
|
||||
"blueprints": blueprints_cmd,
|
||||
"modules": modules_cmd,
|
||||
"projects": projects_cmd,
|
||||
"compose": compose_cmd
|
||||
"compose": compose_cmd,
|
||||
"sources": sources_cmd
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,36 +24,106 @@ VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum)
|
||||
|
||||
# Documentation for the commands
|
||||
epilog = """
|
||||
compose start <blueprint> <type> Start a compose using the selected blueprint and output type.
|
||||
types List the supported output types.
|
||||
status List the status of all running and finished composes.
|
||||
log <uuid> [<size>kB] Show the last 1kB of the compose log.
|
||||
cancel <uuid> Cancel a running compose and delete any intermediate results.
|
||||
delete <uuid,...> Delete the listed compose results.
|
||||
info <uuid> Show detailed information on the compose.
|
||||
metadata <uuid> Download the metadata use to create the compose to <uuid>-metadata.tar
|
||||
logs <uuid> Download the compose logs to <uuid>-logs.tar
|
||||
results <uuid> Download all of the compose results; metadata, logs, and image to <uuid>.tar
|
||||
image <uuid> Download the output image from the compose. Filename depends on the type.
|
||||
blueprints list List the names of the available blueprints.
|
||||
show <blueprint,...> Display the blueprint in TOML format.
|
||||
changes <blueprint,...> Display the changes for each blueprint.
|
||||
diff <blueprint-name> Display the differences between 2 versions of a blueprint.
|
||||
<from-commit> Commit hash or NEWEST
|
||||
<to-commit> Commit hash, NEWEST, or WORKSPACE
|
||||
save <blueprint,...> Save the blueprint to a file, <blueprint-name>.toml
|
||||
delete <blueprint> Delete a blueprint from the server
|
||||
depsolve <blueprint,...> Display the packages needed to install the blueprint.
|
||||
push <blueprint> Push a blueprint TOML file to the server.
|
||||
freeze <blueprint,...> Display the frozen blueprint's modules and packages.
|
||||
freeze show <blueprint,...> Display the frozen blueprint in TOML format.
|
||||
freeze save <blueprint,...> Save the frozen blueprint to a file, <blueprint-name>.frozen.toml.
|
||||
tag <blueprint> Tag the most recent blueprint commit as a release.
|
||||
undo <blueprint> <commit> Undo changes to a blueprint by reverting to the selected commit.
|
||||
workspace <blueprint> Push the blueprint TOML to the temporary workspace storage.
|
||||
modules list List the available modules.
|
||||
projects list List the available projects.
|
||||
projects info <project,...> Show details about the listed projects.
|
||||
compose start <BLUEPRINT> <TYPE>
|
||||
Start a compose using the selected blueprint and output type.
|
||||
|
||||
compose types
|
||||
List the supported output types.
|
||||
|
||||
compose status
|
||||
List the status of all running and finished composes.
|
||||
|
||||
compose log <UUID> [<SIZE>]
|
||||
Show the last SIZE kB of the compose log.
|
||||
|
||||
compose cancel <UUID>
|
||||
Cancel a running compose and delete any intermediate results.
|
||||
|
||||
compose delete <UUID,...>
|
||||
Delete the listed compose results.
|
||||
|
||||
compose info <UUID>
|
||||
Show detailed information on the compose.
|
||||
|
||||
compose metadata <UUID>
|
||||
Download the metadata use to create the compose to <uuid>-metadata.tar
|
||||
|
||||
compose logs <UUID>
|
||||
Download the compose logs to <uuid>-logs.tar
|
||||
|
||||
compose results <UUID>
|
||||
Download all of the compose results; metadata, logs, and image to <uuid>.tar
|
||||
|
||||
compose image <UUID>
|
||||
Download the output image from the compose. Filename depends on the type.
|
||||
|
||||
blueprints list
|
||||
List the names of the available blueprints.
|
||||
|
||||
blueprints show <BLUEPRINT,...>
|
||||
Display the blueprint in TOML format.
|
||||
|
||||
blueprints changes <BLUEPRINT,...>
|
||||
Display the changes for each blueprint.
|
||||
|
||||
blueprints diff <BLUEPRINT> <FROM-COMMIT> <TO-COMMIT>
|
||||
Display the differences between 2 versions of a blueprint.
|
||||
FROM-COMMIT can be a commit hash or NEWEST
|
||||
TO-COMMIT can be a commit hash, NEWEST, or WORKSPACE
|
||||
|
||||
blueprints save <BLUEPRINT,...>
|
||||
Save the blueprint to a file, <BLUEPRINT>.toml
|
||||
|
||||
blueprints delete <BLUEPRINT>
|
||||
Delete a blueprint from the server
|
||||
|
||||
blueprints depsolve <BLUEPRINT,...>
|
||||
Display the packages needed to install the blueprint.
|
||||
|
||||
blueprints push <BLUEPRINT>
|
||||
Push a blueprint TOML file to the server.
|
||||
|
||||
blueprints freeze <BLUEPRINT,...>
|
||||
Display the frozen blueprint's modules and packages.
|
||||
|
||||
blueprints freeze show <BLUEPRINT,...>
|
||||
Display the frozen blueprint in TOML format.
|
||||
|
||||
blueprints freeze save <BLUEPRINT,...>
|
||||
Save the frozen blueprint to a file, <blueprint-name>.frozen.toml.
|
||||
|
||||
blueprints tag <BLUEPRINT>
|
||||
Tag the most recent blueprint commit as a release.
|
||||
|
||||
blueprints undo <BLUEPRINT> <COMMIT>
|
||||
Undo changes to a blueprint by reverting to the selected commit.
|
||||
|
||||
blueprints workspace <BLUEPRINT>
|
||||
Push the blueprint TOML to the temporary workspace storage.
|
||||
|
||||
modules list
|
||||
List the available modules.
|
||||
|
||||
projects list
|
||||
List the available projects.
|
||||
|
||||
projects info <PROJECT,...>
|
||||
Show details about the listed projects.
|
||||
|
||||
sources list
|
||||
List the available sources
|
||||
|
||||
sources info <SOURCE-NAME,...>
|
||||
Details about the source.
|
||||
|
||||
sources add <SOURCE.TOML>
|
||||
Add a package source to the server.
|
||||
|
||||
sources change <SOURCE.TOML>
|
||||
Change an existing source
|
||||
|
||||
sources delete <SOURCE-NAME>
|
||||
Delete a package source.
|
||||
"""
|
||||
|
||||
def composer_cli_parser():
|
||||
|
143
src/composer/cli/sources.py
Normal file
143
src/composer/cli/sources.py
Normal file
@ -0,0 +1,143 @@
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import logging
|
||||
log = logging.getLogger("composer-cli")
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from composer import http_client as client
|
||||
from composer.cli.utilities import argify, handle_api_result
|
||||
|
||||
def sources_cmd(opts):
|
||||
"""Process sources commands
|
||||
|
||||
:param opts: Cmdline arguments
|
||||
:type opts: argparse.Namespace
|
||||
:returns: Value to return from sys.exit()
|
||||
:rtype: int
|
||||
"""
|
||||
cmd_map = {
|
||||
"list": sources_list,
|
||||
"info": sources_info,
|
||||
"add": sources_add,
|
||||
"change": sources_add,
|
||||
"delete": sources_delete,
|
||||
}
|
||||
if opts.args[1] not in cmd_map:
|
||||
log.error("Unknown sources command: %s", opts.args[1])
|
||||
return 1
|
||||
|
||||
return cmd_map[opts.args[1]](opts.socket, opts.api_version, opts.args[2:], opts.json)
|
||||
|
||||
def sources_list(socket_path, api_version, args, show_json=False):
|
||||
"""Output the list of available sources
|
||||
|
||||
:param socket_path: Path to the Unix socket to use for API communication
|
||||
:type socket_path: str
|
||||
:param api_version: Version of the API to talk to. eg. "0"
|
||||
:type api_version: str
|
||||
:param args: List of remaining arguments from the cmdline
|
||||
:type args: list of str
|
||||
:param show_json: Set to True to show the JSON output instead of the human readable output
|
||||
:type show_json: bool
|
||||
|
||||
sources list
|
||||
"""
|
||||
api_route = client.api_url(api_version, "/projects/source/list")
|
||||
result = client.get_url_json(socket_path, api_route)
|
||||
if show_json:
|
||||
print(json.dumps(result, indent=4))
|
||||
return 0
|
||||
|
||||
print("Sources: %s" % ", ".join(result["sources"]))
|
||||
return 0
|
||||
|
||||
def sources_info(socket_path, api_version, args, show_json=False):
|
||||
"""Output info on a list of projects
|
||||
|
||||
:param socket_path: Path to the Unix socket to use for API communication
|
||||
:type socket_path: str
|
||||
:param api_version: Version of the API to talk to. eg. "0"
|
||||
:type api_version: str
|
||||
:param args: List of remaining arguments from the cmdline
|
||||
:type args: list of str
|
||||
:param show_json: Set to True to show the JSON output instead of the human readable output
|
||||
:type show_json: bool
|
||||
|
||||
sources info <source-name>
|
||||
"""
|
||||
if len(args) == 0:
|
||||
log.error("sources info is missing the name of the source")
|
||||
return 1
|
||||
|
||||
if show_json:
|
||||
api_route = client.api_url(api_version, "/projects/source/info/%s" % ",".join(args))
|
||||
result = client.get_url_json(socket_path, api_route)
|
||||
print(json.dumps(result, indent=4))
|
||||
return 0
|
||||
else:
|
||||
api_route = client.api_url(api_version, "/projects/source/info/%s?format=toml" % ",".join(args))
|
||||
result = client.get_url_raw(socket_path, api_route)
|
||||
print(result)
|
||||
return 0
|
||||
|
||||
def sources_add(socket_path, api_version, args, show_json=False):
|
||||
"""Add or change a source
|
||||
|
||||
:param socket_path: Path to the Unix socket to use for API communication
|
||||
:type socket_path: str
|
||||
:param api_version: Version of the API to talk to. eg. "0"
|
||||
:type api_version: str
|
||||
:param args: List of remaining arguments from the cmdline
|
||||
:type args: list of str
|
||||
:param show_json: Set to True to show the JSON output instead of the human readable output
|
||||
:type show_json: bool
|
||||
|
||||
sources add <source.toml>
|
||||
"""
|
||||
api_route = client.api_url(api_version, "/projects/source/new")
|
||||
rval = 0
|
||||
for source in argify(args):
|
||||
if not os.path.exists(source):
|
||||
log.error("Missing source file: %s", source)
|
||||
continue
|
||||
source_toml = open(source, "r").read()
|
||||
|
||||
result = client.post_url_toml(socket_path, api_route, source_toml)
|
||||
if handle_api_result(result, show_json):
|
||||
rval = 1
|
||||
return rval
|
||||
|
||||
def sources_delete(socket_path, api_version, args, show_json=False):
|
||||
"""Delete a source
|
||||
|
||||
:param socket_path: Path to the Unix socket to use for API communication
|
||||
:type socket_path: str
|
||||
:param api_version: Version of the API to talk to. eg. "0"
|
||||
:type api_version: str
|
||||
:param args: List of remaining arguments from the cmdline
|
||||
:type args: list of str
|
||||
:param show_json: Set to True to show the JSON output instead of the human readable output
|
||||
:type show_json: bool
|
||||
|
||||
sources delete <source-name>
|
||||
"""
|
||||
api_route = client.api_url(api_version, "/projects/source/delete/%s" % args[0])
|
||||
result = client.delete_url_json(socket_path, api_route)
|
||||
|
||||
return handle_api_result(result, show_json)
|
Loading…
Reference in New Issue
Block a user