2016-07-08 19:04:00 +00:00
|
|
|
package server
|
|
|
|
|
2016-07-29 22:35:10 +00:00
|
|
|
import (
|
|
|
|
"github.com/mrunalp/ocid/oci"
|
|
|
|
)
|
|
|
|
|
2016-07-19 18:53:57 +00:00
|
|
|
const (
|
|
|
|
runtimeAPIVersion = "v1alpha1"
|
2016-07-08 19:04:00 +00:00
|
|
|
)
|
|
|
|
|
2016-07-19 18:53:57 +00:00
|
|
|
// Server implements the RuntimeService and ImageService
|
|
|
|
type Server struct {
|
2016-08-01 23:05:37 +00:00
|
|
|
runtime *oci.Runtime
|
|
|
|
sandboxDir string
|
|
|
|
state *serverState
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 18:53:57 +00:00
|
|
|
// New creates a new Server with options provided
|
2016-08-01 22:08:21 +00:00
|
|
|
func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
|
2016-08-01 23:05:37 +00:00
|
|
|
r, err := oci.New(runtimePath, containerDir)
|
2016-07-19 18:53:57 +00:00
|
|
|
if err != nil {
|
2016-07-29 22:35:10 +00:00
|
|
|
return nil, err
|
2016-07-19 18:53:57 +00:00
|
|
|
}
|
2016-08-01 23:05:37 +00:00
|
|
|
sandboxes := make(map[string]*sandbox)
|
2016-07-29 22:35:10 +00:00
|
|
|
return &Server{
|
2016-08-01 23:05:37 +00:00
|
|
|
runtime: r,
|
|
|
|
sandboxDir: sandboxDir,
|
|
|
|
state: &serverState{
|
|
|
|
sandboxes: sandboxes,
|
|
|
|
},
|
2016-07-29 22:35:10 +00:00
|
|
|
}, nil
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
|
2016-08-01 23:05:37 +00:00
|
|
|
type serverState struct {
|
|
|
|
sandboxes map[string]*sandbox
|
|
|
|
}
|
|
|
|
|
2016-07-20 01:30:05 +00:00
|
|
|
type sandbox struct {
|
|
|
|
name string
|
|
|
|
logDir string
|
|
|
|
labels map[string]string
|
|
|
|
}
|
2016-08-01 23:05:37 +00:00
|
|
|
|
|
|
|
func (s *Server) addSandbox(sb *sandbox) {
|
|
|
|
s.state.sandboxes[sb.name] = sb
|
|
|
|
}
|