commit
8c543556a3
7 changed files with 19 additions and 21 deletions
|
@ -279,8 +279,8 @@ func procCreateNetwork(c libnetwork.NetworkController, vars map[string]string, b
|
||||||
processCreateDefaults(c, &create)
|
processCreateDefaults(c, &create)
|
||||||
|
|
||||||
options := []libnetwork.NetworkOption{}
|
options := []libnetwork.NetworkOption{}
|
||||||
if len(create.Labels) > 0 {
|
if len(create.DriverOpts) > 0 {
|
||||||
options = append(options, libnetwork.NetworkOptionLabels(create.Labels))
|
options = append(options, libnetwork.NetworkOptionDriverOpts(create.DriverOpts))
|
||||||
}
|
}
|
||||||
nw, err := c.NewNetwork(create.NetworkType, create.Name, options...)
|
nw, err := c.NewNetwork(create.NetworkType, create.Name, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -229,7 +229,7 @@ func TestCreateDeleteNetwork(t *testing.T) {
|
||||||
bridge.BridgeName: "abc",
|
bridge.BridgeName: "abc",
|
||||||
netlabel.EnableIPv6: "true",
|
netlabel.EnableIPv6: "true",
|
||||||
}
|
}
|
||||||
nc := networkCreate{Name: "network_1", NetworkType: bridgeNetType, Labels: ops}
|
nc := networkCreate{Name: "network_1", NetworkType: bridgeNetType, DriverOpts: ops}
|
||||||
goodBody, err := json.Marshal(nc)
|
goodBody, err := json.Marshal(nc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -263,7 +263,7 @@ func TestCreateDeleteNetwork(t *testing.T) {
|
||||||
netlabel.EnableIPv6: "true",
|
netlabel.EnableIPv6: "true",
|
||||||
bridge.BridgeName: "abc",
|
bridge.BridgeName: "abc",
|
||||||
}
|
}
|
||||||
nc = networkCreate{Name: "network_2", NetworkType: bridgeNetType, Labels: labels}
|
nc = networkCreate{Name: "network_2", NetworkType: bridgeNetType, DriverOpts: labels}
|
||||||
goodBody, err = json.Marshal(nc)
|
goodBody, err = json.Marshal(nc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -297,7 +297,7 @@ func TestGetNetworksAndEndpoints(t *testing.T) {
|
||||||
ops := map[string]string{
|
ops := map[string]string{
|
||||||
bridge.BridgeName: "api_test_nw",
|
bridge.BridgeName: "api_test_nw",
|
||||||
}
|
}
|
||||||
nc := networkCreate{Name: "sh", NetworkType: bridgeNetType, Labels: ops}
|
nc := networkCreate{Name: "sh", NetworkType: bridgeNetType, DriverOpts: ops}
|
||||||
body, err := json.Marshal(nc)
|
body, err := json.Marshal(nc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1837,7 +1837,7 @@ func TestEndToEnd(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create network
|
// Create network
|
||||||
nc := networkCreate{Name: "network-fiftyfive", NetworkType: bridgeNetType, Labels: ops}
|
nc := networkCreate{Name: "network-fiftyfive", NetworkType: bridgeNetType, DriverOpts: ops}
|
||||||
body, err := json.Marshal(nc)
|
body, err := json.Marshal(nc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -36,7 +36,7 @@ type sandboxResource struct {
|
||||||
type networkCreate struct {
|
type networkCreate struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
NetworkType string `json:"network_type"`
|
NetworkType string `json:"network_type"`
|
||||||
Labels map[string]string `json:"labels"`
|
DriverOpts map[string]string `json:"driver_opts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// endpointCreate represents the body of the "create endpoint" http request message
|
// endpointCreate represents the body of the "create endpoint" http request message
|
||||||
|
|
|
@ -48,8 +48,8 @@ func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct network create request body
|
// Construct network create request body
|
||||||
var labels []string
|
var driverOpts []string
|
||||||
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, Labels: labels}
|
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, DriverOpts: driverOpts}
|
||||||
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
|
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -36,7 +36,7 @@ type SandboxResource struct {
|
||||||
type networkCreate struct {
|
type networkCreate struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
NetworkType string `json:"network_type"`
|
NetworkType string `json:"network_type"`
|
||||||
Labels []string `json:"labels"`
|
DriverOpts []string `json:"driver_opts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// serviceCreate represents the body of the "publish service" http request message
|
// serviceCreate represents the body of the "publish service" http request message
|
||||||
|
|
|
@ -74,7 +74,6 @@ type NetworkController interface {
|
||||||
Config() config.Config
|
Config() config.Config
|
||||||
|
|
||||||
// Create a new network. The options parameter carries network specific options.
|
// Create a new network. The options parameter carries network specific options.
|
||||||
// Labels support will be added in the near future.
|
|
||||||
NewNetwork(networkType, name string, options ...NetworkOption) (Network, error)
|
NewNetwork(networkType, name string, options ...NetworkOption) (Network, error)
|
||||||
|
|
||||||
// Networks returns the list of Network(s) managed by this controller.
|
// Networks returns the list of Network(s) managed by this controller.
|
||||||
|
|
|
@ -33,7 +33,6 @@ type Network interface {
|
||||||
|
|
||||||
// Create a new endpoint to this network symbolically identified by the
|
// Create a new endpoint to this network symbolically identified by the
|
||||||
// specified unique name. The options parameter carry driver specific options.
|
// specified unique name. The options parameter carry driver specific options.
|
||||||
// Labels support will be added in the near future.
|
|
||||||
CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error)
|
CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error)
|
||||||
|
|
||||||
// Delete the network.
|
// Delete the network.
|
||||||
|
@ -58,7 +57,7 @@ type Network interface {
|
||||||
// NetworkInfo returns some configuration and operational information about the network
|
// NetworkInfo returns some configuration and operational information about the network
|
||||||
type NetworkInfo interface {
|
type NetworkInfo interface {
|
||||||
IpamConfig() (string, []*IpamConf, []*IpamConf)
|
IpamConfig() (string, []*IpamConf, []*IpamConf)
|
||||||
Labels() map[string]string
|
DriverOptions() map[string]string
|
||||||
Scope() string
|
Scope() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +401,7 @@ func (n *network) UnmarshalJSON(b []byte) (err error) {
|
||||||
|
|
||||||
if v, ok := netMap["generic"]; ok {
|
if v, ok := netMap["generic"]; ok {
|
||||||
n.generic = v.(map[string]interface{})
|
n.generic = v.(map[string]interface{})
|
||||||
// Restore labels in their map[string]string form
|
// Restore opts in their map[string]string form
|
||||||
if v, ok := n.generic[netlabel.GenericData]; ok {
|
if v, ok := n.generic[netlabel.GenericData]; ok {
|
||||||
var lmap map[string]string
|
var lmap map[string]string
|
||||||
ba, err := json.Marshal(v)
|
ba, err := json.Marshal(v)
|
||||||
|
@ -484,19 +483,19 @@ func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkOptionLabels function returns an option setter for any parameter described by a map
|
// NetworkOptionDriverOpts function returns an option setter for any parameter described by a map
|
||||||
func NetworkOptionLabels(labels map[string]string) NetworkOption {
|
func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
|
||||||
return func(n *network) {
|
return func(n *network) {
|
||||||
if n.generic == nil {
|
if n.generic == nil {
|
||||||
n.generic = make(map[string]interface{})
|
n.generic = make(map[string]interface{})
|
||||||
}
|
}
|
||||||
if labels == nil {
|
if opts == nil {
|
||||||
labels = make(map[string]string)
|
opts = make(map[string]string)
|
||||||
}
|
}
|
||||||
// Store the options
|
// Store the options
|
||||||
n.generic[netlabel.GenericData] = labels
|
n.generic[netlabel.GenericData] = opts
|
||||||
// Decode and store the endpoint options of libnetwork interest
|
// Decode and store the endpoint options of libnetwork interest
|
||||||
if val, ok := labels[netlabel.EnableIPv6]; ok {
|
if val, ok := opts[netlabel.EnableIPv6]; ok {
|
||||||
var err error
|
var err error
|
||||||
if n.enableIPv6, err = strconv.ParseBool(val); err != nil {
|
if n.enableIPv6, err = strconv.ParseBool(val); err != nil {
|
||||||
log.Warnf("Failed to parse %s' value: %s (%s)", netlabel.EnableIPv6, val, err.Error())
|
log.Warnf("Failed to parse %s' value: %s (%s)", netlabel.EnableIPv6, val, err.Error())
|
||||||
|
@ -1056,7 +1055,7 @@ func (n *network) Info() NetworkInfo {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *network) Labels() map[string]string {
|
func (n *network) DriverOptions() map[string]string {
|
||||||
n.Lock()
|
n.Lock()
|
||||||
defer n.Unlock()
|
defer n.Unlock()
|
||||||
if n.generic != nil {
|
if n.generic != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue