forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_driver.go
197 lines (161 loc) · 4.6 KB
/
server_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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package rpcdriver
import (
"encoding/gob"
"encoding/json"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/state"
"github.com/docker/machine/libmachine/version"
)
func init() {
gob.Register(new(RPCFlags))
gob.Register(new(mcnflag.IntFlag))
gob.Register(new(mcnflag.StringFlag))
gob.Register(new(mcnflag.StringSliceFlag))
gob.Register(new(mcnflag.BoolFlag))
}
type RPCFlags struct {
Values map[string]interface{}
}
func (r RPCFlags) Get(key string) interface{} {
val, ok := r.Values[key]
if !ok {
log.Warnf("Trying to access option %s which does not exist", key)
log.Warn("THIS ***WILL*** CAUSE UNEXPECTED BEHAVIOR")
}
return val
}
func (r RPCFlags) String(key string) string {
val, ok := r.Get(key).(string)
if !ok {
log.Warnf("Type assertion did not go smoothly to string for key %s", key)
}
return val
}
func (r RPCFlags) StringSlice(key string) []string {
val, ok := r.Get(key).([]string)
if !ok {
log.Warnf("Type assertion did not go smoothly to string slice for key %s", key)
}
return val
}
func (r RPCFlags) Int(key string) int {
val, ok := r.Get(key).(int)
if !ok {
log.Warnf("Type assertion did not go smoothly to int for key %s", key)
}
return val
}
func (r RPCFlags) Bool(key string) bool {
val, ok := r.Get(key).(bool)
if !ok {
log.Warnf("Type assertion did not go smoothly to bool for key %s", key)
}
return val
}
type RPCServerDriver struct {
ActualDriver drivers.Driver
CloseCh chan bool
HeartbeatCh chan bool
}
func NewRPCServerDriver(d drivers.Driver) *RPCServerDriver {
return &RPCServerDriver{
ActualDriver: d,
CloseCh: make(chan bool),
HeartbeatCh: make(chan bool),
}
}
func (r *RPCServerDriver) Close(_, _ *struct{}) error {
r.CloseCh <- true
return nil
}
func (r *RPCServerDriver) GetVersion(_ *struct{}, reply *int) error {
*reply = version.APIVersion
return nil
}
func (r *RPCServerDriver) GetConfigRaw(_ *struct{}, reply *[]byte) error {
driverData, err := json.Marshal(r.ActualDriver)
if err != nil {
return err
}
*reply = driverData
return nil
}
func (r *RPCServerDriver) GetCreateFlags(_ *struct{}, reply *[]mcnflag.Flag) error {
*reply = r.ActualDriver.GetCreateFlags()
return nil
}
func (r *RPCServerDriver) SetConfigRaw(data []byte, _ *struct{}) error {
return json.Unmarshal(data, &r.ActualDriver)
}
func (r *RPCServerDriver) Create(_, _ *struct{}) error {
return r.ActualDriver.Create()
}
func (r *RPCServerDriver) DriverName(_ *struct{}, reply *string) error {
*reply = r.ActualDriver.DriverName()
return nil
}
func (r *RPCServerDriver) GetIP(_ *struct{}, reply *string) error {
ip, err := r.ActualDriver.GetIP()
*reply = ip
return err
}
func (r *RPCServerDriver) GetMachineName(_ *struct{}, reply *string) error {
*reply = r.ActualDriver.GetMachineName()
return nil
}
func (r *RPCServerDriver) GetSSHHostname(_ *struct{}, reply *string) error {
hostname, err := r.ActualDriver.GetSSHHostname()
*reply = hostname
return err
}
func (r *RPCServerDriver) GetSSHKeyPath(_ *struct{}, reply *string) error {
*reply = r.ActualDriver.GetSSHKeyPath()
return nil
}
// GetSSHPort returns port for use with ssh
func (r *RPCServerDriver) GetSSHPort(_ *struct{}, reply *int) error {
port, err := r.ActualDriver.GetSSHPort()
*reply = port
return err
}
func (r *RPCServerDriver) GetSSHUsername(_ *struct{}, reply *string) error {
*reply = r.ActualDriver.GetSSHUsername()
return nil
}
func (r *RPCServerDriver) GetURL(_ *struct{}, reply *string) error {
info, err := r.ActualDriver.GetURL()
*reply = info
return err
}
func (r *RPCServerDriver) GetState(_ *struct{}, reply *state.State) error {
s, err := r.ActualDriver.GetState()
*reply = s
return err
}
func (r *RPCServerDriver) Kill(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Kill()
}
func (r *RPCServerDriver) PreCreateCheck(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.PreCreateCheck()
}
func (r *RPCServerDriver) Remove(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Remove()
}
func (r *RPCServerDriver) Restart(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Restart()
}
func (r *RPCServerDriver) SetConfigFromFlags(flags *drivers.DriverOptions, _ *struct{}) error {
return r.ActualDriver.SetConfigFromFlags(*flags)
}
func (r *RPCServerDriver) Start(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Start()
}
func (r *RPCServerDriver) Stop(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Stop()
}
func (r *RPCServerDriver) Heartbeat(_ *struct{}, _ *struct{}) error {
r.HeartbeatCh <- true
return nil
}