Skip to content
Merged
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
5 changes: 4 additions & 1 deletion aenv/src/aenv/client/scheduler_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ async def create_env_instance(
ttl: str = "",
environment_variables: Optional[Dict[str, str]] = None,
arguments: Optional[List[str]] = None,
owner: Optional[str] = None,
) -> EnvInstance:
"""
Create a new environment instance.
Expand All @@ -119,6 +120,7 @@ async def create_env_instance(
environment_variables: Optional environment variables
arguments: Optional arguments
ttl: Time to live for instance
owner: Optional owner of the instance
Returns:
Created EnvInstance

Expand All @@ -130,14 +132,15 @@ async def create_env_instance(
raise NetworkError("Client not connected")

logger.info(
f"Creating environment instance: {name}, datasource: {datasource}, ttl: {ttl}, environment_variables: {environment_variables}, arguments: {arguments}, url: {self.base_url}"
f"Creating environment instance: {name}, datasource: {datasource}, ttl: {ttl}, environment_variables: {environment_variables}, arguments: {arguments}, owner: {owner}, url: {self.base_url}"
)
request = EnvInstanceCreateRequest(
envName=name,
datasource=datasource,
environment_variables=environment_variables,
arguments=arguments,
ttl=ttl,
owner=owner,
)

for attempt in range(self.max_retries + 1):
Expand Down
39 changes: 37 additions & 2 deletions aenv/src/aenv/core/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os
import traceback
from datetime import datetime, timezone
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Tuple
from urllib.parse import urlparse, urlunparse

import httpx
Expand Down Expand Up @@ -58,6 +58,28 @@ def make_mcp_url(aenv_url: str, port: str, path: str = "") -> str:
return urlunparse(new)


def split_env_name_version(env_name: str) -> Tuple[str, str]:
"""
Split environment name into name and version.

Args:
env_name: Environment name in format "name@version" or just "name"

Returns:
Tuple of (name, version). If no @ symbol, version is empty string.
"""
if not env_name:
return "", ""

parts = env_name.split("@", 1)
if len(parts) == 1:
# No @ symbol, use entire string as name
return parts[0], ""
else:
# Has @ symbol, first part as name, second part as version
return parts[0], parts[1]


class ToolResult:
"""Result of a tool execution."""

Expand Down Expand Up @@ -94,6 +116,7 @@ def __init__(
max_retries: int = 10,
api_key: Optional[str] = None,
skip_for_healthy: bool = False,
owner: Optional[str] = None,
):
"""
Initialize environment.
Expand All @@ -117,6 +140,7 @@ def __init__(
self.arguments = arguments or []
self.dummy_instance_ip = os.getenv("DUMMY_INSTANCE_IP")
self.skip_for_healthy = skip_for_healthy
self.owner = owner

if not aenv_url:
aenv_url = self.dummy_instance_ip or os.getenv(
Expand Down Expand Up @@ -788,12 +812,23 @@ async def _create_env_instance(self):
f"{self._log_prefix()} Creating environment instance: {self.env_name}"
)
try:
# Parse env_name to extract name and version
env_name_parsed, env_version_parsed = split_env_name_version(self.env_name)

# Inject system environment variables envNAME and envversion
env_vars = (
dict(self.environment_variables) if self.environment_variables else {}
)
env_vars["envNAME"] = env_name_parsed
env_vars["envversion"] = env_version_parsed

self._instance = await self._client.create_env_instance(
name=self.env_name,
datasource=self.datasource,
environment_variables=self.environment_variables,
environment_variables=env_vars,
arguments=self.arguments,
ttl=self.ttl,
owner=self.owner,
)
logger.info(
f"{self._log_prefix()} Environment instance created with ID: {self._instance.id}"
Expand Down
1 change: 1 addition & 0 deletions aenv/src/aenv/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class EnvInstanceCreateRequest(BaseModel):
Field(None, description="Environment variables"),
)
arguments: Optional[List[str]] = (Field(None, description="Startup arguments"),)
owner: Optional[str] = Field(None, description="Instance owner")


class EnvInstanceListResponse(BaseModel):
Expand Down
14 changes: 13 additions & 1 deletion aenv/src/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@

import click

from cli.cmds import build, config, get, init, instances, list, push, run, version
from cli.cmds import (
build,
config,
get,
init,
instance,
instances,
list,
push,
run,
version,
)
from cli.cmds.common import Config, global_error_handler, pass_config


Expand Down Expand Up @@ -44,6 +55,7 @@ def cli(cfg: Config, debug: bool, verbose: bool):
cli.add_command(build)
cli.add_command(config)
cli.add_command(instances)
cli.add_command(instance)

if __name__ == "__main__":
cli()
2 changes: 2 additions & 0 deletions aenv/src/cli/cmds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from cli.cmds.config import config
from cli.cmds.get import get
from cli.cmds.init import init
from cli.cmds.instance import instance
from cli.cmds.instances import instances
from cli.cmds.list import list_env as list
from cli.cmds.push import push
Expand All @@ -38,4 +39,5 @@
"build",
"config",
"instances",
"instance",
]
Loading
Loading