-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add debug juju action for enabling/disabling flavor #106
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3abe337
feat: add debug juju action for enabling/disabling flavor
florentianayuwono a922775
decrease cyclop
florentianayuwono 430f2f7
fix path
florentianayuwono 9d7cd79
use container
florentianayuwono 5102d11
Apply suggestions from code review
florentianayuwono 00d918f
add env
florentianayuwono f449ef4
Merge branch 'main' into feat/debug-action-ISD-4481
florentianayuwono f80904a
Merge branch 'main' into feat/debug-action-ISD-4481
is-devops-bot 126296a
feat: update action command
florentianayuwono 81eb481
remove unused imports
florentianayuwono 55b4683
address code reviews
florentianayuwono 763cfc5
Merge branch 'main' into feat/debug-action-ISD-4481
florentianayuwono 19dff2e
add req library
florentianayuwono 2fc9ba7
Merge remote-tracking branch 'origin' into feat/debug-action-ISD-4481
florentianayuwono 46cfb0e
refactor to planner client class
florentianayuwono 4007655
address code reviews
florentianayuwono a1a8a3c
Update charms/planner-operator/src/planner.py
florentianayuwono ccb7e60
add unit tests
florentianayuwono d86e8a2
use pytest raise
florentianayuwono 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
Some comments aren't visible on the classic Files Changed page.
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
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
|
florentianayuwono marked this conversation as resolved.
|
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,127 @@ | ||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| """Planner API client.""" | ||
|
|
||
| import typing | ||
|
|
||
| import requests | ||
|
|
||
|
|
||
| class PlannerError(Exception): | ||
| """Error for planner application issues.""" | ||
|
|
||
|
|
||
| class PlannerClient: | ||
| """Client for interacting with the planner API.""" | ||
|
|
||
| def __init__(self, base_url: str, admin_token: str, timeout: int = 10) -> None: | ||
| """Initialize the planner client. | ||
|
|
||
| Args: | ||
| base_url: Base URL for the planner API. | ||
| admin_token: Admin token for authentication. | ||
| timeout: Request timeout in seconds. | ||
| """ | ||
| self._base_url = base_url.rstrip("/") | ||
| self._admin_token = admin_token | ||
| self._timeout = timeout | ||
|
|
||
| def _request( | ||
| self, | ||
| method: str, | ||
| path: str, | ||
| json_data: dict[str, typing.Any] | None = None, | ||
| ) -> requests.Response: | ||
| """Make an HTTP request to the planner API. | ||
|
|
||
| Args: | ||
| method: HTTP method (GET, POST, PATCH, DELETE). | ||
| path: API path (e.g., "/api/v1/flavors/small"). | ||
| json_data: Optional JSON payload. | ||
|
|
||
| Returns: | ||
| Response object. | ||
|
|
||
| Raises: | ||
| PlannerError: If API returns non-2xx status code. | ||
| RuntimeError: If connection fails. | ||
| """ | ||
| url = f"{self._base_url}{path}" | ||
| headers = {"Authorization": f"Bearer {self._admin_token}"} | ||
|
|
||
| try: | ||
| response = requests.request( | ||
| method=method, | ||
| url=url, | ||
| json=json_data, | ||
| headers=headers, | ||
| timeout=self._timeout, | ||
| ) | ||
| response.raise_for_status() | ||
| return response | ||
| except requests.exceptions.HTTPError as e: | ||
| error_body = e.response.text if e.response else "" | ||
| raise PlannerError( | ||
| f"HTTP error {e.response.status_code}: {error_body}" | ||
| ) from e | ||
| except requests.exceptions.RequestException as e: | ||
| raise RuntimeError(f"Connection error: {str(e)}") from e | ||
|
|
||
| def update_flavor(self, flavor_name: str, is_disabled: bool) -> None: | ||
| """Update flavor disabled status. | ||
|
|
||
| Args: | ||
| flavor_name: The name of the flavor to update. | ||
| is_disabled: Whether to disable (True) or enable (False) the flavor. | ||
|
|
||
| Raises: | ||
| PlannerError: If API returns non-2xx status code. | ||
| RuntimeError: If connection fails. | ||
| """ | ||
| self._request( | ||
| method="PATCH", | ||
| path=f"/api/v1/flavors/{flavor_name}", | ||
| json_data={"is_disabled": is_disabled}, | ||
| ) | ||
|
|
||
| def list_auth_token_names(self) -> list[str]: | ||
| """List all auth token names. | ||
|
|
||
| Returns: | ||
| List of auth token names. | ||
|
|
||
| Raises: | ||
| PlannerError: If API returns non-2xx status code. | ||
| RuntimeError: If connection fails. | ||
| """ | ||
| response = self._request(method="GET", path="/api/v1/auth/token") | ||
| return response.json()["names"] | ||
|
florentianayuwono marked this conversation as resolved.
|
||
|
|
||
| def create_auth_token(self, name: str) -> str: | ||
| """Create an auth token. | ||
|
|
||
| Args: | ||
| name: The name of the auth token. | ||
|
|
||
| Returns: | ||
| The auth token value. | ||
|
|
||
| Raises: | ||
| PlannerError: If API returns non-2xx status code. | ||
| RuntimeError: If connection fails. | ||
| """ | ||
| response = self._request(method="POST", path=f"/api/v1/auth/token/{name}") | ||
| return response.json()["token"] | ||
|
|
||
| def delete_auth_token(self, name: str) -> None: | ||
| """Delete an auth token. | ||
|
|
||
| Args: | ||
| name: The name of the auth token. | ||
|
|
||
| Raises: | ||
| PlannerError: If API returns non-2xx status code. | ||
| RuntimeError: If connection fails. | ||
| """ | ||
| self._request(method="DELETE", path=f"/api/v1/auth/token/{name}") | ||
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.