2016-07-08 19:04:00 +00:00
|
|
|
package server
|
|
|
|
|
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-07-20 01:30:05 +00:00
|
|
|
runtime ociRuntime
|
|
|
|
sandboxDir string
|
|
|
|
sandboxes []*sandbox
|
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-07-20 01:30:05 +00:00
|
|
|
func New(runtimePath, sandboxDir string) (*Server, error) {
|
2016-07-19 18:53:57 +00:00
|
|
|
// TODO(runcom): runtimePath arg is unused but it might be useful
|
|
|
|
// if we're willing to open the doors to other runtimes in the future.
|
|
|
|
r := &runcRuntime{}
|
|
|
|
return &Server{
|
2016-07-20 01:30:05 +00:00
|
|
|
runtime: r,
|
|
|
|
sandboxDir: sandboxDir,
|
2016-07-19 18:53:57 +00:00
|
|
|
}, nil
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 18:53:57 +00:00
|
|
|
// TODO(runcom): export? this is being done just because runc shows a 3 line version :/
|
|
|
|
// but it might actually be a useful abstraction (?)
|
|
|
|
type ociRuntime interface {
|
|
|
|
Name() string
|
|
|
|
Path() (string, error)
|
|
|
|
Version() (string, error)
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 18:53:57 +00:00
|
|
|
type runcRuntime struct {
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 18:53:57 +00:00
|
|
|
func (r *runcRuntime) Name() string {
|
|
|
|
return "runc"
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 18:53:57 +00:00
|
|
|
func (r *runcRuntime) Path() (string, error) {
|
|
|
|
// TODO(runcom): we're saying runc is always in $PATH here for now
|
|
|
|
return "runc", nil
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 18:53:57 +00:00
|
|
|
func (r *runcRuntime) Version() (string, error) {
|
|
|
|
path, err := r.Path()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
runtimeVersion, err := execRuncVersion(path, "-v")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return runtimeVersion, nil
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
|
|
|
|
type sandbox struct {
|
|
|
|
name string
|
|
|
|
logDir string
|
|
|
|
labels map[string]string
|
|
|
|
}
|