2015-09-25 06:19:17 -04:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2017-01-19 06:04:26 -05:00
|
|
|
"fmt"
|
2015-09-25 06:19:17 -04:00
|
|
|
"net/http"
|
2017-03-09 14:42:10 -05:00
|
|
|
"strconv"
|
2017-01-19 06:04:26 -05:00
|
|
|
"strings"
|
2015-09-25 06:19:17 -04:00
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-03-09 14:42:10 -05:00
|
|
|
"github.com/docker/docker/api/errors"
|
2015-09-25 06:19:17 -04:00
|
|
|
"github.com/docker/docker/api/server/httputils"
|
2016-09-06 14:46:37 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/api/types/network"
|
2017-02-02 08:48:53 -05:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2015-09-25 06:19:17 -04:00
|
|
|
"github.com/docker/libnetwork"
|
2016-11-04 15:27:36 -04:00
|
|
|
"github.com/docker/libnetwork/networkdb"
|
2015-09-25 06:19:17 -04:00
|
|
|
)
|
|
|
|
|
2016-12-29 03:10:40 -05:00
|
|
|
var (
|
|
|
|
// acceptedNetworkFilters is a list of acceptable filters
|
|
|
|
acceptedNetworkFilters = map[string]bool{
|
|
|
|
"driver": true,
|
|
|
|
"type": true,
|
|
|
|
"name": true,
|
|
|
|
"id": true,
|
|
|
|
"label": true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2015-09-25 06:19:17 -04:00
|
|
|
func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
filter := r.Form.Get("filters")
|
|
|
|
netFilters, err := filters.FromParam(filter)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-12-29 03:10:40 -05:00
|
|
|
if err := netFilters.Validate(acceptedNetworkFilters); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-06-13 22:52:49 -04:00
|
|
|
list := []types.NetworkResource{}
|
2015-09-25 06:19:17 -04:00
|
|
|
|
2016-12-26 07:53:13 -05:00
|
|
|
if nr, err := n.cluster.GetNetworks(); err == nil {
|
2016-10-13 12:34:19 -04:00
|
|
|
list = append(list, nr...)
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
2015-11-10 03:57:06 -05:00
|
|
|
|
2016-06-13 22:52:49 -04:00
|
|
|
// Combine the network list returned by Docker daemon if it is not already
|
|
|
|
// returned by the cluster manager
|
|
|
|
SKIP:
|
|
|
|
for _, nw := range n.backend.GetNetworks() {
|
|
|
|
for _, nl := range list {
|
|
|
|
if nl.ID == nw.ID() {
|
|
|
|
continue SKIP
|
|
|
|
}
|
|
|
|
}
|
2017-02-02 08:48:53 -05:00
|
|
|
|
|
|
|
var nr *types.NetworkResource
|
2017-02-19 03:43:08 -05:00
|
|
|
// Versions < 1.27 fetches all the containers attached to a network
|
2017-02-02 08:48:53 -05:00
|
|
|
// in a network list api call. It is a heavy weight operation when
|
2017-02-19 03:43:08 -05:00
|
|
|
// run across all the networks. Starting API version 1.27, this detailed
|
2017-02-02 08:48:53 -05:00
|
|
|
// info is available for network specific GET API (equivalent to inspect)
|
2017-02-19 03:43:08 -05:00
|
|
|
if versions.LessThan(httputils.VersionFromContext(ctx), "1.27") {
|
2017-03-09 14:42:10 -05:00
|
|
|
nr = n.buildDetailedNetworkResources(nw, false)
|
2017-02-02 08:48:53 -05:00
|
|
|
} else {
|
|
|
|
nr = n.buildNetworkResource(nw)
|
|
|
|
}
|
|
|
|
list = append(list, *nr)
|
2015-11-10 03:57:06 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 22:52:49 -04:00
|
|
|
list, err = filterNetworks(list, netFilters)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-09-25 06:19:17 -04:00
|
|
|
return httputils.WriteJSON(w, http.StatusOK, list)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-19 06:04:26 -05:00
|
|
|
term := vars["id"]
|
2017-03-09 14:42:10 -05:00
|
|
|
var (
|
|
|
|
verbose bool
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if v := r.URL.Query().Get("verbose"); v != "" {
|
|
|
|
if verbose, err = strconv.ParseBool(v); err != nil {
|
|
|
|
err = fmt.Errorf("invalid value for verbose: %s", v)
|
|
|
|
return errors.NewBadRequestError(err)
|
|
|
|
}
|
|
|
|
}
|
2017-01-19 06:04:26 -05:00
|
|
|
|
|
|
|
// In case multiple networks have duplicate names, return error.
|
|
|
|
// TODO (yongtang): should we wrap with version here for backward compatibility?
|
|
|
|
|
|
|
|
// First find based on full ID, return immediately once one is found.
|
|
|
|
// If a network appears both in swarm and local, assume it is in local first
|
|
|
|
|
|
|
|
// For full name and partial ID, save the result first, and process later
|
|
|
|
// in case multiple records was found based on the same term
|
|
|
|
listByFullName := map[string]types.NetworkResource{}
|
|
|
|
listByPartialID := map[string]types.NetworkResource{}
|
|
|
|
|
|
|
|
nw := n.backend.GetNetworks()
|
|
|
|
for _, network := range nw {
|
|
|
|
if network.ID() == term {
|
2017-03-09 14:42:10 -05:00
|
|
|
return httputils.WriteJSON(w, http.StatusOK, *n.buildDetailedNetworkResources(network, verbose))
|
2017-01-19 06:04:26 -05:00
|
|
|
}
|
|
|
|
if network.Name() == term {
|
|
|
|
// No need to check the ID collision here as we are still in
|
|
|
|
// local scope and the network ID is unique in this scope.
|
2017-03-09 14:42:10 -05:00
|
|
|
listByFullName[network.ID()] = *n.buildDetailedNetworkResources(network, verbose)
|
2017-01-19 06:04:26 -05:00
|
|
|
}
|
|
|
|
if strings.HasPrefix(network.ID(), term) {
|
|
|
|
// No need to check the ID collision here as we are still in
|
|
|
|
// local scope and the network ID is unique in this scope.
|
2017-03-09 14:42:10 -05:00
|
|
|
listByPartialID[network.ID()] = *n.buildDetailedNetworkResources(network, verbose)
|
2017-01-19 06:04:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nr, _ := n.cluster.GetNetworks()
|
|
|
|
for _, network := range nr {
|
|
|
|
if network.ID == term {
|
|
|
|
return httputils.WriteJSON(w, http.StatusOK, network)
|
|
|
|
}
|
|
|
|
if network.Name == term {
|
|
|
|
// Check the ID collision as we are in swarm scope here, and
|
|
|
|
// the map (of the listByFullName) may have already had a
|
|
|
|
// network with the same ID (from local scope previously)
|
|
|
|
if _, ok := listByFullName[network.ID]; !ok {
|
|
|
|
listByFullName[network.ID] = network
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(network.ID, term) {
|
|
|
|
// Check the ID collision as we are in swarm scope here, and
|
|
|
|
// the map (of the listByPartialID) may have already had a
|
|
|
|
// network with the same ID (from local scope previously)
|
|
|
|
if _, ok := listByPartialID[network.ID]; !ok {
|
|
|
|
listByPartialID[network.ID] = network
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find based on full name, returns true only if no duplicates
|
|
|
|
if len(listByFullName) == 1 {
|
|
|
|
for _, v := range listByFullName {
|
|
|
|
return httputils.WriteJSON(w, http.StatusOK, v)
|
2016-06-13 22:52:49 -04:00
|
|
|
}
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
2017-01-19 06:04:26 -05:00
|
|
|
if len(listByFullName) > 1 {
|
|
|
|
return fmt.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find based on partial ID, returns true only if no duplicates
|
|
|
|
if len(listByPartialID) == 1 {
|
|
|
|
for _, v := range listByPartialID {
|
|
|
|
return httputils.WriteJSON(w, http.StatusOK, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(listByPartialID) > 1 {
|
|
|
|
return fmt.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID))
|
|
|
|
}
|
|
|
|
|
|
|
|
return libnetwork.ErrNoSuchNetwork(term)
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
2016-04-13 04:33:46 -04:00
|
|
|
var create types.NetworkCreateRequest
|
2015-09-25 06:19:17 -04:00
|
|
|
|
|
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := httputils.CheckForJSON(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&create); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-12-26 07:53:13 -05:00
|
|
|
if nws, err := n.cluster.GetNetworksByName(create.Name); err == nil && len(nws) > 0 {
|
2016-06-29 21:08:55 -04:00
|
|
|
return libnetwork.NetworkNameError(create.Name)
|
|
|
|
}
|
|
|
|
|
2016-03-28 13:41:06 -04:00
|
|
|
nw, err := n.backend.CreateNetwork(create)
|
2015-09-25 06:19:17 -04:00
|
|
|
if err != nil {
|
2017-01-19 01:49:10 -05:00
|
|
|
var warning string
|
|
|
|
if _, ok := err.(libnetwork.NetworkNameError); ok {
|
|
|
|
// check if user defined CheckDuplicate, if set true, return err
|
|
|
|
// otherwise prepare a warning message
|
|
|
|
if create.CheckDuplicate {
|
|
|
|
return libnetwork.NetworkNameError(create.Name)
|
|
|
|
}
|
|
|
|
warning = libnetwork.NetworkNameError(create.Name).Error()
|
|
|
|
}
|
|
|
|
|
2016-06-13 22:52:49 -04:00
|
|
|
if _, ok := err.(libnetwork.ManagerRedirectError); !ok {
|
|
|
|
return err
|
|
|
|
}
|
2016-12-26 07:53:13 -05:00
|
|
|
id, err := n.cluster.CreateNetwork(create)
|
2016-06-13 22:52:49 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-01-19 01:49:10 -05:00
|
|
|
nw = &types.NetworkCreateResponse{
|
|
|
|
ID: id,
|
|
|
|
Warning: warning,
|
|
|
|
}
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
2016-03-28 13:41:06 -04:00
|
|
|
return httputils.WriteJSON(w, http.StatusCreated, nw)
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
var connect types.NetworkConnect
|
|
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := httputils.CheckForJSON(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&connect); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-08-23 19:50:15 -04:00
|
|
|
return n.backend.ConnectContainerToNetwork(connect.Container, vars["id"], connect.EndpointConfig)
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
var disconnect types.NetworkDisconnect
|
|
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := httputils.CheckForJSON(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&disconnect); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-08-26 16:08:28 -04:00
|
|
|
return n.backend.DisconnectContainerFromNetwork(disconnect.Container, vars["id"], disconnect.Force)
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *networkRouter) deleteNetwork(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
2016-03-05 11:41:51 -05:00
|
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-12-26 07:53:13 -05:00
|
|
|
if _, err := n.cluster.GetNetwork(vars["id"]); err == nil {
|
|
|
|
if err = n.cluster.RemoveNetwork(vars["id"]); err != nil {
|
2016-09-27 14:04:36 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
w.WriteHeader(http.StatusNoContent)
|
|
|
|
return nil
|
2016-06-13 22:52:49 -04:00
|
|
|
}
|
2016-03-05 11:41:51 -05:00
|
|
|
if err := n.backend.DeleteNetwork(vars["id"]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
w.WriteHeader(http.StatusNoContent)
|
|
|
|
return nil
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
2016-06-13 22:52:49 -04:00
|
|
|
func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.NetworkResource {
|
2015-09-25 06:19:17 -04:00
|
|
|
r := &types.NetworkResource{}
|
|
|
|
if nw == nil {
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2016-03-16 17:52:34 -04:00
|
|
|
info := nw.Info()
|
2015-09-25 06:19:17 -04:00
|
|
|
r.Name = nw.Name()
|
|
|
|
r.ID = nw.ID()
|
2016-08-30 00:53:16 -04:00
|
|
|
r.Created = info.Created()
|
2016-03-16 17:52:34 -04:00
|
|
|
r.Scope = info.Scope()
|
2016-12-26 07:53:13 -05:00
|
|
|
if n.cluster.IsManager() {
|
2017-01-18 10:48:09 -05:00
|
|
|
if _, err := n.cluster.GetNetwork(nw.ID()); err == nil {
|
2016-06-13 22:52:49 -04:00
|
|
|
r.Scope = "swarm"
|
|
|
|
}
|
|
|
|
} else if info.Dynamic() {
|
|
|
|
r.Scope = "swarm"
|
|
|
|
}
|
2015-09-25 06:19:17 -04:00
|
|
|
r.Driver = nw.Type()
|
2016-03-16 17:52:34 -04:00
|
|
|
r.EnableIPv6 = info.IPv6Enabled()
|
|
|
|
r.Internal = info.Internal()
|
2016-11-22 14:33:00 -05:00
|
|
|
r.Attachable = info.Attachable()
|
2016-03-16 17:52:34 -04:00
|
|
|
r.Options = info.DriverOptions()
|
2015-09-25 06:19:17 -04:00
|
|
|
r.Containers = make(map[string]types.EndpointResource)
|
2016-03-16 17:52:34 -04:00
|
|
|
buildIpamResources(r, info)
|
|
|
|
r.Labels = info.Labels()
|
2015-10-09 14:21:48 -04:00
|
|
|
|
2016-11-04 15:27:36 -04:00
|
|
|
peers := info.Peers()
|
|
|
|
if len(peers) != 0 {
|
|
|
|
r.Peers = buildPeerInfoResources(peers)
|
|
|
|
}
|
|
|
|
|
2017-02-02 08:48:53 -05:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2017-03-09 14:42:10 -05:00
|
|
|
func (n *networkRouter) buildDetailedNetworkResources(nw libnetwork.Network, verbose bool) *types.NetworkResource {
|
2017-02-02 08:48:53 -05:00
|
|
|
if nw == nil {
|
|
|
|
return &types.NetworkResource{}
|
|
|
|
}
|
|
|
|
|
|
|
|
r := n.buildNetworkResource(nw)
|
2015-09-25 06:19:17 -04:00
|
|
|
epl := nw.Endpoints()
|
|
|
|
for _, e := range epl {
|
2015-11-03 17:15:34 -05:00
|
|
|
ei := e.Info()
|
|
|
|
if ei == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
sb := ei.Sandbox()
|
2016-07-06 05:54:46 -04:00
|
|
|
tmpID := e.ID()
|
|
|
|
key := "ep-" + tmpID
|
2016-03-12 16:29:25 -05:00
|
|
|
if sb != nil {
|
|
|
|
key = sb.ContainerID()
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
2016-07-06 05:54:46 -04:00
|
|
|
r.Containers[key] = buildEndpointResource(tmpID, e.Name(), ei)
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
2017-03-09 14:42:10 -05:00
|
|
|
if !verbose {
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
services := nw.Info().Services()
|
|
|
|
r.Services = make(map[string]network.ServiceInfo)
|
|
|
|
for name, service := range services {
|
|
|
|
tasks := []network.Task{}
|
|
|
|
for _, t := range service.Tasks {
|
|
|
|
tasks = append(tasks, network.Task{
|
|
|
|
Name: t.Name,
|
|
|
|
EndpointID: t.EndpointID,
|
|
|
|
EndpointIP: t.EndpointIP,
|
|
|
|
Info: t.Info,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
r.Services[name] = network.ServiceInfo{
|
|
|
|
VIP: service.VIP,
|
|
|
|
Ports: service.Ports,
|
|
|
|
Tasks: tasks,
|
|
|
|
LocalLBIndex: service.LocalLBIndex,
|
|
|
|
}
|
|
|
|
}
|
2015-09-25 06:19:17 -04:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2016-11-04 15:27:36 -04:00
|
|
|
func buildPeerInfoResources(peers []networkdb.PeerInfo) []network.PeerInfo {
|
|
|
|
peerInfo := make([]network.PeerInfo, 0, len(peers))
|
|
|
|
for _, peer := range peers {
|
|
|
|
peerInfo = append(peerInfo, network.PeerInfo{
|
|
|
|
Name: peer.Name,
|
|
|
|
IP: peer.IP,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return peerInfo
|
|
|
|
}
|
|
|
|
|
2016-03-16 17:52:34 -04:00
|
|
|
func buildIpamResources(r *types.NetworkResource, nwInfo libnetwork.NetworkInfo) {
|
|
|
|
id, opts, ipv4conf, ipv6conf := nwInfo.IpamConfig()
|
2015-10-09 14:21:48 -04:00
|
|
|
|
2016-03-16 17:52:34 -04:00
|
|
|
ipv4Info, ipv6Info := nwInfo.IpamInfo()
|
2015-12-27 23:56:57 -05:00
|
|
|
|
2015-10-09 14:21:48 -04:00
|
|
|
r.IPAM.Driver = id
|
|
|
|
|
2015-10-23 15:28:39 -04:00
|
|
|
r.IPAM.Options = opts
|
|
|
|
|
2015-10-09 14:21:48 -04:00
|
|
|
r.IPAM.Config = []network.IPAMConfig{}
|
|
|
|
for _, ip4 := range ipv4conf {
|
2015-12-27 23:56:57 -05:00
|
|
|
if ip4.PreferredPool == "" {
|
|
|
|
continue
|
|
|
|
}
|
2015-10-09 14:21:48 -04:00
|
|
|
iData := network.IPAMConfig{}
|
|
|
|
iData.Subnet = ip4.PreferredPool
|
|
|
|
iData.IPRange = ip4.SubPool
|
|
|
|
iData.Gateway = ip4.Gateway
|
|
|
|
iData.AuxAddress = ip4.AuxAddresses
|
|
|
|
r.IPAM.Config = append(r.IPAM.Config, iData)
|
|
|
|
}
|
|
|
|
|
2015-12-27 23:56:57 -05:00
|
|
|
if len(r.IPAM.Config) == 0 {
|
|
|
|
for _, ip4Info := range ipv4Info {
|
|
|
|
iData := network.IPAMConfig{}
|
|
|
|
iData.Subnet = ip4Info.IPAMData.Pool.String()
|
2016-08-11 21:08:54 -04:00
|
|
|
iData.Gateway = ip4Info.IPAMData.Gateway.IP.String()
|
2015-12-27 23:56:57 -05:00
|
|
|
r.IPAM.Config = append(r.IPAM.Config, iData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hasIpv6Conf := false
|
2015-10-09 14:21:48 -04:00
|
|
|
for _, ip6 := range ipv6conf {
|
2015-12-27 23:56:57 -05:00
|
|
|
if ip6.PreferredPool == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
hasIpv6Conf = true
|
2015-10-09 14:21:48 -04:00
|
|
|
iData := network.IPAMConfig{}
|
|
|
|
iData.Subnet = ip6.PreferredPool
|
|
|
|
iData.IPRange = ip6.SubPool
|
|
|
|
iData.Gateway = ip6.Gateway
|
|
|
|
iData.AuxAddress = ip6.AuxAddresses
|
|
|
|
r.IPAM.Config = append(r.IPAM.Config, iData)
|
|
|
|
}
|
2015-12-27 23:56:57 -05:00
|
|
|
|
|
|
|
if !hasIpv6Conf {
|
|
|
|
for _, ip6Info := range ipv6Info {
|
|
|
|
iData := network.IPAMConfig{}
|
|
|
|
iData.Subnet = ip6Info.IPAMData.Pool.String()
|
|
|
|
iData.Gateway = ip6Info.IPAMData.Gateway.String()
|
|
|
|
r.IPAM.Config = append(r.IPAM.Config, iData)
|
|
|
|
}
|
|
|
|
}
|
2015-10-09 14:21:48 -04:00
|
|
|
}
|
|
|
|
|
2016-07-06 05:54:46 -04:00
|
|
|
func buildEndpointResource(id string, name string, info libnetwork.EndpointInfo) types.EndpointResource {
|
2015-09-25 06:19:17 -04:00
|
|
|
er := types.EndpointResource{}
|
|
|
|
|
2016-07-06 05:54:46 -04:00
|
|
|
er.EndpointID = id
|
|
|
|
er.Name = name
|
|
|
|
ei := info
|
2015-11-03 17:15:34 -05:00
|
|
|
if ei == nil {
|
|
|
|
return er
|
|
|
|
}
|
|
|
|
|
|
|
|
if iface := ei.Iface(); iface != nil {
|
2015-09-25 06:19:17 -04:00
|
|
|
if mac := iface.MacAddress(); mac != nil {
|
|
|
|
er.MacAddress = mac.String()
|
|
|
|
}
|
2015-10-10 12:43:03 -04:00
|
|
|
if ip := iface.Address(); ip != nil && len(ip.IP) > 0 {
|
|
|
|
er.IPv4Address = ip.String()
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
2015-10-10 12:43:03 -04:00
|
|
|
if ipv6 := iface.AddressIPv6(); ipv6 != nil && len(ipv6.IP) > 0 {
|
|
|
|
er.IPv6Address = ipv6.String()
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return er
|
|
|
|
}
|
2016-10-18 00:36:52 -04:00
|
|
|
|
|
|
|
func (n *networkRouter) postNetworksPrune(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-12-07 17:02:13 -05:00
|
|
|
pruneFilters, err := filters.FromParam(r.Form.Get("filters"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pruneReport, err := n.backend.NetworksPrune(pruneFilters)
|
2016-10-18 00:36:52 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return httputils.WriteJSON(w, http.StatusOK, pruneReport)
|
|
|
|
}
|