forked from docker/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As described in our ROADMAP.md, introduce new Swarm management API endpoints relying on swarmkit to deploy services. It currently vendors docker/engine-api changes. This PR is fully backward compatible (joining a Swarm is an optional feature of the Engine, and existing commands are not impacted). Signed-off-by: Tonis Tiigi <[email protected]> Signed-off-by: Victor Vieux <[email protected]> Signed-off-by: Daniel Nephin <[email protected]> Signed-off-by: Jana Radhakrishnan <[email protected]> Signed-off-by: Madhu Venugopal <[email protected]>
- Loading branch information
1 parent
4479304
commit 534a90a
Showing
42 changed files
with
4,045 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/docker/docker/runconfig" | ||
"github.com/docker/engine-api/types" | ||
"github.com/docker/engine-api/types/filters" | ||
) | ||
|
||
type filterHandler func([]types.NetworkResource, string) ([]types.NetworkResource, error) | ||
|
||
var ( | ||
// AcceptedFilters is an acceptable filters for validation | ||
AcceptedFilters = map[string]bool{ | ||
"driver": true, | ||
"type": true, | ||
"name": true, | ||
"id": true, | ||
"label": true, | ||
} | ||
) | ||
|
||
func filterNetworkByType(nws []types.NetworkResource, netType string) (retNws []types.NetworkResource, err error) { | ||
switch netType { | ||
case "builtin": | ||
for _, nw := range nws { | ||
if runconfig.IsPreDefinedNetwork(nw.Name) { | ||
retNws = append(retNws, nw) | ||
} | ||
} | ||
case "custom": | ||
for _, nw := range nws { | ||
if !runconfig.IsPreDefinedNetwork(nw.Name) { | ||
retNws = append(retNws, nw) | ||
} | ||
} | ||
default: | ||
return nil, fmt.Errorf("Invalid filter: 'type'='%s'", netType) | ||
} | ||
return retNws, nil | ||
} | ||
|
||
// filterNetworks filters network list according to user specified filter | ||
// and returns user chosen networks | ||
func filterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.NetworkResource, error) { | ||
// if filter is empty, return original network list | ||
if filter.Len() == 0 { | ||
return nws, nil | ||
} | ||
|
||
if err := filter.Validate(AcceptedFilters); err != nil { | ||
return nil, err | ||
} | ||
|
||
var displayNet []types.NetworkResource | ||
for _, nw := range nws { | ||
if filter.Include("driver") { | ||
if !filter.ExactMatch("driver", nw.Driver) { | ||
continue | ||
} | ||
} | ||
if filter.Include("name") { | ||
if !filter.Match("name", nw.Name) { | ||
continue | ||
} | ||
} | ||
if filter.Include("id") { | ||
if !filter.Match("id", nw.ID) { | ||
continue | ||
} | ||
} | ||
if filter.Include("label") { | ||
if !filter.MatchKVList("label", nw.Labels) { | ||
continue | ||
} | ||
} | ||
displayNet = append(displayNet, nw) | ||
} | ||
|
||
if filter.Include("type") { | ||
var typeNet []types.NetworkResource | ||
errFilter := filter.WalkValues("type", func(fval string) error { | ||
passList, err := filterNetworkByType(displayNet, fval) | ||
if err != nil { | ||
return err | ||
} | ||
typeNet = append(typeNet, passList...) | ||
return nil | ||
}) | ||
if errFilter != nil { | ||
return nil, errFilter | ||
} | ||
displayNet = typeNet | ||
} | ||
|
||
return displayNet, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package swarm | ||
|
||
import ( | ||
basictypes "github.com/docker/engine-api/types" | ||
types "github.com/docker/engine-api/types/swarm" | ||
) | ||
|
||
// Backend abstracts an swarm commands manager. | ||
type Backend interface { | ||
Init(req types.InitRequest) (string, error) | ||
Join(req types.JoinRequest) error | ||
Leave(force bool) error | ||
Inspect() (types.Swarm, error) | ||
Update(uint64, types.Spec) error | ||
GetServices(basictypes.ServiceListOptions) ([]types.Service, error) | ||
GetService(string) (types.Service, error) | ||
CreateService(types.ServiceSpec) (string, error) | ||
UpdateService(string, uint64, types.ServiceSpec) error | ||
RemoveService(string) error | ||
GetNodes(basictypes.NodeListOptions) ([]types.Node, error) | ||
GetNode(string) (types.Node, error) | ||
UpdateNode(string, uint64, types.NodeSpec) error | ||
RemoveNode(string) error | ||
GetTasks(basictypes.TaskListOptions) ([]types.Task, error) | ||
GetTask(string) (types.Task, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package swarm | ||
|
||
import "github.com/docker/docker/api/server/router" | ||
|
||
// buildRouter is a router to talk with the build controller | ||
type swarmRouter struct { | ||
backend Backend | ||
routes []router.Route | ||
} | ||
|
||
// NewRouter initializes a new build router | ||
func NewRouter(b Backend) router.Router { | ||
r := &swarmRouter{ | ||
backend: b, | ||
} | ||
r.initRoutes() | ||
return r | ||
} | ||
|
||
// Routes returns the available routers to the swarm controller | ||
func (sr *swarmRouter) Routes() []router.Route { | ||
return sr.routes | ||
} | ||
|
||
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), | ||
router.NewPostRoute("/swarm/update", sr.updateCluster), | ||
router.NewGetRoute("/services", sr.getServices), | ||
router.NewGetRoute("/services/{id:.*}", sr.getService), | ||
router.NewPostRoute("/services/create", sr.createService), | ||
router.NewPostRoute("/services/{id:.*}/update", sr.updateService), | ||
router.NewDeleteRoute("/services/{id:.*}", sr.removeService), | ||
router.NewGetRoute("/nodes", sr.getNodes), | ||
router.NewGetRoute("/nodes/{id:.*}", sr.getNode), | ||
router.NewDeleteRoute("/nodes/{id:.*}", sr.removeNode), | ||
router.NewPostRoute("/nodes/{id:.*}/update", sr.updateNode), | ||
router.NewGetRoute("/tasks", sr.getTasks), | ||
router.NewGetRoute("/tasks/{id:.*}", sr.getTask), | ||
} | ||
} |
Oops, something went wrong.