forked from boot2docker/boot2docker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
78 lines (66 loc) · 1.71 KB
/
driver.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package driver
import (
"errors"
"fmt"
)
type InitFunc func(i *MachineConfig) (Machine, error)
type MachineState string
const (
// Known ports
SSHPort = 22
DockerPort = 2376
// VM states
Poweroff = MachineState("poweroff")
Running = MachineState("running")
Paused = MachineState("paused")
Saved = MachineState("saved")
Aborted = MachineState("aborted")
)
// Machine represents a virtual machine instance
type Machine interface {
Start() error
Save() error
Pause() error
Stop() error
Refresh() error
Poweroff() error
Restart() error
Reset() error
Delete() error
Modify() error
AddNATPF(n int, name string, rule PFRule) error
DelNATPF(n int, name string) error
SetNIC(n int, nic NIC) error
AddStorageCtl(name string, ctl StorageController) error
DelStorageCtl(name string) error
AttachStorage(ctlName string, medium StorageMedium) error
GetState() MachineState
GetName() string
GetSerialFile() string
GetDockerPort() uint
GetSSHPort() uint
}
var (
// All registred machines
machines map[string]InitFunc
ErrNotSupported = errors.New("driver not supported")
ErrMachineNotExist = errors.New("machine not exist")
ErrMachineExist = errors.New("machine already exists")
ErrPrerequisites = errors.New("prerequisites for machine not satisfied (hypervisor installed?)")
)
func init() {
machines = make(map[string]InitFunc)
}
func Register(driver string, initFunc InitFunc) error {
if _, exists := machines[driver]; exists {
return fmt.Errorf("Driver already registered %s", driver)
}
machines[driver] = initFunc
return nil
}
func GetMachine(mc *MachineConfig) (Machine, error) {
if initFunc, exists := machines[mc.Driver]; exists {
return initFunc(mc)
}
return nil, ErrNotSupported
}