forked from boot2docker/boot2docker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
machine.go
166 lines (140 loc) · 3.95 KB
/
machine.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package dummy
import (
"fmt"
"os"
"github.com/boot2docker/boot2docker-cli/driver"
)
func init() {
if err := driver.Register("dummy", InitFunc); err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize driver. Error : %s", err.Error())
os.Exit(1)
}
}
// Initialize the Machine.
func InitFunc(i *driver.MachineConfig) (driver.Machine, error) {
fmt.Printf("Init dummy %s\n", i.VM)
return &Machine{Name: i.VM, State: driver.Poweroff}, nil
}
// Machine information.
type Machine struct {
Name string
UUID string
State driver.MachineState
CPUs uint
Memory uint // main memory (in MB)
VRAM uint // video memory (in MB)
CfgFile string
BaseFolder string
OSType string
BootOrder []string // max 4 slots, each in {none|floppy|dvd|disk|net}
DockerPort uint
SSHPort uint
SerialFile string
}
// Refresh reloads the machine information.
func (m *Machine) Refresh() error {
fmt.Printf("Refresh %s: %s\n", m.Name, m.State)
return nil
}
// Start starts the machine.
func (m *Machine) Start() error {
m.State = driver.Running
fmt.Printf("Start %s: %s\n", m.Name, m.State)
return nil
}
// Suspend suspends the machine and saves its state to disk.
func (m *Machine) Save() error {
m.State = driver.Saved
fmt.Printf("Save %s: %s\n", m.Name, m.State)
return nil
}
// Pause pauses the execution of the machine.
func (m *Machine) Pause() error {
m.State = driver.Paused
fmt.Printf("Pause %s: %s\n", m.Name, m.State)
return nil
}
// Stop gracefully stops the machine.
func (m *Machine) Stop() error {
m.State = driver.Poweroff
fmt.Printf("Stop %s: %s\n", m.Name, m.State)
return nil
}
// Poweroff forcefully stops the machine. State is lost and might corrupt the disk image.
func (m *Machine) Poweroff() error {
m.State = driver.Poweroff
fmt.Printf("Poweroff %s: %s\n", m.Name, m.State)
return nil
}
// Restart gracefully restarts the machine.
func (m *Machine) Restart() error {
m.State = driver.Running
fmt.Printf("Restart %s: %s\n", m.Name, m.State)
return nil
}
// Reset forcefully restarts the machine. State is lost and might corrupt the disk image.
func (m *Machine) Reset() error {
m.State = driver.Running
fmt.Printf("Reset %s: %s\n", m.Name, m.State)
return nil
}
// Get current name
func (m *Machine) GetName() string {
return m.Name
}
// Get current state
func (m *Machine) GetState() driver.MachineState {
return m.State
}
// Get serial file
func (m *Machine) GetSerialFile() string {
return m.SerialFile
}
// Get Docker port
func (m *Machine) GetDockerPort() uint {
return m.DockerPort
}
// Get SSH port
func (m *Machine) GetSSHPort() uint {
return m.SSHPort
}
// Delete deletes the machine and associated disk images.
func (m *Machine) Delete() error {
fmt.Printf("Delete %s: %s\n", m.Name, m.State)
return nil
}
// Modify changes the settings of the machine.
func (m *Machine) Modify() error {
fmt.Printf("Modify %s: %s\n", m.Name, m.State)
return m.Refresh()
}
// AddNATPF adds a NAT port forarding rule to the n-th NIC with the given name.
func (m *Machine) AddNATPF(n int, name string, rule driver.PFRule) error {
fmt.Println("Add NAT PF")
return nil
}
// DelNATPF deletes the NAT port forwarding rule with the given name from the n-th NIC.
func (m *Machine) DelNATPF(n int, name string) error {
fmt.Println("Del NAT PF")
return nil
}
// SetNIC set the n-th NIC.
func (m *Machine) SetNIC(n int, nic driver.NIC) error {
fmt.Println("Set NIC")
return nil
}
// AddStorageCtl adds a storage controller with the given name.
func (m *Machine) AddStorageCtl(name string, ctl driver.StorageController) error {
fmt.Println("Add storage ctl")
return nil
}
// DelStorageCtl deletes the storage controller with the given name.
func (m *Machine) DelStorageCtl(name string) error {
fmt.Println("Del storage ctl")
return nil
}
// AttachStorage attaches a storage medium to the named storage controller.
func (m *Machine) AttachStorage(ctlName string, medium driver.StorageMedium) error {
fmt.Println("Attach storage")
return nil
}