Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/runloop_api_client/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SnapshotOps,
BenchmarkOps,
BlueprintOps,
NetworkPolicyOps,
StorageObjectOps,
)
from .agent import Agent
Expand All @@ -27,6 +28,7 @@
AsyncSnapshotOps,
AsyncBenchmarkOps,
AsyncBlueprintOps,
AsyncNetworkPolicyOps,
AsyncStorageObjectOps,
)
from .devbox import Devbox, NamedShell
Expand All @@ -43,6 +45,7 @@
from .benchmark_run import BenchmarkRun
from .async_scenario import AsyncScenario
from .async_snapshot import AsyncSnapshot
from .network_policy import NetworkPolicy
from .storage_object import StorageObject
from .async_benchmark import AsyncBenchmark
from .async_blueprint import AsyncBlueprint
Expand All @@ -51,6 +54,7 @@
from .scenario_builder import ScenarioBuilder
from .async_scenario_run import AsyncScenarioRun
from .async_benchmark_run import AsyncBenchmarkRun
from .async_network_policy import AsyncNetworkPolicy
from .async_storage_object import AsyncStorageObject
from .async_execution_result import AsyncExecutionResult
from .async_scenario_builder import AsyncScenarioBuilder
Expand All @@ -76,6 +80,8 @@
"AsyncSnapshotOps",
"StorageObjectOps",
"AsyncStorageObjectOps",
"NetworkPolicyOps",
"AsyncNetworkPolicyOps",
# Resource classes
"Agent",
"AsyncAgent",
Expand Down Expand Up @@ -104,6 +110,8 @@
"AsyncSnapshot",
"StorageObject",
"AsyncStorageObject",
"NetworkPolicy",
"AsyncNetworkPolicy",
"NamedShell",
"AsyncNamedShell",
]
15 changes: 15 additions & 0 deletions src/runloop_api_client/sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
BenchmarkUpdateParams,
BlueprintCreateParams,
DevboxUploadFileParams,
NetworkPolicyListParams,
DevboxCreateTunnelParams,
DevboxDownloadFileParams,
DevboxRemoveTunnelParams,
DevboxSnapshotDiskParams,
NetworkPolicyCreateParams,
NetworkPolicyUpdateParams,
DevboxReadFileContentsParams,
DevboxWriteFileContentsParams,
)
Expand Down Expand Up @@ -236,3 +239,15 @@ class SDKBenchmarkListRunsParams(RunSelfListParams, BaseRequestOptions):

class SDKBenchmarkRunListScenarioRunsParams(RunListScenarioRunsParams, BaseRequestOptions):
pass


class SDKNetworkPolicyCreateParams(NetworkPolicyCreateParams, LongRequestOptions):
pass


class SDKNetworkPolicyListParams(NetworkPolicyListParams, BaseRequestOptions):
pass


