Merge pull request #97 from mesosphere/dcos-package-list-installed
DCOS package list-installed command extensions
This commit is contained in:
@@ -6,7 +6,7 @@ Usage:
|
||||
dcos package info
|
||||
dcos package install [--options=<options_file> --app-id=<app_id>]
|
||||
<package_name>
|
||||
dcos package list-installed
|
||||
dcos package list-installed [--endpoints --app-id=<app-id> <package_name>]
|
||||
dcos package search <query>
|
||||
dcos package sources
|
||||
dcos package uninstall [--all | --app-id=<app-id>] <package_name>
|
||||
@@ -99,7 +99,7 @@ def _cmds():
|
||||
|
||||
cmds.Command(
|
||||
hierarchy=['package', 'list-installed'],
|
||||
arg_keys=[],
|
||||
arg_keys=['--endpoints', '--app-id', '<package_name>'],
|
||||
function=_list),
|
||||
|
||||
cmds.Command(
|
||||
@@ -202,7 +202,7 @@ def _update():
|
||||
def _describe(package_name):
|
||||
"""Describe the specified package.
|
||||
|
||||
:param package_name: The package to configure
|
||||
:param package_name: The package to describe
|
||||
:type package_name: str
|
||||
:returns: Process status
|
||||
:rtype: int
|
||||
@@ -230,12 +230,6 @@ def _describe(package_name):
|
||||
|
||||
version_map, version_error = pkg.software_versions()
|
||||
|
||||
if version_error is not None:
|
||||
emitter.publish(version_error)
|
||||
return 1
|
||||
|
||||
version_map, version_error = pkg.software_versions()
|
||||
|
||||
if version_error is not None:
|
||||
emitter.publish(version_error)
|
||||
return 1
|
||||
@@ -304,9 +298,16 @@ def _install(package_name, options_file, app_id):
|
||||
return 0
|
||||
|
||||
|
||||
def _list():
|
||||
"""Describe the specified package.
|
||||
def _list(endpoints, app_id, package_name):
|
||||
"""Show installed apps
|
||||
|
||||
:param endpoints: Whether to include a list of
|
||||
endpoints as port-host pairs
|
||||
:type endpoints: boolean
|
||||
:param package_name: The package to show
|
||||
:type package_name: str
|
||||
:param app_id: App ID of app to show
|
||||
:type app_id: str
|
||||
:returns: Process status
|
||||
:rtype: int
|
||||
"""
|
||||
@@ -314,12 +315,26 @@ def _list():
|
||||
config = _load_config()
|
||||
|
||||
init_client = marathon.create_client(config)
|
||||
installed, error = package.list_installed_packages(init_client)
|
||||
|
||||
def keep(pkg):
|
||||
if package_name and pkg.get('name', '') != package_name:
|
||||
return False
|
||||
if app_id and pkg.get('appId', '') != app_id:
|
||||
return False
|
||||
return True
|
||||
|
||||
installed, error = package.list_installed_packages(init_client, keep)
|
||||
|
||||
if error is not None:
|
||||
emitter.publish(error)
|
||||
return 1
|
||||
|
||||
if endpoints:
|
||||
installed, error = package.get_tasks_multiple(init_client, installed)
|
||||
if error is not None:
|
||||
emitter.publish(error)
|
||||
return 1
|
||||
|
||||
emitter.publish(installed)
|
||||
|
||||
return 0
|
||||
|
||||
@@ -17,7 +17,7 @@ Usage:
|
||||
dcos package info
|
||||
dcos package install [--options=<options_file> --app-id=<app_id>]
|
||||
<package_name>
|
||||
dcos package list-installed
|
||||
dcos package list-installed [--endpoints --app-id=<app-id> <package_name>]
|
||||
dcos package search <query>
|
||||
dcos package sources
|
||||
dcos package uninstall [--all | --app-id=<app-id>] <package_name>
|
||||
@@ -256,6 +256,20 @@ def test_list_installed():
|
||||
assert stdout == b'[]\n'
|
||||
assert stderr == b''
|
||||
|
||||
returncode, stdout, stderr = exec_command(
|
||||
['dcos', 'package', 'list-installed', 'xyzzy'])
|
||||
|
||||
assert returncode == 0
|
||||
assert stdout == b'[]\n'
|
||||
assert stderr == b''
|
||||
|
||||
returncode, stdout, stderr = exec_command(
|
||||
['dcos', 'package', 'list-installed', '--app-id=/xyzzy'])
|
||||
|
||||
assert returncode == 0
|
||||
assert stdout == b'[]\n'
|
||||
assert stderr == b''
|
||||
|
||||
returncode, stdout, stderr = exec_command(
|
||||
['dcos',
|
||||
'package',
|
||||
@@ -267,12 +281,7 @@ def test_list_installed():
|
||||
assert stdout == b''
|
||||
assert stderr == b''
|
||||
|
||||
returncode, stdout, stderr = exec_command(['dcos',
|
||||
'package',
|
||||
'list-installed'])
|
||||
|
||||
assert returncode == 0
|
||||
assert stdout == b"""\
|
||||
expected_output = b"""\
|
||||
[
|
||||
{
|
||||
"appId": "/mesos-dns",
|
||||
@@ -293,7 +302,26 @@ further setup requirements: http://mesosphere.github.io/mesos-dns/docs\
|
||||
}
|
||||
]
|
||||
"""
|
||||
returncode, stdout, stderr = exec_command(
|
||||
['dcos', 'package', 'list-installed'])
|
||||
|
||||
assert returncode == 0
|
||||
assert stderr == b''
|
||||
assert stdout == expected_output
|
||||
|
||||
returncode, stdout, stderr = exec_command(
|
||||
['dcos', 'package', 'list-installed', 'mesos-dns'])
|
||||
|
||||
assert returncode == 0
|
||||
assert stderr == b''
|
||||
assert stdout == expected_output
|
||||
|
||||
returncode, stdout, stderr = exec_command(
|
||||
['dcos', 'package', 'list-installed', '--app-id=/mesos-dns'])
|
||||
|
||||
assert returncode == 0
|
||||
assert stderr == b''
|
||||
assert stdout == expected_output
|
||||
|
||||
|
||||
def test_search():
|
||||
|
||||
@@ -246,6 +246,25 @@ def list_installed_packages(init_client, result_predicate=lambda x: True):
|
||||
return (pkgs, None)
|
||||
|
||||
|
||||
def get_tasks_multiple(init_client, apps):
|
||||
"""Adds tasks to app dictionary
|
||||
:param init_client: The program to use to list packages
|
||||
:type init_client: object
|
||||
:param apps: list of dict
|
||||
:type apps: object
|
||||
:rtype: (list, Error)
|
||||
"""
|
||||
|
||||
for app in apps:
|
||||
tasks, err = init_client.get_tasks(app["appId"])
|
||||
if err is not None:
|
||||
return (None, err)
|
||||
app["endpoints"] = [{"host": t["host"], "ports": t["ports"]}
|
||||
for t in tasks]
|
||||
|
||||
return (apps, None)
|
||||
|
||||
|
||||
def search(query, cfg):
|
||||
"""Returns a list of index entry collections, one for each registry in
|
||||
the supplied config.
|
||||
|
||||
Reference in New Issue
Block a user