Skip to content

Commit

Permalink
Merge pull request #32 from Stackmasters/implement-setups-destroy
Browse files Browse the repository at this point in the history
feat: add destroy option in setups command
  • Loading branch information
parath authored Jun 13, 2024
2 parents 9a1347e + 8ddd00a commit 2ef60b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cycleops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def deploy(self, setup_id: int) -> Optional[Dict[str, Any]]:
jobs_client: JobClient = JobClient(cycleops_client)
return jobs_client.create(description=description, type=type, setup=setup_id)

def destroy(self, setup_id: int) -> Optional[Dict[str, Any]]:
description: str = f"Destroying setup: {setup_id}"
type: str = "Destruction"

jobs_client = JobClient(cycleops_client)
return jobs_client.create(description=description, type=type, setup=setup_id)


class UnitClient(SubClient):
"""
Expand Down
20 changes: 20 additions & 0 deletions cycleops/setups.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ def deploy(
return


@app.command()
def destroy(
setup_identifier: str = typer.Argument(
..., help="The ID or name of the setup. Names take precedence."
),
) -> None:
"""
Deploy the setup with the specified given ID or name.
"""

try:
setup = get_setup(setup_identifier)
setup_client.destroy(setup["id"])

display_success_message(f"Setup {setup['id']} has been queued for destruction")
except Exception as error:
display_error_message(error)
raise typer.Abort()


def get_setup(setup_identifier: str) -> Optional[Dict[str, Any]]:
"""
Retrieves a Setup with either a name or ID. Names take precedence.
Expand Down

0 comments on commit 2ef60b6

Please sign in to comment.