Update README.md
This commit is contained in:
1
app/schemas/__init__.py
Normal file
1
app/schemas/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# Import schemas
|
BIN
app/schemas/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
app/schemas/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
app/schemas/__pycache__/claude_api.cpython-313.pyc
Normal file
BIN
app/schemas/__pycache__/claude_api.cpython-313.pyc
Normal file
Binary file not shown.
BIN
app/schemas/__pycache__/config.cpython-313.pyc
Normal file
BIN
app/schemas/__pycache__/config.cpython-313.pyc
Normal file
Binary file not shown.
BIN
app/schemas/__pycache__/job.cpython-313.pyc
Normal file
BIN
app/schemas/__pycache__/job.cpython-313.pyc
Normal file
Binary file not shown.
78
app/schemas/claude_api.py
Normal file
78
app/schemas/claude_api.py
Normal file
@ -0,0 +1,78 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Dict, Any, List, Optional, Union
|
||||
|
||||
|
||||
class ClaudeJobRequest(BaseModel):
|
||||
"""Request model for Claude to start or manage a job"""
|
||||
job_id: str = Field(..., description="The ID of the job to manage")
|
||||
action: str = Field(..., description="Action to perform: start, stop, restart, status")
|
||||
namespace: Optional[str] = Field("development", description="Nomad namespace")
|
||||
purge: Optional[bool] = Field(False, description="Whether to purge the job when stopping")
|
||||
|
||||
|
||||
class ClaudeJobSpecification(BaseModel):
|
||||
"""Simplified job specification for Claude to create a new job"""
|
||||
job_id: str = Field(..., description="The ID for the new job")
|
||||
name: Optional[str] = Field(None, description="Name of the job (defaults to job_id)")
|
||||
type: str = Field("service", description="Job type: service, batch, or system")
|
||||
datacenters: List[str] = Field(["jm"], description="List of datacenters")
|
||||
namespace: str = Field("development", description="Nomad namespace")
|
||||
docker_image: str = Field(..., description="Docker image to run")
|
||||
count: int = Field(1, description="Number of instances to run")
|
||||
cpu: int = Field(100, description="CPU resources in MHz")
|
||||
memory: int = Field(128, description="Memory in MB")
|
||||
ports: Optional[List[Dict[str, Any]]] = Field(None, description="Port mappings")
|
||||
env_vars: Optional[Dict[str, str]] = Field(None, description="Environment variables")
|
||||
|
||||
def to_nomad_job_spec(self) -> Dict[str, Any]:
|
||||
"""Convert to Nomad job specification format"""
|
||||
# Create a task with the specified Docker image
|
||||
task = {
|
||||
"Name": "app",
|
||||
"Driver": "docker",
|
||||
"Config": {
|
||||
"image": self.docker_image,
|
||||
},
|
||||
"Resources": {
|
||||
"CPU": self.cpu,
|
||||
"MemoryMB": self.memory
|
||||
}
|
||||
}
|
||||
|
||||
# Add environment variables if specified
|
||||
if self.env_vars:
|
||||
task["Env"] = self.env_vars
|
||||
|
||||
# Create network configuration
|
||||
network = {}
|
||||
if self.ports:
|
||||
network["DynamicPorts"] = self.ports
|
||||
task["Config"]["ports"] = [port["Label"] for port in self.ports]
|
||||
|
||||
# Create the full job specification
|
||||
job_spec = {
|
||||
"ID": self.job_id,
|
||||
"Name": self.name or self.job_id,
|
||||
"Type": self.type,
|
||||
"Datacenters": self.datacenters,
|
||||
"Namespace": self.namespace,
|
||||
"TaskGroups": [
|
||||
{
|
||||
"Name": "app",
|
||||
"Count": self.count,
|
||||
"Tasks": [task],
|
||||
"Networks": [network] if network else []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return job_spec
|
||||
|
||||
|
||||
class ClaudeJobResponse(BaseModel):
|
||||
"""Response model for Claude job operations"""
|
||||
success: bool = Field(..., description="Whether the operation was successful")
|
||||
job_id: str = Field(..., description="The ID of the job")
|
||||
status: str = Field(..., description="Current status of the job")
|
||||
message: str = Field(..., description="Human-readable message about the operation")
|
||||
details: Optional[Dict[str, Any]] = Field(None, description="Additional details about the job")
|
56
app/schemas/config.py
Normal file
56
app/schemas/config.py
Normal file
@ -0,0 +1,56 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
|
||||
class ConfigBase(BaseModel):
|
||||
"""Base class for configuration schemas."""
|
||||
repository: str = Field(..., description="Repository URL or identifier")
|
||||
job_id: str = Field(..., description="Nomad job ID")
|
||||
description: Optional[str] = Field(None, description="Description of this configuration")
|
||||
repository_alias: Optional[str] = Field(None, description="Short name or alias for the repository")
|
||||
|
||||
# Additional metadata can be stored in the meta field
|
||||
meta: Optional[Dict[str, Any]] = Field(None, description="Additional metadata")
|
||||
|
||||
|
||||
class ConfigCreate(ConfigBase):
|
||||
"""Schema for creating a new configuration."""
|
||||
name: str = Field(..., description="Configuration name (used as the file name)")
|
||||
|
||||
|
||||
class ConfigUpdate(BaseModel):
|
||||
"""Schema for updating an existing configuration."""
|
||||
repository: Optional[str] = Field(None, description="Repository URL or identifier")
|
||||
job_id: Optional[str] = Field(None, description="Nomad job ID")
|
||||
description: Optional[str] = Field(None, description="Description of this configuration")
|
||||
repository_alias: Optional[str] = Field(None, description="Short name or alias for the repository")
|
||||
meta: Optional[Dict[str, Any]] = Field(None, description="Additional metadata")
|
||||
|
||||
|
||||
class ConfigResponse(ConfigBase):
|
||||
"""Schema for configuration response."""
|
||||
name: str = Field(..., description="Configuration name")
|
||||
repository_info: Optional[Dict[str, Any]] = Field(None, description="Repository information from Gitea if available")
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"name": "my-web-app",
|
||||
"repository": "http://gitea.internal.example.com/username/repo-name",
|
||||
"repository_alias": "web-app",
|
||||
"job_id": "web-app",
|
||||
"description": "Web application running in Nomad",
|
||||
"meta": {
|
||||
"owner": "devops-team",
|
||||
"environment": "production"
|
||||
},
|
||||
"repository_info": {
|
||||
"description": "A web application",
|
||||
"default_branch": "main",
|
||||
"stars": 5,
|
||||
"forks": 2,
|
||||
"owner": "username",
|
||||
"html_url": "http://gitea.internal.example.com/username/repo-name"
|
||||
}
|
||||
}
|
||||
}
|
80
app/schemas/job.py
Normal file
80
app/schemas/job.py
Normal file
@ -0,0 +1,80 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Dict, Any, List, Optional
|
||||
|
||||
|
||||
class JobSpecification(BaseModel):
|
||||
"""
|
||||
Nomad job specification. This is a simplified schema as the actual
|
||||
Nomad job spec is quite complex and varies by job type.
|
||||
"""
|
||||
id: Optional[str] = Field(None, description="Job ID")
|
||||
ID: Optional[str] = Field(None, description="Job ID (Nomad format)")
|
||||
name: Optional[str] = Field(None, description="Job name")
|
||||
Name: Optional[str] = Field(None, description="Job name (Nomad format)")
|
||||
type: Optional[str] = Field(None, description="Job type (service, batch, system)")
|
||||
Type: Optional[str] = Field(None, description="Job type (Nomad format)")
|
||||
datacenters: Optional[List[str]] = Field(None, description="List of datacenters")
|
||||
Datacenters: Optional[List[str]] = Field(None, description="List of datacenters (Nomad format)")
|
||||
task_groups: Optional[List[Dict[str, Any]]] = Field(None, description="Task groups")
|
||||
TaskGroups: Optional[List[Dict[str, Any]]] = Field(None, description="Task groups (Nomad format)")
|
||||
meta: Optional[Dict[str, str]] = Field(None, description="Job metadata")
|
||||
Meta: Optional[Dict[str, str]] = Field(None, description="Job metadata (Nomad format)")
|
||||
|
||||
# Allow additional fields (to handle the complete Nomad job spec)
|
||||
class Config:
|
||||
extra = "allow"
|
||||
|
||||
|
||||
class JobOperation(BaseModel):
|
||||
"""Response after a job operation (start, stop, etc.)"""
|
||||
job_id: str = Field(..., description="The ID of the job")
|
||||
eval_id: Optional[str] = Field(None, description="The evaluation ID")
|
||||
status: str = Field(..., description="The status of the operation")
|
||||
warnings: Optional[str] = Field(None, description="Any warnings from Nomad")
|
||||
|
||||
|
||||
class JobResponse(BaseModel):
|
||||
"""
|
||||
Job response schema. This is a simplified version as the actual
|
||||
Nomad job response is quite complex and varies by job type.
|
||||
"""
|
||||
ID: str = Field(..., description="Job ID")
|
||||
Name: str = Field(..., description="Job name")
|
||||
Status: str = Field(..., description="Job status")
|
||||
Type: str = Field(..., description="Job type")
|
||||
repository: Optional[str] = Field(None, description="Associated repository if any")
|
||||
|
||||
# Allow additional fields (to handle the complete Nomad job response)
|
||||
class Config:
|
||||
extra = "allow"
|
||||
|
||||
|
||||
class TaskGroup(BaseModel):
|
||||
"""Task group schema."""
|
||||
Name: str
|
||||
Count: int
|
||||
Tasks: List[Dict[str, Any]]
|
||||
|
||||
class Config:
|
||||
extra = "allow"
|
||||
|
||||
|
||||
class Task(BaseModel):
|
||||
"""Task schema."""
|
||||
Name: str
|
||||
Driver: str
|
||||
Config: Dict[str, Any]
|
||||
|
||||
class Config:
|
||||
extra = "allow"
|
||||
|
||||
|
||||
class Allocation(BaseModel):
|
||||
"""Allocation schema."""
|
||||
ID: str
|
||||
JobID: str
|
||||
TaskGroup: str
|
||||
ClientStatus: str
|
||||
|
||||
class Config:
|
||||
extra = "allow"
|
Reference in New Issue
Block a user