Skip to content

Commit

Permalink
Marathon list ID only Mode (#1080)
Browse files Browse the repository at this point in the history
* adding quiet mode to match job functionality to get list of ids

* quiet should be false by default
  • Loading branch information
kensipe authored and klueska committed Nov 2, 2017
1 parent b4ae348 commit 409175c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
10 changes: 6 additions & 4 deletions cli/dcoscli/data/help/marathon.txt
Expand Up @@ -8,7 +8,7 @@ Usage:
dcos marathon --version
dcos marathon about
dcos marathon app add [<app-resource>]
dcos marathon app list [--json]
dcos marathon app list [--json|--quiet]
dcos marathon app remove [--force] <app-id>
dcos marathon app restart [--force] <app-id>
dcos marathon app show [--app-version=<app-version>] <app-id>
Expand All @@ -17,7 +17,7 @@ Usage:
dcos marathon app kill [--scale] [--host=<host>] <app-id>
dcos marathon app update [--force] <app-id> [<properties>...]
dcos marathon app version list [--max-count=<max-count>] <app-id>
dcos marathon deployment list [--json <app-id>]
dcos marathon deployment list [--json|--quiet] [<app-id>]
dcos marathon deployment rollback <deployment-id>
dcos marathon deployment stop <deployment-id>
dcos marathon deployment watch [--max-count=<max-count>]
Expand All @@ -34,14 +34,14 @@ Usage:
dcos marathon plugin list [--json]
dcos marathon pod add [<pod-resource>]
dcos marathon pod kill <pod-id> [<instance-ids>...]
dcos marathon pod list [--json]
dcos marathon pod list [--json|--quiet]
dcos marathon pod remove [--force] <pod-id>
dcos marathon pod show <pod-id>
dcos marathon pod update [--force] <pod-id>
dcos marathon debug list [--json]
dcos marathon debug summary <app-id> [--json]
dcos marathon debug details <app-id> [--json]
dcos marathon task list [--json <app-id>]
dcos marathon task list [--json|--quiet] [<app-id>]
dcos marathon task stop [--wipe] <task-id>
dcos marathon task kill [--scale] [--wipe] [--json] [<task-ids>...]
dcos marathon task show <task-id>
Expand Down Expand Up @@ -146,6 +146,8 @@ Options:
Print JSON-formatted data.
--max-count=<max-count>
Maximum number of entries to fetch and return.
-q, --quiet
Display IDs only for list.
--scale
Scale the app down after performing the the operation.
--version
Expand Down
47 changes: 32 additions & 15 deletions cli/dcoscli/marathon/main.py
Expand Up @@ -54,7 +54,7 @@ def _cmds():

cmds.Command(
hierarchy=['marathon', 'deployment', 'list'],
arg_keys=['<app-id>', '--json'],
arg_keys=['<app-id>', '--json', '--quiet'],
function=subcommand.deployment_list),

cmds.Command(
Expand All @@ -74,7 +74,7 @@ def _cmds():

cmds.Command(
hierarchy=['marathon', 'task', 'list'],
arg_keys=['<app-id>', '--json'],
arg_keys=['<app-id>', '--json', '--quiet'],
function=subcommand.task_list),

cmds.Command(
Expand All @@ -99,7 +99,7 @@ def _cmds():

cmds.Command(
hierarchy=['marathon', 'app', 'list'],
arg_keys=['--json'],
arg_keys=['--json', '--quiet'],
function=subcommand.list),

cmds.Command(
Expand Down Expand Up @@ -194,7 +194,7 @@ def _cmds():

cmds.Command(
hierarchy=['marathon', 'pod', 'list'],
arg_keys=['--json'],
arg_keys=['--json', '--quiet'],
function=subcommand.pod_list),

cmds.Command(
Expand Down Expand Up @@ -426,7 +426,7 @@ def add(self, app_resource):

return 0

def list(self, json_):
def list(self, json_, quiet_=False):
"""
:param json_: output json if True
:type json_: bool
Expand All @@ -437,7 +437,10 @@ def list(self, json_):
client = self._create_marathon_client()
apps = client.get_apps()

if json_:
if quiet_:
for app in apps:
emitter.publish(app.get('id'))
elif json_:
emitter.publish(apps)
else:
deployments = client.get_deployments()
Expand Down Expand Up @@ -851,7 +854,7 @@ def version_list(self, app_id, max_count):
emitter.publish(versions)
return 0

def deployment_list(self, app_id, json_):
def deployment_list(self, app_id, json_, quiet_=False):
"""
:param app_id: the application id
:type app_id: str
Expand All @@ -871,10 +874,14 @@ def deployment_list(self, app_id, json_):
msg += " for '{}'".format(app_id)
raise DCOSException(msg)

emitting.publish_table(emitter,
deployments,
tables.deployment_table,
json_)
if quiet_:
for deployment in deployments:
emitter.publish(deployment.get('id'))
else:
emitting.publish_table(emitter,
deployments,
tables.deployment_table,
json_)
return 0

def deployment_stop(self, deployment_id):
Expand Down Expand Up @@ -943,7 +950,7 @@ def deployment_watch(self, deployment_id, max_count, interval):

return 0

def task_list(self, app_id, json_):
def task_list(self, app_id, json_, quiet_=False):
"""
:param app_id: the id of the application
:type app_id: str
Expand All @@ -956,7 +963,12 @@ def task_list(self, app_id, json_):
client = self._create_marathon_client()
tasks = client.get_tasks(app_id)

emitting.publish_table(emitter, tasks, tables.app_task_table, json_)
if quiet_:
for task in tasks:
emitter.publish(task.get('id'))
else:
emitting.publish_table(emitter, tasks,
tables.app_task_table, json_)
return 0

def task_stop(self, task_id, wipe):
Expand Down Expand Up @@ -1071,7 +1083,7 @@ def pod_remove(self, pod_id, force):
marathon_client.remove_pod(pod_id, force)
return 0

def pod_list(self, json_):
def pod_list(self, json_, quiet_=False):
"""
:param json_: output JSON if true
:type json_: bool
Expand All @@ -1085,7 +1097,12 @@ def pod_list(self, json_):
pods = marathon_client.list_pod()
queued_apps = marathon_client.get_queued_apps()
_enhance_row_with_overdue_information(pods, queued_apps)
emitting.publish_table(emitter, pods, tables.pod_table, json_)

if quiet_:
for pod in pods:
emitter.publish(pod.get('id'))
else:
emitting.publish_table(emitter, pods, tables.pod_table, json_)
return 0

def pod_show(self, pod_id):
Expand Down

0 comments on commit 409175c

Please sign in to comment.