class SDKNetworkPolicyUpdateParams(NetworkPolicyUpdateParams, LongRequestOptions):
pass
61 changes: 61 additions & 0 deletions src/runloop_api_client/sdk/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
SDKBenchmarkCreateParams,
SDKBlueprintCreateParams,
SDKDiskSnapshotListParams,
SDKNetworkPolicyListParams,
SDKNetworkPolicyCreateParams,
SDKDevboxCreateFromImageParams,
)
from .._types import Timeout, NotGiven, not_given
Expand All @@ -39,6 +41,7 @@
from .async_benchmark import AsyncBenchmark
from .async_blueprint import AsyncBlueprint
from ..lib.context_loader import TarFilter, build_directory_tar
from .async_network_policy import AsyncNetworkPolicy
from .async_storage_object import AsyncStorageObject
from .async_scenario_builder import AsyncScenarioBuilder
from ..types.object_create_params import ContentType
Expand Down Expand Up @@ -867,6 +870,60 @@ async def list(self, **params: Unpack[SDKBenchmarkListParams]) -> list[AsyncBenc
return [AsyncBenchmark(self._client, item.id) for item in page.benchmarks]


class AsyncNetworkPolicyOps:
"""High-level async manager for creating and managing network policies.

Accessed via ``runloop.network_policy`` from :class:`AsyncRunloopSDK`, provides
coroutines to create, retrieve, update, delete, and list network policies.

Example:
>>> runloop = AsyncRunloopSDK()
>>> policy = await runloop.network_policy.create(
... name="my-policy",
... allowed_hostnames=["github.com", "*.npmjs.org"],
... )
>>> policies = await runloop.network_policy.list()
"""

def __init__(self, client: AsyncRunloop) -> None:
"""Initialize AsyncNetworkPolicyOps.

:param client: AsyncRunloop client instance
:type client: AsyncRunloop
"""
self._client = client

async def create(self, **params: Unpack[SDKNetworkPolicyCreateParams]) -> AsyncNetworkPolicy:
"""Create a new network policy.

:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKNetworkPolicyCreateParams` for available parameters
:return: The newly created network policy
:rtype: AsyncNetworkPolicy
"""
response = await self._client.network_policies.create(**params)
return AsyncNetworkPolicy(self._client, response.id)

def from_id(self, network_policy_id: str) -> AsyncNetworkPolicy:
"""Get an AsyncNetworkPolicy instance for an existing network policy ID.

:param network_policy_id: ID of the network policy
:type network_policy_id: str
:return: AsyncNetworkPolicy instance for the given ID
:rtype: AsyncNetworkPolicy
"""
return AsyncNetworkPolicy(self._client, network_policy_id)

async def list(self, **params: Unpack[SDKNetworkPolicyListParams]) -> list[AsyncNetworkPolicy]:
"""List all network policies, optionally filtered by parameters.

:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKNetworkPolicyListParams` for available parameters
:return: List of network policies
:rtype: list[AsyncNetworkPolicy]
"""
page = self._client.network_policies.list(**params)
return [AsyncNetworkPolicy(self._client, item.id) async for item in page]


class AsyncRunloopSDK:
"""High-level asynchronous entry point for the Runloop SDK.

Expand All @@ -892,6 +949,8 @@ class AsyncRunloopSDK:
:vartype snapshot: AsyncSnapshotOps
:ivar storage_object: High-level async interface for storage object management
:vartype storage_object: AsyncStorageObjectOps
:ivar network_policy: High-level async interface for network policy management
:vartype network_policy: AsyncNetworkPolicyOps

Example:
>>> runloop = AsyncRunloopSDK() # Uses RUNLOOP_API_KEY env var
Expand All @@ -906,6 +965,7 @@ class AsyncRunloopSDK:
benchmark: AsyncBenchmarkOps
devbox: AsyncDevboxOps
blueprint: AsyncBlueprintOps
network_policy: AsyncNetworkPolicyOps
scenario: AsyncScenarioOps
scorer: AsyncScorerOps
snapshot: AsyncSnapshotOps
Expand Down Expand Up @@ -953,6 +1013,7 @@ def __init__(
self.benchmark = AsyncBenchmarkOps(self.api)
self.devbox = AsyncDevboxOps(self.api)
self.blueprint = AsyncBlueprintOps(self.api)
self.network_policy = AsyncNetworkPolicyOps(self.api)
self.scenario = AsyncScenarioOps(self.api)
self.scorer = AsyncScorerOps(self.api)
self.snapshot = AsyncSnapshotOps(self.api)
Expand Down
80 changes: 80 additions & 0 deletions src/runloop_api_client/sdk/async_network_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""NetworkPolicy resource class for asynchronous operations."""

from __future__ import annotations

from typing_extensions import Unpack, override

from ._types import BaseRequestOptions, LongRequestOptions, SDKNetworkPolicyUpdateParams
from .._client import AsyncRunloop
from ..types.network_policy_view import NetworkPolicyView


class AsyncNetworkPolicy:
"""Asynchronous wrapper around a network policy resource."""

def __init__(
self,
client: AsyncRunloop,
network_policy_id: str,
) -> None:
"""Initialize the wrapper.

:param client: Generated AsyncRunloop client
:type client: AsyncRunloop
:param network_policy_id: NetworkPolicy ID returned by the API
:type network_policy_id: str
"""
self._client = client
self._id = network_policy_id

@override
def __repr__(self) -> str:
return f"<AsyncNetworkPolicy id={self._id!r}>"

@property
def id(self) -> str:
"""Return the network policy ID.

:return: Unique network policy ID
:rtype: str
"""
return self._id

async def get_info(
self,
**options: Unpack[BaseRequestOptions],
) -> NetworkPolicyView:
"""Retrieve the latest network policy details.

:param options: Optional request configuration
:return: API response describing the network policy
:rtype: NetworkPolicyView
"""
return await self._client.network_policies.retrieve(
self._id,
**options,
)

async def update(self, **params: Unpack[SDKNetworkPolicyUpdateParams]) -> NetworkPolicyView:
"""Update the network policy.

:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKNetworkPolicyUpdateParams` for available parameters
:return: Updated network policy view
:rtype: NetworkPolicyView
"""
return await self._client.network_policies.update(self._id, **params)

async def delete(
self,
**options: Unpack[LongRequestOptions],
) -> NetworkPolicyView:
"""Delete the network policy.

:param options: Optional long-running request configuration
:return: API response acknowledging deletion
:rtype: NetworkPolicyView
"""
return await self._client.network_policies.delete(
self._id,
**options,
)
4 changes: 1 addition & 3 deletions src/runloop_api_client/sdk/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,5 @@ def list_runs(
**params,
)
return [
BenchmarkRun(self._client, run.id, run.benchmark_id)
for run in page.runs
if run.benchmark_id is not None
BenchmarkRun(self._client, run.id, run.benchmark_id) for run in page.runs if run.benchmark_id is not None
]
80 changes: 80 additions & 0 deletions src/runloop_api_client/sdk/network_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""NetworkPolicy resource class for synchronous operations."""

from __future__ import annotations

from typing_extensions import Unpack, override

from ._types import BaseRequestOptions, LongRequestOptions, SDKNetworkPolicyUpdateParams
from .._client import Runloop
from ..types.network_policy_view import NetworkPolicyView


class NetworkPolicy:
"""Synchronous wrapper around a network policy resource."""

def __init__(
self,
client: Runloop,
network_policy_id: str,
) -> None:
"""Initialize the wrapper.

:param client: Generated Runloop client
:type client: Runloop
:param network_policy_id: NetworkPolicy ID returned by the API
:type network_policy_id: str
"""
self._client = client
self._id = network_policy_id

@override
def __repr__(self) -> str:
return f"<NetworkPolicy id={self._id!r}>"

@property
def id(self) -> str:
"""Return the network policy ID.

:return: Unique network policy ID
:rtype: str
"""
return self._id

def get_info(
self,
**options: Unpack[BaseRequestOptions],
) -> NetworkPolicyView:
"""Retrieve the latest network policy details.

:param options: Optional request configuration
:return: API response describing the network policy
:rtype: NetworkPolicyView
"""
return self._client.network_policies.retrieve(
self._id,
**options,
)

def update(self, **params: Unpack[SDKNetworkPolicyUpdateParams]) -> NetworkPolicyView:
"""Update the network policy.

:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKNetworkPolicyUpdateParams` for available parameters
:return: Updated network policy view
:rtype: NetworkPolicyView
"""
return self._client.network_policies.update(self._id, **params)

def delete(
self,
**options: Unpack[LongRequestOptions],
) -> NetworkPolicyView:
"""Delete the network policy.

:param options: Optional long-running request configuration
:return: API response acknowledging deletion
:rtype: NetworkPolicyView
"""
return self._client.network_policies.delete(
self._id,
**options,
)
Loading
Loading