mirror of
https://github.com/clearlinux/libnetwork.git
synced 2026-09-06 05:41:50 +00:00
Few changes to the UI and API implementation
1. replaced --net option for service UI with SERVICE.[NETWORK] format 2. Making using of the default network/driver backend support 3. NetworkName and NetworkType from the UI/API can be empty string and it will be replaced with DefaultNetwork and DefaultDriver As per the design goals, we wanted to keep libnetwork core free of handling defaults. Rather, the clients (docker & dnet) must handle the defaultness of these entities. Also, since there is no API to get these Default values from the backend, UI will not handle the default values either. Hence, this falls under the responsibility of the API layer to handle this specific case. Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
+34
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/docker/libnetwork/netlabel"
|
||||
"github.com/docker/libnetwork/types"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
@@ -39,6 +40,11 @@ const (
|
||||
urlEpID = "endpoint-id"
|
||||
urlEpPID = "endpoint-partial-id"
|
||||
urlCnID = "container-id"
|
||||
|
||||
// BridgeNetworkDriver is the built-in default for Network Driver
|
||||
BridgeNetworkDriver = "bridge"
|
||||
// BridgeDefaultNetwork is the built-in default for network name
|
||||
BridgeDefaultNetwork = "bridge"
|
||||
)
|
||||
|
||||
// NewHTTPHandler creates and initialize the HTTP handler to serve the requests for libnetwork
|
||||
@@ -246,6 +252,30 @@ func (ej *endpointJoin) parseOptions() []libnetwork.EndpointOption {
|
||||
Process functions
|
||||
*******************/
|
||||
|
||||
func processCreateDefaults(c libnetwork.NetworkController, nc *networkCreate) {
|
||||
if nc.NetworkType == "" {
|
||||
nc.NetworkType = c.Config().Daemon.DefaultDriver
|
||||
}
|
||||
if nc.NetworkType == BridgeNetworkDriver {
|
||||
if nc.Options == nil {
|
||||
nc.Options = make(map[string]interface{})
|
||||
}
|
||||
genericData, ok := nc.Options[netlabel.GenericData]
|
||||
if !ok {
|
||||
genericData = make(map[string]interface{})
|
||||
}
|
||||
gData := genericData.(map[string]interface{})
|
||||
|
||||
if _, ok := gData["BridgeName"]; !ok {
|
||||
gData["BridgeName"] = nc.Name
|
||||
}
|
||||
if _, ok := gData["AllowNonDefaultBridge"]; !ok {
|
||||
gData["AllowNonDefaultBridge"] = "true"
|
||||
}
|
||||
nc.Options[netlabel.GenericData] = genericData
|
||||
}
|
||||
}
|
||||
|
||||
/***************************
|
||||
NetworkController interface
|
||||
****************************/
|
||||
@@ -256,6 +286,7 @@ func procCreateNetwork(c libnetwork.NetworkController, vars map[string]string, b
|
||||
if err != nil {
|
||||
return "", &responseStatus{Status: "Invalid body: " + err.Error(), StatusCode: http.StatusBadRequest}
|
||||
}
|
||||
processCreateDefaults(c, &create)
|
||||
|
||||
nw, err := c.NewNetwork(create.NetworkType, create.Name, create.parseOptions()...)
|
||||
if err != nil {
|
||||
@@ -665,6 +696,9 @@ func findNetwork(c libnetwork.NetworkController, s string, by int) (libnetwork.N
|
||||
case byID:
|
||||
nw, err = c.NetworkByID(s)
|
||||
case byName:
|
||||
if s == "" {
|
||||
s = c.Config().Daemon.DefaultNetwork
|
||||
}
|
||||
nw, err = c.NetworkByName(s)
|
||||
default:
|
||||
panic(fmt.Sprintf("unexpected selector for network search: %d", by))
|
||||
|
||||
Reference in New Issue
Block a user