diff --git a/contract/machines.go b/contract/machines.go index 4c93d35..a19f30a 100644 --- a/contract/machines.go +++ b/contract/machines.go @@ -1,7 +1,23 @@ package host +import "time" + +type Machine struct { + ID MachineID `json:"id"` + Artifact ArtifactRef `json:"artifact"` + SystemVolumeID VolumeID `json:"system_volume_id,omitempty"` + UserVolumeIDs []VolumeID `json:"user_volume_ids,omitempty"` + Phase MachinePhase `json:"phase"` + RuntimeHost string `json:"runtime_host,omitempty"` + Error string `json:"error,omitempty"` + CreatedAt time.Time `json:"created_at"` + StartedAt *time.Time `json:"started_at,omitempty"` +} + type CreateMachineRequest struct { - MachineID MachineID `json:"machine_id"` + MachineID MachineID `json:"machine_id"` + Artifact ArtifactRef `json:"artifact"` + UserVolumeIDs []VolumeID `json:"user_volume_ids,omitempty"` } type CreateMachineResponse struct { diff --git a/contract/storage.go b/contract/storage.go new file mode 100644 index 0000000..59325ff --- /dev/null +++ b/contract/storage.go @@ -0,0 +1,15 @@ +package host + +import "time" + +type ArtifactRef struct { + ID ArtifactID `json:"id"` + Version ArtifactVersion `json:"version"` +} + +type Volume struct { + ID VolumeID `json:"id"` + Kind VolumeKind `json:"kind"` + AttachedMachineID *MachineID `json:"attached_machine_id,omitempty"` + CreatedAt time.Time `json:"created_at"` +} diff --git a/contract/types.go b/contract/types.go index 9470317..fa5a379 100644 --- a/contract/types.go +++ b/contract/types.go @@ -1,6 +1,8 @@ package host -import "time" +type ArtifactID string + +type ArtifactVersion string type MachineID string @@ -23,12 +25,3 @@ const ( VolumeKindSystem VolumeKind = "system" VolumeKindUser VolumeKind = "user" ) - -type Machine struct { - ID MachineID `json:"id"` - Phase MachinePhase `json:"phase"` - RuntimeHost string `json:"runtime_host,omitempty"` - Error string `json:"error,omitempty"` - CreatedAt time.Time `json:"created_at"` - StartedAt *time.Time `json:"started_at,omitempty"` -} diff --git a/internal/model/types.go b/internal/model/types.go index 7aa29f5..3c83b15 100644 --- a/internal/model/types.go +++ b/internal/model/types.go @@ -6,22 +6,40 @@ import ( contracthost "github.com/getcompanion-ai/computer-host/contract" ) -type MachineRecord struct { - ID contracthost.MachineID - Phase contracthost.MachinePhase - RuntimeHost string - Error string - CreatedAt time.Time - StartedAt *time.Time -} - type StoragePool string -type VolumeRecord struct { - ID contracthost.VolumeID - MachineID contracthost.MachineID - Kind contracthost.VolumeKind - Pool StoragePool - Path string - CreatedAt time.Time +const ( + StoragePoolArtifacts StoragePool = "artifacts" + StoragePoolMachineDisks StoragePool = "machine-disks" + StoragePoolState StoragePool = "state" + StoragePoolUserVolumes StoragePool = "user-volumes" +) + +type ArtifactRecord struct { + Ref contracthost.ArtifactRef + KernelImagePath string + RootFSPath string + CreatedAt time.Time +} + +type MachineRecord struct { + ID contracthost.MachineID + Artifact contracthost.ArtifactRef + SystemVolumeID contracthost.VolumeID + UserVolumeIDs []contracthost.VolumeID + Phase contracthost.MachinePhase + RuntimeHost string + Error string + CreatedAt time.Time + StartedAt *time.Time +} + +type VolumeRecord struct { + ID contracthost.VolumeID + Kind contracthost.VolumeKind + AttachedMachineID *contracthost.MachineID + SourceArtifact *contracthost.ArtifactRef + Pool StoragePool + Path string + CreatedAt time.Time } diff --git a/internal/store/store.go b/internal/store/store.go index 57db4b2..0604683 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -8,9 +8,17 @@ import ( ) type Store interface { + PutArtifact(context.Context, model.ArtifactRecord) error + GetArtifact(context.Context, contracthost.ArtifactRef) (*model.ArtifactRecord, error) + ListArtifacts(context.Context) ([]model.ArtifactRecord, error) CreateMachine(context.Context, model.MachineRecord) error GetMachine(context.Context, contracthost.MachineID) (*model.MachineRecord, error) ListMachines(context.Context) ([]model.MachineRecord, error) UpdateMachine(context.Context, model.MachineRecord) error DeleteMachine(context.Context, contracthost.MachineID) error + CreateVolume(context.Context, model.VolumeRecord) error + GetVolume(context.Context, contracthost.VolumeID) (*model.VolumeRecord, error) + ListVolumes(context.Context) ([]model.VolumeRecord, error) + UpdateVolume(context.Context, model.VolumeRecord) error + DeleteVolume(context.Context, contracthost.VolumeID) error }