github.com/a4a881d4/docker@v1.9.0-rc2/api/server/router/network/network.go (about) 1 package network 2 3 import ( 4 "net/http" 5 6 "github.com/docker/docker/api/server/httputils" 7 "github.com/docker/docker/api/server/router" 8 "github.com/docker/docker/api/server/router/local" 9 "github.com/docker/docker/daemon" 10 "github.com/docker/docker/errors" 11 "golang.org/x/net/context" 12 ) 13 14 // networkRouter is a router to talk with the network controller 15 type networkRouter struct { 16 daemon *daemon.Daemon 17 routes []router.Route 18 } 19 20 // NewRouter initializes a new network router 21 func NewRouter(d *daemon.Daemon) router.Router { 22 r := &networkRouter{ 23 daemon: d, 24 } 25 r.initRoutes() 26 return r 27 } 28 29 // Routes returns the available routes to the network controller 30 func (r *networkRouter) Routes() []router.Route { 31 return r.routes 32 } 33 34 func (r *networkRouter) initRoutes() { 35 r.routes = []router.Route{ 36 // GET 37 local.NewGetRoute("/networks", r.controllerEnabledMiddleware(r.getNetworksList)), 38 local.NewGetRoute("/networks/{id:.*}", r.controllerEnabledMiddleware(r.getNetwork)), 39 // POST 40 local.NewPostRoute("/networks/create", r.controllerEnabledMiddleware(r.postNetworkCreate)), 41 local.NewPostRoute("/networks/{id:.*}/connect", r.controllerEnabledMiddleware(r.postNetworkConnect)), 42 local.NewPostRoute("/networks/{id:.*}/disconnect", r.controllerEnabledMiddleware(r.postNetworkDisconnect)), 43 // DELETE 44 local.NewDeleteRoute("/networks/{id:.*}", r.controllerEnabledMiddleware(r.deleteNetwork)), 45 } 46 } 47 48 func (r *networkRouter) controllerEnabledMiddleware(handler httputils.APIFunc) httputils.APIFunc { 49 if r.daemon.NetworkControllerEnabled() { 50 return handler 51 } 52 return networkControllerDisabled 53 } 54 55 func networkControllerDisabled(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { 56 return errors.ErrorNetworkControllerNotEnabled.WithArgs() 57 }