diff --git a/CHANGELOG.D/1396.feature b/CHANGELOG.D/1396.feature new file mode 100644 index 000000000..41ef7ae87 --- /dev/null +++ b/CHANGELOG.D/1396.feature @@ -0,0 +1 @@ +Support job tags listing: `neuro job tags`. diff --git a/README.md b/README.md index 785bac273..1ac39771f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ * [neuro job submit](#neuro-job-submit) * [neuro job ls](#neuro-job-ls) * [neuro job status](#neuro-job-status) + * [neuro job tags](#neuro-job-tags) * [neuro job exec](#neuro-job-exec) * [neuro job port-forward](#neuro-job-port-forward) * [neuro job logs](#neuro-job-logs) @@ -377,6 +378,7 @@ Name | Description| | _[neuro job submit](#neuro-job-submit)_| Submit an image to run on the cluster | | _[neuro job ls](#neuro-job-ls)_| List all jobs | | _[neuro job status](#neuro-job-status)_| Display status of a job | +| _[neuro job tags](#neuro-job-tags)_| List all tags submitted by the user | | _[neuro job exec](#neuro-job-exec)_| Execute command in a running job | | _[neuro job port-forward](#neuro-job-port-forward)_| Forward port\(s) of a running job to local port\(s) | | _[neuro job logs](#neuro-job-logs)_| Print the logs for a container | @@ -518,7 +520,7 @@ neuro ps -a --owner=user-1 --owner=user-2 neuro ps --name my-experiments-v1 -s failed -s succeeded neuro ps --description=my favourite job neuro ps -s failed -s succeeded -q -neuro ps --tag tag1 -t tag2 +neuro ps -t tag1 -t tag2 ``` @@ -559,6 +561,25 @@ Name | Description| +### neuro job tags + +List all tags submitted by the user. + +**Usage:** + +```bash +neuro job tags [OPTIONS] +``` + +**Options:** + +Name | Description| +|----|------------| +|_--help_|Show this message and exit.| + + + + ### neuro job exec Execute command in a running job.
@@ -1768,7 +1789,7 @@ neuro ps -a --owner=user-1 --owner=user-2 neuro ps --name my-experiments-v1 -s failed -s succeeded neuro ps --description=my favourite job neuro ps -s failed -s succeeded -q -neuro ps --tag tag1 -t tag2 +neuro ps -t tag1 -t tag2 ``` diff --git a/docs/jobs_reference.rst b/docs/jobs_reference.rst index c22e329dc..5f3b5fbb0 100644 --- a/docs/jobs_reference.rst +++ b/docs/jobs_reference.rst @@ -156,6 +156,12 @@ Jobs :return: :class:`JobDescription` instance with job status details. + .. comethod:: tags() -> List[str] + + Get the list of all tags submitted by the user. + + :return: :class:`List[str]` list of tags. + .. comethod:: top(id: str) -> AsyncIterator[JobTelemetry] :async-for: diff --git a/neuromation/api/jobs.py b/neuromation/api/jobs.py index 91a7ca6ef..a2d4cf2b6 100644 --- a/neuromation/api/jobs.py +++ b/neuromation/api/jobs.py @@ -215,6 +215,13 @@ async def status(self, id: str) -> JobDescription: ret = await resp.json() return _job_description_from_api(ret, self._parse) + async def tags(self) -> List[str]: + url = self._config.api_url / "tags" + auth = await self._config._api_auth() + async with self._core.request("GET", url, auth=auth) as resp: + ret = await resp.json() + return ret["tags"] + async def top(self, id: str) -> AsyncIterator[JobTelemetry]: url = self._config.monitoring_url / id / "top" auth = await self._config._api_auth() diff --git a/neuromation/cli/job.py b/neuromation/cli/job.py index c020cf01f..ac4b23453 100644 --- a/neuromation/cli/job.py +++ b/neuromation/cli/job.py @@ -575,7 +575,7 @@ async def ls( neuro ps --name my-experiments-v1 -s failed -s succeeded neuro ps --description="my favourite job" neuro ps -s failed -s succeeded -q - neuro ps --tag tag1 -t tag2 + neuro ps -t tag1 -t tag2 """ format = await calc_columns(root.client, format) @@ -625,6 +625,15 @@ async def status(root: Root, job: str) -> None: click.echo(JobStatusFormatter()(res)) +@command() +async def tags(root: Root) -> None: + """ + List all tags submitted by the user. + """ + res = await root.client.jobs.tags() + pager_maybe(res, root.tty, root.terminal_size) + + @command() @click.argument("job") async def browse(root: Root, job: str) -> None: @@ -941,6 +950,7 @@ async def run( job.add_command(submit) job.add_command(ls) job.add_command(status) +job.add_command(tags) job.add_command(exec) job.add_command(port_forward) job.add_command(logs) diff --git a/tests/e2e/test_e2e_jobs.py b/tests/e2e/test_e2e_jobs.py index 13a9e16e8..4789f54e2 100644 --- a/tests/e2e/test_e2e_jobs.py +++ b/tests/e2e/test_e2e_jobs.py @@ -189,6 +189,10 @@ def test_job_tags(helper: Helper) -> None: jobs = [x.split(" ")[0] for x in store_out_list] assert job_id in jobs + captured = helper.run_cli(["job", "tags"]) + tags_listed = captured.out.split("\n") + assert set(tags) <= set(tags_listed) + @pytest.mark.e2e def test_job_kill_non_existing(helper: Helper) -> None: