-
Notifications
You must be signed in to change notification settings - Fork 9
PythonTFE : Agents agentpools #31
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
Changes from 3 commits
39f4247
b654fd6
e02c0ad
532d0c1
61c1c83
21ead28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| """Agent and Agent Pool models for the Python TFE SDK. | ||
|
|
||
| This module contains Pydantic models for Terraform Enterprise/Cloud agents and agent pools, | ||
| including all necessary option classes for CRUD operations. | ||
|
|
||
| Based on the Go TFE implementation: | ||
| https://github.com/hashicorp/go-tfe/blob/main/agent.go | ||
| https://github.com/hashicorp/go-tfe/blob/main/agent_pool.go | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime | ||
| from enum import Enum | ||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
|
|
||
| class AgentStatus(str, Enum): | ||
| """Agent status enumeration.""" | ||
|
|
||
| IDLE = "idle" | ||
| BUSY = "busy" | ||
| UNKNOWN = "unknown" | ||
|
|
||
|
|
||
| class AgentPoolAllowedWorkspacePolicy(str, Enum): | ||
| """Agent pool allowed workspace policy enumeration.""" | ||
|
|
||
| ALL_WORKSPACES = "all-workspaces" | ||
| SPECIFIC_WORKSPACES = "specific-workspaces" | ||
|
|
||
|
|
||
| class Agent(BaseModel): | ||
| """Agent represents a Terraform Enterprise agent.""" | ||
|
|
||
| id: str | ||
| name: str | None = None | ||
| status: AgentStatus | None = None | ||
| version: str | None = None | ||
| last_ping_at: datetime | None = None | ||
| ip_address: str | None = None | ||
|
|
||
| # Relations | ||
| agent_pool: AgentPool | None = None | ||
|
|
||
|
|
||
| class AgentPool(BaseModel): | ||
| """Agent Pool represents a Terraform Enterprise agent pool.""" | ||
|
|
||
| id: str | ||
| name: str | None = None | ||
| created_at: datetime | None = None | ||
| organization_scoped: bool | None = None | ||
| allowed_workspace_policy: AgentPoolAllowedWorkspacePolicy | None = None | ||
| agent_count: int = 0 | ||
|
|
||
| # Relations | ||
| organization: Any | None = None # Organization type from main types | ||
| workspaces: list[Any] = Field(default_factory=list) # Workspace types | ||
| agents: list[Agent] = Field(default_factory=list) | ||
|
|
||
|
|
||
| # Agent Pool Options | ||
|
|
||
|
|
||
| class AgentPoolListOptions(BaseModel): | ||
| """Options for listing agent pools.""" | ||
|
|
||
| # Pagination options | ||
| page_number: int | None = None | ||
| page_size: int | None = None | ||
| # Optional: Include related resources | ||
| include: list[str] | None = None | ||
| # Optional: Filter by allowed workspace policy | ||
| allowed_workspace_policy: AgentPoolAllowedWorkspacePolicy | None = None | ||
|
|
||
|
|
||
| class AgentPoolCreateOptions(BaseModel): | ||
| """Options for creating an agent pool.""" | ||
|
|
||
| # Required: A name to identify the agent pool | ||
| name: str | ||
| # Optional: Whether the agent pool is organization scoped | ||
| organization_scoped: bool | None = None | ||
| # Optional: Allowed workspace policy | ||
| allowed_workspace_policy: AgentPoolAllowedWorkspacePolicy | None = None | ||
|
|
||
|
|
||
| class AgentPoolUpdateOptions(BaseModel): | ||
| """Options for updating an agent pool.""" | ||
|
|
||
| # Optional: A name to identify the agent pool | ||
| name: str | None = None | ||
| # Optional: Whether the agent pool is organization scoped | ||
| organization_scoped: bool | None = None | ||
| # Optional: Allowed workspace policy | ||
| allowed_workspace_policy: AgentPoolAllowedWorkspacePolicy | None = None | ||
|
|
||
|
|
||
| class AgentPoolReadOptions(BaseModel): | ||
| """Options for reading an agent pool.""" | ||
|
|
||
| # Optional: Include related resources | ||
| include: list[str] | None = None | ||
|
|
||
|
|
||
| # Agent Pool Workspace Assignment Options | ||
|
|
||
|
|
||
| class AgentPoolAssignToWorkspacesOptions(BaseModel): | ||
| """Options for assigning an agent pool to workspaces.""" | ||
|
|
||
| workspace_ids: list[str] = Field(default_factory=list) | ||
|
|
||
|
|
||
| class AgentPoolRemoveFromWorkspacesOptions(BaseModel): | ||
| """Options for removing an agent pool from workspaces.""" | ||
|
|
||
| workspace_ids: list[str] = Field(default_factory=list) | ||
|
|
||
|
|
||
| # Agent Options | ||
|
|
||
|
|
||
| class AgentListOptions(BaseModel): | ||
| """Options for listing agents.""" | ||
|
|
||
| # Pagination options | ||
| page_number: int | None = None | ||
| page_size: int | None = None | ||
| # Optional: Filter by status | ||
| status: AgentStatus | None = None | ||
|
|
||
|
|
||
| class AgentReadOptions(BaseModel): | ||
| """Options for reading an agent.""" | ||
|
|
||
| # Optional: Include related resources | ||
| include: list[str] | None = None | ||
|
|
||
|
|
||
| # Agent Token Options | ||
|
|
||
|
|
||
| class AgentTokenCreateOptions(BaseModel): | ||
| """Options for creating an agent token.""" | ||
|
|
||
| # Required: A description for the token | ||
| description: str | ||
|
|
||
|
|
||
| class AgentToken(BaseModel): | ||
| """Agent Token represents an authentication token for agents.""" | ||
|
|
||
| id: str | ||
| description: str | None = None | ||
| created_at: datetime | None = None | ||
| last_used_at: datetime | None = None | ||
| token: str | None = None # Only returned on creation | ||
|
|
||
| # Relations | ||
| agent_pool: AgentPool | None = None | ||
|
|
||
|
|
||
| class AgentTokenListOptions(BaseModel): | ||
| """Options for listing agent tokens.""" | ||
|
|
||
| # Pagination options | ||
| page_number: int | None = None | ||
| page_size: int | None = None | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| """Legacy Agent Pool model - DEPRECATED. | ||
|
Member
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. we don't need backward compatibility right now. This package is still under internal development. As we have moved to agent.py, please update run_task to inherit from new model file. |
||
|
|
||
| This file is kept for backward compatibility. | ||
| Please use src/tfe/models/agent.py for new agent and agent pool models. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| # Re-export from the new agent module | ||
|
|
||
|
|
||
| class AgentPool(BaseModel): | ||
| """Legacy Agent Pool model - use agent.AgentPool instead.""" | ||
|
|
||
| id: str | ||
|
|
||
| def __init_subclass__(cls, **kwargs: Any) -> None: | ||
| import warnings | ||
|
|
||
| warnings.warn( | ||
| "AgentPool from agentpool.py is deprecated. Use agent.AgentPool instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| super().__init_subclass__(**kwargs) | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| from pydantic import BaseModel, Field | ||
|
|
||
| from ..types import Pagination | ||
| from .agentpool import AgentPool | ||
| from .agent_pool import AgentPool | ||
|
Member
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. why not just use model/agent.py here ?
Contributor
Author
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. resolved |
||
| from .organization import Organization | ||
| from .workspace_run_task import WorkspaceRunTask | ||
|
|
||
|
|
||
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.
Remove these lines of go-tfe ref
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.
resolved