Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marathon list ID only Mode #1080

Merged
merged 2 commits into from Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -31,14 +31,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 @@ -143,6 +143,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 @@ -52,7 +52,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 @@ -72,7 +72,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 @@ -97,7 +97,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 @@ -177,7 +177,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 @@ -409,7 +409,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 @@ -420,7 +420,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 @@ -760,7 +763,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 @@ -780,10 +783,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 @@ -852,7 +859,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 @@ -865,7 +872,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 @@ -980,7 +992,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 @@ -994,7 +1006,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