handle dcos task commands when no task is given (#796)

This commit is contained in:
tamarrow
2016-10-07 15:08:22 -07:00
committed by GitHub
parent 8d7b4f02be
commit 43aa7f7b3b
2 changed files with 20 additions and 17 deletions

View File

@@ -86,9 +86,6 @@ def _task(task, completed, json_):
:returns: process return code
"""
if task is None:
task = ""
tasks = sorted(mesos.get_master().tasks(completed=completed, fltr=task),
key=lambda t: t['name'])
@@ -120,10 +117,7 @@ def _log(follow, completed, lines, task, file_):
:rtype: int
"""
if task is None:
fltr = ""
else:
fltr = task
fltr = task
if file_ is None:
file_ = 'stdout'
@@ -138,7 +132,9 @@ def _log(follow, completed, lines, task, file_):
tasks = master.tasks(completed=completed, fltr=fltr)
if not tasks:
if not completed:
if not fltr:
raise DCOSException("No tasks found. Exiting.")
elif not completed:
completed_tasks = master.tasks(completed=True, fltr=fltr)
if completed_tasks:
msg = 'No running tasks match ID [{}]; however, there '.format(
@@ -154,6 +150,10 @@ def _log(follow, completed, lines, task, file_):
mesos_files = _mesos_files(tasks, file_, client)
if not mesos_files:
if fltr is None:
msg = "No tasks found. Exiting"
else:
msg = "No matching tasks. Exiting."
raise DCOSException('No matching tasks. Exiting.')
log.log_files(mesos_files, follow, lines)
@@ -176,8 +176,6 @@ def _ls(task, path, long_, completed):
:rtype: int
"""
if task is None:
task = ""
if path is None:
path = '.'
if path.startswith('/'):
@@ -189,8 +187,11 @@ def _ls(task, path, long_, completed):
completed=completed)
if len(task_objects) == 0:
raise DCOSException(
'Cannot find a task with ID containing "{}"'.format(task))
if task is None:
raise DCOSException("No tasks found")
else:
raise DCOSException(
'Cannot find a task with ID containing "{}"'.format(task))
try:
all_files = []

View File

@@ -415,12 +415,12 @@ class Master(object):
for slave in self.state()['slaves']
if fltr in slave['id']]
def tasks(self, fltr="", completed=False):
def tasks(self, fltr=None, completed=False):
"""Returns tasks running under the master
:param fltr: May be a substring or regex. Only return tasks
whose 'id' matches `fltr`.
:type fltr: str
:param fltr: May be None, a substring or regex. None returns all tasks,
else return tasks whose 'id' matches `fltr`.
:type fltr: str | None
:param completed: also include completed tasks
:type completed: bool
:returns: a list of tasks
@@ -434,7 +434,9 @@ class Master(object):
tasks = []
for framework in self._framework_dicts(completed, completed):
for task in _merge(framework, keys):
if fltr in task['id'] or fnmatch.fnmatchcase(task['id'], fltr):
if fltr is None or \
fltr in task['id'] or \
fnmatch.fnmatchcase(task['id'], fltr):
task = self._framework_obj(framework).task(task['id'])
tasks.append(task)