-
Notifications
You must be signed in to change notification settings - Fork 1
Add beta cluster remediation CLI commands #369
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
Open
blainekasten
wants to merge
13
commits into
next
Choose a base branch
from
blaine/tcl-6313-add-node-remediation-apis-to-sdk-and-cli
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
60e73b7
feat(api): add cluster config/OIDC/add-ons params, project filtering,…
stainless-app[bot] 0d83e7e
fix(types): correct status field to enum in cluster_storage model
stainless-app[bot] 0e48b36
feat(api): add h200-140gb gpu_type to jig deploy/update methods
stainless-app[bot] da57778
fix(api): make duration_days optional in clusters create, size_tib op…
stainless-app[bot] f8b715c
feat: Sync deployments OpenAPI spec
stainless-app[bot] d1b00a5
docs(api): add parameter descriptions to storage methods and types
stainless-app[bot] 5af43e9
feat(api): Add node remediation APIs to clusters sdks
stainless-app[bot] 98e83aa
feat(api): manual updates
stainless-app[bot] e6a7c37
fix(api): remove trigger parameter from remediations list method
stainless-app[bot] 598dbd0
feat(api): manual updates
stainless-app[bot] c5f5a6d
codegen metadata
stainless-app[bot] 5047a5c
Add beta cluster remediation CLI commands
cursoragent 362807a
add remediation retrieve command and some fixes
blainekasten 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,4 @@ | ||
| configured_endpoints: 75 | ||
| openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai/togetherai-5f05c9669c67c3f4b0ebfe2317d2768cd96317424965ebb2acf06a7757a7d0ca.yml | ||
| openapi_spec_hash: 84f45151f4d0eed68551b5ffda61595a | ||
| config_hash: ec427df08d61d8888138f15cd53c6454 | ||
| configured_endpoints: 81 | ||
| openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai/togetherai-3ae47a93fc03893f34b2e442ab8194c1f4224d9d7fe2d02b6342dbe03862f1e7.yml | ||
| openapi_spec_hash: 2544f6840cf7ad23eae3fe8bffed4c4b | ||
| config_hash: b35d5968fb07cce1c1be735f874898b1 |
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
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
33 changes: 33 additions & 0 deletions
33
src/together/lib/cli/api/beta/clusters/remediations/_resolve_remediation.py
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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
|
|
||
| from together import omit | ||
| from together._types import Omit | ||
| from together.lib.cli.utils.config import CLIConfigParameter | ||
| from together.lib.cli.utils._console import console | ||
| from together.types.beta.clusters.remediation import Remediation | ||
|
|
||
|
|
||
| async def resolve_remediation(config: CLIConfigParameter, remediation_id: str) -> Remediation: | ||
| clusters = await config.client.beta.clusters.list() | ||
|
|
||
| for cluster in clusters.clusters: | ||
| page_token: str | Omit = omit | ||
| while True: | ||
| response = await config.client.beta.clusters.remediations.list( | ||
| "-", | ||
| cluster_id=cluster.cluster_id, | ||
| page_size=100, | ||
| page_token=page_token, | ||
| ) | ||
| for remediation in response.remediations: | ||
| if remediation.id == remediation_id: | ||
| return remediation | ||
|
|
||
| if not response.has_next or not response.next_page_token: | ||
| break | ||
| page_token = response.next_page_token | ||
|
|
||
| console.print(f"[red]Error:[/red] Remediation not found: {remediation_id}") | ||
| sys.exit(1) |
37 changes: 37 additions & 0 deletions
37
src/together/lib/cli/api/beta/clusters/remediations/approve.py
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional, Annotated | ||
|
|
||
| from cyclopts import Parameter | ||
|
|
||
| from together import omit | ||
| from together._utils._json import openapi_dumps | ||
| from together.lib.cli.utils.config import CLIConfigParameter | ||
| from together.lib.cli.utils._console import console | ||
| from together.lib.cli.components.loader import show_loading_status | ||
| from together.lib.cli.api.beta.clusters.remediations._resolve_remediation import resolve_remediation | ||
|
|
||
|
|
||
| async def approve( | ||
| remediation_id: str, | ||
| comment: Annotated[Optional[str], Parameter(help="Comment explaining the approval")] = None, | ||
| *, | ||
| config: CLIConfigParameter, | ||
| ) -> None: | ||
| """Approve a pending remediation.""" | ||
| remediation = await show_loading_status("Finding remediation...", resolve_remediation(config, remediation_id)) | ||
| response = await show_loading_status( | ||
| "Approving remediation...", | ||
| config.client.beta.clusters.remediations.approve( | ||
| remediation_id, | ||
| cluster_id=remediation.cluster_id, | ||
| instance_id=remediation.instance_id, | ||
| comment=comment or omit, | ||
| ), | ||
| ) | ||
|
|
||
| if config.json: | ||
| console.print_json(openapi_dumps(response).decode("utf-8")) | ||
| return | ||
|
|
||
| console.print(f"[blue]Remediation approved.[/blue] ({response.id})") |
30 changes: 30 additions & 0 deletions
30
src/together/lib/cli/api/beta/clusters/remediations/cancel.py
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from together._utils._json import openapi_dumps | ||
| from together.lib.cli.utils.config import CLIConfigParameter | ||
| from together.lib.cli.utils._console import console | ||
| from together.lib.cli.components.loader import show_loading_status | ||
| from together.lib.cli.api.beta.clusters.remediations._resolve_remediation import resolve_remediation | ||
|
|
||
|
|
||
| async def cancel( | ||
| remediation_id: str, | ||
| *, | ||
| config: CLIConfigParameter, | ||
| ) -> None: | ||
| """Cancel a pending remediation.""" | ||
| remediation = await show_loading_status("Finding remediation...", resolve_remediation(config, remediation_id)) | ||
| response = await show_loading_status( | ||
| "Cancelling remediation...", | ||
| config.client.beta.clusters.remediations.cancel( | ||
| remediation_id, | ||
| cluster_id=remediation.cluster_id, | ||
| instance_id=remediation.instance_id, | ||
| ), | ||
| ) | ||
|
|
||
| if config.json: | ||
| console.print_json(openapi_dumps(response).decode("utf-8")) | ||
| return | ||
|
|
||
| console.print(f"[blue]Remediation cancelled.[/blue] ({response.id})") |
62 changes: 62 additions & 0 deletions
62
src/together/lib/cli/api/beta/clusters/remediations/create.py
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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Literal, Optional, Annotated, cast | ||
|
|
||
| from cyclopts import Parameter | ||
|
|
||
| from together import omit | ||
| from together._utils._json import openapi_dumps | ||
| from together.lib.cli.utils.config import CLIConfigParameter | ||
| from together.lib.cli.utils._console import console | ||
| from together.lib.cli.components.loader import show_loading_status | ||
|
|
||
| RemediationModeParameter = Annotated[ | ||
| Literal[ | ||
| "VM_ONLY", | ||
| "HOST_AWARE", | ||
| "EVICT_WITHOUT_REPLACEMENT", | ||
| "REBOOT_VM", | ||
| ], | ||
| Parameter(help="The type of remediation to perform"), | ||
| ] | ||
|
|
||
|
|
||
| async def create( | ||
| cluster_id: Annotated[str, Parameter(help="The ID of the cluster")], | ||
| instance_id: Annotated[str, Parameter(help="The ID of the node within the cluster to remediate")], | ||
| *, | ||
| mode: RemediationModeParameter, | ||
| remediation_id: Annotated[Optional[str], Parameter(help="Client-specified ID for idempotency")] = None, | ||
| reason: Annotated[Optional[str], Parameter(help="Reason for the remediation")] = None, | ||
| config: CLIConfigParameter, | ||
| ) -> None: | ||
| """Create a node remediation for an instance.""" | ||
| safe_mode = cast( | ||
| Literal[ | ||
| "REMEDIATION_MODE_VM_ONLY", | ||
| "REMEDIATION_MODE_HOST_AWARE", | ||
| "REMEDIATION_MODE_EVICT_WITHOUT_REPLACEMENT", | ||
| "REMEDIATION_MODE_REBOOT_VM", | ||
| ], | ||
| f"REMEDIATION_MODE_{mode}", | ||
| ) | ||
|
|
||
| response = await show_loading_status( | ||
| "Creating remediation...", | ||
| config.client.beta.clusters.remediations.create( | ||
| instance_id, | ||
| cluster_id=cluster_id, | ||
| mode=safe_mode, | ||
| remediation_id=remediation_id or omit, | ||
| reason=reason or omit, | ||
| ), | ||
| ) | ||
|
|
||
| if config.json: | ||
| console.print_json(openapi_dumps(response).decode("utf-8")) | ||
| return | ||
|
|
||
| console.print(f"[green]√ Remediation created[/green] [dim]({response.id})[/dim]") | ||
| console.print(f" Remediations may take some time to complete.\n") | ||
| console.print(f" To retrieve the status:") | ||
| console.print(f" [dim]-[/dim] [primary]tg beta clusters remediations {response.id}[/primary]") | ||
73 changes: 73 additions & 0 deletions
73
src/together/lib/cli/api/beta/clusters/remediations/list.py
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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional, Annotated | ||
|
|
||
| from cyclopts import Parameter | ||
|
|
||
| from together import omit | ||
| from together._utils._json import openapi_dumps | ||
| from together.lib.utils.tools import format_datetime | ||
| from together.lib.cli.utils.config import CLIConfigParameter | ||
| from together.lib.cli.utils._console import console | ||
| from together.lib.cli.components.list import ListTable | ||
| from together.lib.cli.components.loader import show_loading_status | ||
|
|
||
|
|
||
| async def list( | ||
| cluster_id: str, | ||
| instance_id: Annotated[Optional[str], Parameter(help="Instance ID to list remediations for")] = None, | ||
| after: Annotated[Optional[str], Parameter(help="Pagination token from a previous request")] = None, | ||
| *, | ||
| config: CLIConfigParameter, | ||
| ) -> None: | ||
| """List node remediations for a cluster or instance.""" | ||
| response = await show_loading_status( | ||
| "Loading remediations...", | ||
| config.client.beta.clusters.remediations.list( | ||
| instance_id or "-", | ||
| cluster_id=cluster_id, | ||
| page_token=after or omit, | ||
| ), | ||
| ) | ||
|
|
||
| if config.json: | ||
| console.print_json(openapi_dumps(response).decode("utf-8")) | ||
| return | ||
|
|
||
| table = ListTable(title="Cluster Remediations", empty_message="No remediations found for this cluster.") | ||
| table.add_column("Created") | ||
| table.add_primary_column("Instance", ratio=3) | ||
| table.add_column("Mode") | ||
| table.add_column("State") | ||
| table.add_column("Remediation ID", ratio=3) | ||
|
|
||
| for remediation in response.remediations: | ||
| table.add_row( | ||
| format_datetime(remediation.create_time) if remediation.create_time else "-", | ||
| remediation.instance_id, | ||
| remediation.mode.replace("REMEDIATION_MODE_", ""), | ||
| _colorize(remediation.state), | ||
| remediation.id, | ||
| ) | ||
|
|
||
| console.print(table) | ||
| if response.has_next and response.next_page_token: | ||
| command = f"tg beta clusters remediations ls {cluster_id}" | ||
| if instance_id: | ||
| command += f" {instance_id}" | ||
| console.print("\n[blue dim]To display the next page, run:[/blue dim]") | ||
| console.print(f" [dim]-[/dim] [white]{command} --after {response.next_page_token}[/white]") | ||
|
|
||
|
|
||
| def _colorize(state: str) -> str: | ||
| state_colors = { | ||
| "PENDING_APPROVAL": "yellow", | ||
| "PENDING": "yellow", | ||
| "RUNNING": "yellow", | ||
| "SUCCEEDED": "green", | ||
| "FAILED": "red", | ||
| "CANCELLED": "dim", | ||
| "AUTO_RESOLVED": "green", | ||
| } | ||
| color = state_colors[state] if state in state_colors else "white" | ||
| return f"[{color}]{state}[/{color}]" |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.