feat: add tool catalog and installation endpoints with models for tool management
This commit is contained in:
@@ -22,6 +22,7 @@ from ..api_models import (
|
||||
from ..app import Application
|
||||
from ..domain import PortRule, VmRecord, VmSpec
|
||||
from ..errors import ValidationError
|
||||
from ..tool_catalog import normalize_tools
|
||||
from ..validation import (
|
||||
parse_cpu,
|
||||
parse_name,
|
||||
@@ -33,6 +34,7 @@ from ..validation import (
|
||||
parse_username,
|
||||
)
|
||||
from .dependencies import get_authorized_application
|
||||
from .tools import tool_service
|
||||
|
||||
|
||||
router = APIRouter(prefix="/vms", tags=["vms"])
|
||||
@@ -73,6 +75,9 @@ def create_vm(
|
||||
ports = parse_ports([f"{rule.port}:{rule.protocol}" for rule in request.ports or ()])
|
||||
if not request.no_default_ports and not any(rule.port == 22 for rule in ports):
|
||||
ports = tuple(sorted((*ports, PortRule(22)), key=lambda rule: rule.port))
|
||||
tools = normalize_tools([item.model_dump() for item in request.tools], allow_empty=True)
|
||||
if tools:
|
||||
tool_service(application).start()
|
||||
vm = application.lifecycle.create(
|
||||
VmSpec(
|
||||
cpu=parse_cpu(str(request.cpu)),
|
||||
@@ -83,8 +88,11 @@ def create_vm(
|
||||
password=parse_password(request.password.get_secret_value()),
|
||||
name=parse_name(request.name) if request.name is not None else None,
|
||||
ports=ports,
|
||||
tools=tools,
|
||||
)
|
||||
)
|
||||
if tools:
|
||||
tool_service(application).notify()
|
||||
return vm_response(vm, policy_status=_mutation_policy_status(vm))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user