2016-06-13 22:52:49 -04:00
|
|
|
package swarm
|
|
|
|
|
2016-10-26 04:17:31 -04:00
|
|
|
import (
|
|
|
|
"github.com/docker/docker/api/server/router"
|
|
|
|
"github.com/docker/docker/daemon"
|
|
|
|
)
|
2016-06-13 22:52:49 -04:00
|
|
|
|
2016-11-10 21:45:48 -05:00
|
|
|
// swarmRouter is a router to talk with the build controller
|
2016-06-13 22:52:49 -04:00
|
|
|
type swarmRouter struct {
|
|
|
|
backend Backend
|
|
|
|
routes []router.Route
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRouter initializes a new build router
|
2016-10-26 04:17:31 -04:00
|
|
|
func NewRouter(d *daemon.Daemon, b Backend) router.Router {
|
2016-06-13 22:52:49 -04:00
|
|
|
r := &swarmRouter{
|
|
|
|
backend: b,
|
|
|
|
}
|
|
|
|
r.initRoutes()
|
2016-10-26 04:17:31 -04:00
|
|
|
if d.HasExperimental() {
|
|
|
|
r.addExperimentalRoutes()
|
|
|
|
}
|
2016-06-13 22:52:49 -04:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
// Routes returns the available routers to the swarm controller
|
|
|
|
func (sr *swarmRouter) Routes() []router.Route {
|
|
|
|
return sr.routes
|
|
|
|
}
|
|
|
|
|
2016-10-26 04:17:31 -04:00
|
|
|
func (sr *swarmRouter) addExperimentalRoutes() {
|
|
|
|
sr.routes = append(sr.routes,
|
|
|
|
router.Cancellable(router.NewGetRoute("/services/{id}/logs", sr.getServiceLogs)),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-06-13 22:52:49 -04:00
|
|
|
func (sr *swarmRouter) initRoutes() {
|
|
|
|
sr.routes = []router.Route{
|
|
|
|
router.NewPostRoute("/swarm/init", sr.initCluster),
|
|
|
|
router.NewPostRoute("/swarm/join", sr.joinCluster),
|
|
|
|
router.NewPostRoute("/swarm/leave", sr.leaveCluster),
|
|
|
|
router.NewGetRoute("/swarm", sr.inspectCluster),
|
2016-10-27 21:50:49 -04:00
|
|
|
router.NewGetRoute("/swarm/unlockkey", sr.getUnlockKey),
|
2016-06-13 22:52:49 -04:00
|
|
|
router.NewPostRoute("/swarm/update", sr.updateCluster),
|
2016-10-21 21:07:55 -04:00
|
|
|
router.NewPostRoute("/swarm/unlock", sr.unlockCluster),
|
2016-06-13 22:52:49 -04:00
|
|
|
router.NewGetRoute("/services", sr.getServices),
|
2016-10-26 04:17:31 -04:00
|
|
|
router.NewGetRoute("/services/{id}", sr.getService),
|
2016-06-13 22:52:49 -04:00
|
|
|
router.NewPostRoute("/services/create", sr.createService),
|
2016-10-26 04:17:31 -04:00
|
|
|
router.NewPostRoute("/services/{id}/update", sr.updateService),
|
|
|
|
router.NewDeleteRoute("/services/{id}", sr.removeService),
|
2016-06-13 22:52:49 -04:00
|
|
|
router.NewGetRoute("/nodes", sr.getNodes),
|
2016-10-26 04:17:31 -04:00
|
|
|
router.NewGetRoute("/nodes/{id}", sr.getNode),
|
|
|
|
router.NewDeleteRoute("/nodes/{id}", sr.removeNode),
|
|
|
|
router.NewPostRoute("/nodes/{id}/update", sr.updateNode),
|
2016-06-13 22:52:49 -04:00
|
|
|
router.NewGetRoute("/tasks", sr.getTasks),
|
2016-10-26 04:17:31 -04:00
|
|
|
router.NewGetRoute("/tasks/{id}", sr.getTask),
|
2016-10-19 12:22:02 -04:00
|
|
|
router.NewGetRoute("/secrets", sr.getSecrets),
|
2016-10-27 03:41:32 -04:00
|
|
|
router.NewPostRoute("/secrets", sr.createSecret),
|
2016-10-26 04:17:31 -04:00
|
|
|
router.NewDeleteRoute("/secrets/{id}", sr.removeSecret),
|
|
|
|
router.NewGetRoute("/secrets/{id}", sr.getSecret),
|
|
|
|
router.NewPostRoute("/secrets/{id}/update", sr.updateSecret),
|
2016-06-13 22:52:49 -04:00
|
|
|
}
|
|
|
|
}
|