@@ -33,6 +33,7 @@ import (
33
33
"github.com/contiv/netplugin/mgmtfn/dockplugin/libnetClient"
34
34
"github.com/contiv/netplugin/netmaster/client"
35
35
"github.com/contiv/netplugin/netmaster/intent"
36
+ "github.com/contiv/netplugin/plugin"
36
37
"github.com/docker/docker/pkg/plugins"
37
38
"github.com/docker/libnetwork/drivers/remote/api"
38
39
"github.com/gorilla/mux"
@@ -41,8 +42,11 @@ import (
41
42
const pluginPath = "/run/docker/plugins"
42
43
const driverName = "netplugin"
43
44
45
+ var netPlugin * plugin.NetPlugin
46
+
44
47
// InitDockPlugin initializes the docker plugin
45
- func InitDockPlugin () error {
48
+ func InitDockPlugin (netplugin * plugin.NetPlugin ) error {
49
+ netPlugin = netplugin
46
50
hostname , err := os .Hostname ()
47
51
if err != nil {
48
52
log .Fatalf ("Could not retrieve hostname: %v" , err )
@@ -436,8 +440,20 @@ func join() func(http.ResponseWriter, *http.Request) {
436
440
437
441
ep , err := netdcliGetEndpoint (networkName + "-" + jr .EndpointID )
438
442
if err != nil {
439
- httpError (w , "Could not derive created interface" , err )
440
- return
443
+ // Add the endpoint oper state
444
+ err = netPlugin .CreateEndpoint (networkName + "-" + jr .EndpointID )
445
+ if err != nil {
446
+ log .Errorf ("Endpoint creation failed. Error: %s" , err )
447
+ httpError (w , "Could not create endpoint" , err )
448
+ return
449
+ }
450
+
451
+ // Try to get it again
452
+ ep , err = netdcliGetEndpoint (networkName + "-" + jr .EndpointID )
453
+ if err != nil {
454
+ httpError (w , "Could not find created endpoint" , err )
455
+ return
456
+ }
441
457
}
442
458
443
459
nw , err := netdcliGetNetwork (networkName )
@@ -454,7 +470,7 @@ func join() func(http.ResponseWriter, *http.Request) {
454
470
Gateway : nw [0 ].DefaultGw ,
455
471
}
456
472
457
- log .Infof ("Sending JoinResponse: {%+v}" , joinResp )
473
+ log .Infof ("Sending JoinResponse: {%+v}, InterfaceName: %s " , joinResp , ep [ 0 ]. PortName )
458
474
459
475
content , err = json .Marshal (joinResp )
460
476
if err != nil {
@@ -469,6 +485,37 @@ func join() func(http.ResponseWriter, *http.Request) {
469
485
func leave () func (http.ResponseWriter , * http.Request ) {
470
486
return func (w http.ResponseWriter , r * http.Request ) {
471
487
logEvent ("leave" )
488
+
489
+ lr := api.LeaveRequest {}
490
+ content , err := ioutil .ReadAll (r .Body )
491
+ if err != nil {
492
+ httpError (w , "Could not read join request" , err )
493
+ return
494
+ }
495
+
496
+ if err := json .Unmarshal (content , & lr ); err != nil {
497
+ httpError (w , "Could not parse join request" , err )
498
+ return
499
+ }
500
+
501
+ log .Infof ("LeaveRequest: %+v" , lr )
502
+
503
+ networkName , err := GetNetworkName (lr .NetworkID )
504
+ if err != nil {
505
+ log .Errorf ("Error getting network name for UUID: %s. Err: %v" , lr .NetworkID , err )
506
+ httpError (w , "Could not get network name" , err )
507
+ return
508
+ }
509
+
510
+ // Delete the Endpoint
511
+ err = netPlugin .DeleteEndpoint (networkName + "-" + lr .EndpointID )
512
+ if err != nil {
513
+ log .Errorf ("error deleting an endpoint upon container stop: %v \n " , err )
514
+ httpError (w , "Could not delete endpoint" , err )
515
+ return
516
+ }
517
+
518
+ // Send response
472
519
w .WriteHeader (200 )
473
520
}
474
521
}
0 commit comments