Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
33 changes: 32 additions & 1 deletion src/blaxel/core/client/models/sandbox_fork_request.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any, TypeVar, Union
from typing import TYPE_CHECKING, Any, TypeVar, Union

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
from ..models.env import Env


T = TypeVar("T", bound="SandboxForkRequest")


Expand All @@ -17,6 +21,9 @@ class SandboxForkRequest:
target_name (str): Name of the target application to create or update Example: my-app.
target_type (str): Target resource type to fork into Example: application.
custom_domain (Union[Unset, str]): Custom domain for the application
envs (Union[Unset, list['Env']]): Environment variables the fork runs with, on top of the ones the source has. A
variable the source already carries takes this value in the fork, one it does not is added, and every other
variable of the source is kept.
port (Union[Unset, int]): Port to expose from the sandbox Example: 8080.
prefix (Union[Unset, str]): URL prefix for the application
snapshot_id (Union[Unset, str]): Snapshot ID to fork from. When set, the application revision references this
Expand All @@ -28,19 +35,31 @@ class SandboxForkRequest:
target_name: str
target_type: str
custom_domain: Union[Unset, str] = UNSET
envs: Union[Unset, list["Env"]] = UNSET
port: Union[Unset, int] = UNSET
prefix: Union[Unset, str] = UNSET
snapshot_id: Union[Unset, str] = UNSET
traffic: Union[Unset, int] = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> dict[str, Any]:

target_name = self.target_name

target_type = self.target_type

custom_domain = self.custom_domain

envs: Union[Unset, list[dict[str, Any]]] = UNSET
if not isinstance(self.envs, Unset):
envs = []
for envs_item_data in self.envs:
if type(envs_item_data) is dict:
envs_item = envs_item_data
else:
envs_item = envs_item_data.to_dict()
envs.append(envs_item)

port = self.port

prefix = self.prefix
Expand All @@ -59,6 +78,8 @@ def to_dict(self) -> dict[str, Any]:
)
if custom_domain is not UNSET:
field_dict["customDomain"] = custom_domain
if envs is not UNSET:
field_dict["envs"] = envs
if port is not UNSET:
field_dict["port"] = port
if prefix is not UNSET:
Expand All @@ -72,6 +93,8 @@ def to_dict(self) -> dict[str, Any]:

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T | None:
from ..models.env import Env

if not src_dict:
return None
d = src_dict.copy()
Expand All @@ -81,6 +104,13 @@ def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T | None:

custom_domain = d.pop("customDomain", d.pop("custom_domain", UNSET))

envs = []
_envs = d.pop("envs", UNSET)
for envs_item_data in _envs or []:
envs_item = Env.from_dict(envs_item_data)

envs.append(envs_item)

port = d.pop("port", UNSET)

prefix = d.pop("prefix", UNSET)
Expand All @@ -93,6 +123,7 @@ def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T | None:
target_name=target_name,
target_type=target_type,
custom_domain=custom_domain,
envs=envs,
port=port,
prefix=prefix,
snapshot_id=snapshot_id,
Expand Down
8 changes: 8 additions & 0 deletions src/blaxel/core/sandbox/default/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ...client.api.compute.update_sandbox import asyncio as update_sandbox
from ...client.client import client
from ...client.models import (
Env,
Metadata,
MetadataLabels,
Sandbox,
Expand Down Expand Up @@ -430,6 +431,7 @@ async def fork(
custom_domain: str | None = None,
prefix: str | None = None,
snapshot_id: str | None = None,
envs: list[Env] | None = None,
) -> SandboxForkResponse:
"""Fork this sandbox into a new sandbox or application.

Expand All @@ -444,6 +446,10 @@ async def fork(
custom_domain: Custom domain for an application fork.
prefix: URL prefix for an application fork.
snapshot_id: Snapshot ID to fork from.
envs: Environment variables the fork runs with, on top of the ones
the source has: a variable the source already carries takes this
value in the fork, one it does not is added, and every other
variable of the source is kept.
"""
body = SandboxForkRequest(target_name=target_name, target_type=target_type)
if port is not None:
Expand All @@ -456,6 +462,8 @@ async def fork(
body.prefix = prefix
if snapshot_id is not None:
body.snapshot_id = snapshot_id
if envs is not None:
body.envs = envs
response = await fork_sandbox(
self.metadata.name,
client=client,
Expand Down
8 changes: 8 additions & 0 deletions src/blaxel/core/sandbox/sync/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ...client.api.compute.update_sandbox import sync as update_sandbox
from ...client.client import client
from ...client.models import (
Env,
Metadata,
Sandbox,
SandboxForkRequest,
Expand Down Expand Up @@ -328,6 +329,7 @@ def fork(
custom_domain: str | None = None,
prefix: str | None = None,
snapshot_id: str | None = None,
envs: list[Env] | None = None,
) -> SandboxForkResponse:
"""Fork this sandbox into a new sandbox or application.

Expand All @@ -342,6 +344,10 @@ def fork(
custom_domain: Custom domain for an application fork.
prefix: URL prefix for an application fork.
snapshot_id: Snapshot ID to fork from.
envs: Environment variables the fork runs with, on top of the ones
the source has: a variable the source already carries takes this
value in the fork, one it does not is added, and every other
variable of the source is kept.
"""
body = SandboxForkRequest(target_name=target_name, target_type=target_type)
if port is not None:
Expand All @@ -354,6 +360,8 @@ def fork(
body.prefix = prefix
if snapshot_id is not None:
body.snapshot_id = snapshot_id
if envs is not None:
body.envs = envs
response = fork_sandbox(
self.metadata.name,
client=client,
Expand Down
Loading