-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add job ls command * Add tests for job ls command * Remove optional --namespace flag from 'job ls' command * Assert job list output * Minor changes * Update README file * Remove 'Slurm' term from descriptions * Minor changes
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from ..utils.console import xpk_exit, xpk_print | ||
from ..core.core import add_zone_and_project | ||
from ..core.app_profile import APP_PROFILE_TEMPLATE_DEFAULT_NAME | ||
from ..core.commands import ( | ||
run_command_with_updates, | ||
) | ||
|
||
|
||
def job_list(args) -> None: | ||
"""Function around job list. | ||
Args: | ||
args: user provided arguments for running the command. | ||
Returns: | ||
None | ||
""" | ||
add_zone_and_project(args) | ||
xpk_print( | ||
f'Listing jobs for project {args.project} and zone {args.zone}:', | ||
flush=True, | ||
) | ||
|
||
if run_slurm_job_list_command(args): | ||
xpk_exit(1) | ||
xpk_exit(0) | ||
|
||
|
||
def run_slurm_job_list_command(args) -> None: | ||
cmd = ( | ||
f'kubectl-kjob list slurm --profile {APP_PROFILE_TEMPLATE_DEFAULT_NAME}' | ||
) | ||
|
||
return_code = run_command_with_updates(cmd, 'list slurm jobs', args) | ||
if return_code != 0: | ||
xpk_print(f'Listing jobs returned ERROR {return_code}') | ||
xpk_exit(return_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from .common import add_shared_arguments | ||
from ..commands.job import job_list | ||
|
||
|
||
def set_job_parser(job_parser): | ||
job_subcommands = job_parser.add_subparsers( | ||
title='job subcommands', | ||
dest='xpk_job_subcommands', | ||
help=( | ||
'These are commands related to job management. Look at help for' | ||
' specific subcommands for more details.' | ||
), | ||
) | ||
|
||
### "job ls" command parser ### | ||
job_list_parser = job_subcommands.add_parser('ls', help='List jobs.') | ||
|
||
add_shared_arguments(job_list_parser) | ||
job_list_parser.set_defaults(func=job_list) |