@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
13
13
limitations under the License.
14
14
*/
15
15
16
- package drivers
16
+ package docker
17
17
18
18
import (
19
19
"errors"
@@ -25,30 +25,34 @@ import (
25
25
"path"
26
26
"strconv"
27
27
28
- "github.com/contiv/netplugin/core "
28
+ "github.com/contiv/netplugin/crtclient "
29
29
"github.com/vishvananda/netlink"
30
30
// "github.com/vishvananda/netns"
31
31
)
32
32
33
- type DockerDriverConfig struct {
33
+ type DockerConfig struct {
34
34
Docker struct {
35
35
Socket string
36
36
}
37
37
}
38
38
39
- type DockerDriver struct {
39
+ type Docker struct {
40
40
Client * dockerclient.DockerClient
41
41
}
42
42
43
- func (d * DockerDriver ) Init (config * core .Config ) error {
43
+ func (d * Docker ) Init (config * crtclient .Config ) error {
44
44
if config == nil {
45
- return & core. Error { Desc : fmt . Sprintf ( "Invalid arguments. cfg: %v" , config )}
45
+ return errors . New ( "null config!" )
46
46
}
47
47
48
- cfg , ok := config .V .(* DockerDriverConfig )
48
+ cfg , ok := config .V .(* DockerConfig )
49
49
50
50
if ! ok {
51
- return & core.Error {Desc : "Invalid config type passed!" }
51
+ return errors .New ("Invalid config type passed!" )
52
+ }
53
+
54
+ if cfg .Docker .Socket == "" {
55
+ return errors .New (fmt .Sprintf ("Invalid arguments. cfg: %v" , config ))
52
56
}
53
57
54
58
// TODO: ADD TLS support
@@ -57,10 +61,10 @@ func (d *DockerDriver) Init(config *core.Config) error {
57
61
return nil
58
62
}
59
63
60
- func (d * DockerDriver ) Deinit () {
64
+ func (d * Docker ) Deinit () {
61
65
}
62
66
63
- func (d * DockerDriver ) getContPid (contName string ) (string , error ) {
67
+ func (d * Docker ) getContPid (contName string ) (string , error ) {
64
68
contInfo , err := d .Client .InspectContainer (contName )
65
69
if err != nil {
66
70
return "" , errors .New ("couldn't obtain container info" )
@@ -93,7 +97,7 @@ func setIfNs(ifname string, pid int) error {
93
97
// Note: most of the work in this function is a temporary workaround for
94
98
// what docker daemon would eventually do; in the meanwhile
95
99
// the essense of the logic is borrowed from pipework
96
- func (d * DockerDriver ) moveIfToContainer (ifId string , contName string ) error {
100
+ func (d * Docker ) moveIfToContainer (ifId string , contName string ) error {
97
101
98
102
// log.Printf("Moving interface '%s' into container '%s' \n", ifId, contName)
99
103
@@ -137,7 +141,7 @@ func (d *DockerDriver) moveIfToContainer(ifId string, contName string) error {
137
141
return err
138
142
}
139
143
140
- func (d * DockerDriver ) cleanupNetns (contName string ) error {
144
+ func (d * Docker ) cleanupNetns (contName string ) error {
141
145
contPid , err := d .getContPid (contName )
142
146
if err != nil {
143
147
return err
@@ -153,7 +157,7 @@ func (d *DockerDriver) cleanupNetns(contName string) error {
153
157
}
154
158
155
159
/*
156
- func (d *DockerDriver ) configureIfAddress(ctx *core .ContainerEpContext) error {
160
+ func (d *Docker ) configureIfAddress(ctx *crtclient .ContainerEpContext) error {
157
161
158
162
log.Printf("configuring ip: addr -%s/%d- on if %s for container %s\n",
159
163
ctx.IpAddress, ctx.SubnetLen, ctx.InterfaceId, ctx.NewContName)
@@ -228,7 +232,7 @@ func (d *DockerDriver) configureIfAddress(ctx *core.ContainerEpContext) error {
228
232
return err
229
233
}
230
234
*/
231
- func (d * DockerDriver ) configureIfAddress (ctx * core .ContainerEpContext ) error {
235
+ func (d * Docker ) configureIfAddress (ctx * crtclient .ContainerEpContext ) error {
232
236
233
237
log .Printf ("configuring ip: addr -%s/%d- on if %s for container %s\n " ,
234
238
ctx .IpAddress , ctx .SubnetLen , ctx .InterfaceId , ctx .NewContName )
@@ -268,7 +272,7 @@ func (d *DockerDriver) configureIfAddress(ctx *core.ContainerEpContext) error {
268
272
269
273
// performs funtion to configure the network access and policies
270
274
// before the container becomes active
271
- func (d * DockerDriver ) AttachEndpoint (ctx * core .ContainerEpContext ) error {
275
+ func (d * Docker ) AttachEndpoint (ctx * crtclient .ContainerEpContext ) error {
272
276
273
277
err := d .moveIfToContainer (ctx .InterfaceId , ctx .NewContName )
274
278
if err != nil {
@@ -289,7 +293,7 @@ func (d *DockerDriver) AttachEndpoint(ctx *core.ContainerEpContext) error {
289
293
}
290
294
291
295
// uninstall the policies and configuration during container attach
292
- func (d * DockerDriver ) DetachEndpoint (ctx * core .ContainerEpContext ) error {
296
+ func (d * Docker ) DetachEndpoint (ctx * crtclient .ContainerEpContext ) error {
293
297
var err error
294
298
295
299
// log.Printf("Detached called for container %s with %s interface\n",
@@ -303,7 +307,7 @@ func (d *DockerDriver) DetachEndpoint(ctx *core.ContainerEpContext) error {
303
307
return err
304
308
}
305
309
306
- func (d * DockerDriver ) GetContainerId (contName string ) string {
310
+ func (d * Docker ) GetContainerId (contName string ) string {
307
311
contInfo , err := d .Client .InspectContainer (contName )
308
312
if err != nil {
309
313
log .Printf ("could not get contId for container %s, err '%s' \n " ,
@@ -319,7 +323,7 @@ func (d *DockerDriver) GetContainerId(contName string) string {
319
323
return contInfo .Id
320
324
}
321
325
322
- func (d * DockerDriver ) GetContainerName (contId string ) (string , error ) {
326
+ func (d * Docker ) GetContainerName (contId string ) (string , error ) {
323
327
contInfo , err := d .Client .InspectContainer (contId )
324
328
if err != nil {
325
329
log .Printf ("could not get contName for container %s, err '%s' \n " ,
0 commit comments