This repository was archived by the owner on Jan 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
cli: restore lease request #233
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||
| import asyncclick as click | ||||||||||
| from jumpstarter.common import MetadataFilter | ||||||||||
| from jumpstarter.config import ( | ||||||||||
| ClientConfigV1Alpha1, | ||||||||||
| UserConfigV1Alpha1, | ||||||||||
|
|
@@ -45,3 +46,42 @@ def lease_release(name, lease, all_leases): | |||||||||
| if not lease: | ||||||||||
| raise ValueError("no lease specified") | ||||||||||
| config.release_lease(lease) | ||||||||||
|
|
||||||||||
| @lease.command("request") | ||||||||||
| @click.option("-l", "--label", "labels", type=(str, str), multiple=True) | ||||||||||
| @click.argument("name", type=str, default="") | ||||||||||
| def lease_request(name, labels): | ||||||||||
| """Request an exporter lease from the jumpstarter controller. | ||||||||||
|
|
||||||||||
| The result of this command will be a lease ID that can be used to | ||||||||||
| connect to the remote exporter. | ||||||||||
|
|
||||||||||
| This is useful for multi-step workflows where you want to hold a lease | ||||||||||
| for a specific exporter while performing multiple operations, or for | ||||||||||
| CI environments where one step will request the lease and other steps | ||||||||||
| will perform operations on the leased exporter. | ||||||||||
|
|
||||||||||
| Example: | ||||||||||
|
|
||||||||||
| .. code-block:: bash | ||||||||||
|
|
||||||||||
| $ JMP_LEASE=$(jmp lease request -l label match) | ||||||||||
| $ jmp shell | ||||||||||
| $$ j --help | ||||||||||
| $$ exit | ||||||||||
| $ jmp lease release -l "${JMP_LEASE}" | ||||||||||
|
|
||||||||||
| """ | ||||||||||
| try: | ||||||||||
| if name: | ||||||||||
| config = ClientConfigV1Alpha1.load(name) | ||||||||||
| else: | ||||||||||
| config = UserConfigV1Alpha1.load_or_create().config.current_client | ||||||||||
| if not config: | ||||||||||
| raise ValueError("No client specified") | ||||||||||
| lease = config.request_lease(metadata_filter=MetadataFilter(labels=dict(labels))) | ||||||||||
| print(lease.name) | ||||||||||
| except ValueError as e: | ||||||||||
| raise click.ClickException(str(e)) from e | ||||||||||
| except Exception as e: | ||||||||||
| raise e | ||||||||||
|
Comment on lines
+86
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve exception handling. The bare - except Exception as e:
- raise e
+ except Exception as e:
+ raise click.ClickException(f"Unexpected error: {str(e)}") from e📝 Committable suggestion
Suggested change
|
||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect flag in example.
The example uses
-lflag for release command but the actual flag is--lease.📝 Committable suggestion