Skip to content

Instantly share code, notes, and snippets.

@tedsuo
Created August 26, 2016 15:26
Show Gist options
  • Select an option

  • Save tedsuo/ae971595d84690ccfed14ad2e888d89c to your computer and use it in GitHub Desktop.

Select an option

Save tedsuo/ae971595d84690ccfed14ad2e888d89c to your computer and use it in GitHub Desktop.
Example Cell API v1.0
package cell
import "io"
type Client interface {
Query(QueryRequest) (QueryResponse, error)
Allocate(AllocationRequest) (AllocationResponse, error)
Run(RunRequest) (RunResponse, error)
Stop(StopRequest) (StopResponse, error)
Delete(DeleteRequest) (DeleteResponse, error)
Events(EventRequest) (EventStream, error)
File(FileRequest) (io.ReadCloser, error)
}
type EventStream interface {
Next() (Event, error)
Close() error
}
type AllocationCommand struct {
Guid string
Resources ContainerResources
Tags Tags
}
type AllocationRequest struct {
Allocate []AllocationCommand
}
type AllocationResponse struct {
AllocationFailures []CommandFailure
}
type CellInfo struct {
Guid string
Zone string
State CellState
Resources CellResources
}
type CellResources struct {
AvailableMemoryMB int
MaxMemoryMB int
AvailableDiskMB int
MaxDiskMB int
AvailableContainers int
MaxContainers int
VolumeDrivers []string
RootFS []string
}
type CellState string
const (
CellStateStarting CellState = "starting"
CellStateRunning CellState = "running"
CellStateEvacuating CellState = "evacuating"
)
type CommandFailure struct {
ContainerGuid string
Error string
}
type ContainerInfo struct {
Guid string
State ContainerState
Resources ContainerResources
ExternalIP string
Stopped bool
Failed bool
FailureReason string
Tags Tags
}
type ContainerResources struct {
MemoryLimitMB int
DiskLimitMB int
RootFS string
VolumeDrivers []string
}
type ContainerState string
const (
ContainerStateReserved ContainerState = "reserved"
ContainerStateInitializing ContainerState = "initializing"
ContainerStateCreated ContainerState = "created"
ContainerStateRunning ContainerState = "running"
ContainerStateCompleted ContainerState = "completed"
)
type DeleteRequest struct {
Delete []DeleteCommand
}
type DeleteCommand struct {
Guid string
}
type DeleteResponse struct {
DeletionFailures []CommandFailure
}
type EventRequest struct {
ContainerInfo bool
ContainerTags []string
}
type Event struct {
Guid string
State ContainerState
}
type FileRequest struct {
Guid string
Path string
}
type QueryRequest struct {
CellInfo bool
Containers bool
ContainerGuids []string
ContainerTags []string
}
type QueryResponse struct {
CellInfo CellInfo
Containers []ContainerInfo
}
type RunRequest struct {
Run []RunCommand
}
type RunResponse struct {
RunFailures []CommandFailure
}
type StopRequest struct {
Stop []StopCommand
}
type StopCommand struct {
Guid string
}
type StopResponse struct {
StopFailures []CommandFailure
}
type Tags map[string]string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment