-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.go
63 lines (54 loc) · 1.35 KB
/
environment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package circuit
import (
"errors"
"github.com/docker/docker/client"
"github.com/operable/circuit-driver/api"
)
type EnvironmentKind int
const (
NativeKind EnvironmentKind = iota
DockerKind
)
type EnvironmentMetadata map[string]string
type EnvironmentUserData map[string]interface{}
type Environment interface {
GetKind() EnvironmentKind
SetUserData(EnvironmentUserData) error
GetUserData() (EnvironmentUserData, error)
GetMetadata() EnvironmentMetadata
Run(request api.ExecRequest) (api.ExecResult, error)
Shutdown() error
}
type DockerEnvironmentOptions struct {
Conn *client.Client
Image string
Tag string
Binds []string
DriverInstance string
DriverPath string
Memory int64
}
type CreateEnvironmentOptions struct {
Kind EnvironmentKind
Bundle string
DockerOptions DockerEnvironmentOptions
}
var ErrorDeadEnvironment = errors.New("Dead environment")
var EmptyExecResult = api.ExecResult{}
func CreateEnvironment(options CreateEnvironmentOptions) (Environment, error) {
switch options.Kind {
case NativeKind:
env := &nativeEnvironment{}
if err := env.init(options); err != nil {
return nil, err
}
return env, nil
case DockerKind:
env := &dockerEnvironment{}
if err := env.init(options); err != nil {
return nil, err
}
return env, nil
}
return nil, nil
}