add CheckDuplicate docs and logics in network
Signed-off-by: allencloud <allen.sun@daocloud.io>
This commit is contained in:
parent
58152530cc
commit
94b880f919
8 changed files with 48 additions and 6 deletions
|
@ -181,6 +181,16 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
|
||||||
|
|
||||||
nw, err := n.backend.CreateNetwork(create)
|
nw, err := n.backend.CreateNetwork(create)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := err.(libnetwork.ManagerRedirectError); !ok {
|
if _, ok := err.(libnetwork.ManagerRedirectError); !ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -188,7 +198,10 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nw = &types.NetworkCreateResponse{ID: id}
|
nw = &types.NetworkCreateResponse{
|
||||||
|
ID: id,
|
||||||
|
Warning: warning,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return httputils.WriteJSON(w, http.StatusCreated, nw)
|
return httputils.WriteJSON(w, http.StatusCreated, nw)
|
||||||
|
|
|
@ -6218,7 +6218,7 @@ paths:
|
||||||
description: "The network's name."
|
description: "The network's name."
|
||||||
type: "string"
|
type: "string"
|
||||||
CheckDuplicate:
|
CheckDuplicate:
|
||||||
description: "Check for networks with duplicate names."
|
description: "Check for networks with duplicate names. Since Network is primarily keyed based on a random ID and not on the name, and network name is strictly a user-friendly alias to the network which is uniquely identified using ID, there is no guaranteed way to check for duplicates. CheckDuplicate is there to provide a best effort checking of any networks which has the same name but it is not guaranteed to catch all name collisions."
|
||||||
type: "boolean"
|
type: "boolean"
|
||||||
Driver:
|
Driver:
|
||||||
description: "Name of the network driver plugin to use."
|
description: "Name of the network driver plugin to use."
|
||||||
|
|
|
@ -416,6 +416,13 @@ type EndpointResource struct {
|
||||||
|
|
||||||
// NetworkCreate is the expected body of the "create network" http request message
|
// NetworkCreate is the expected body of the "create network" http request message
|
||||||
type NetworkCreate struct {
|
type NetworkCreate struct {
|
||||||
|
// Check for networks with duplicate names.
|
||||||
|
// Network is primarily keyed based on a random ID and not on the name.
|
||||||
|
// Network name is strictly a user-friendly alias to the network
|
||||||
|
// which is uniquely identified using ID.
|
||||||
|
// And there is no guaranteed way to check for duplicates.
|
||||||
|
// Option CheckDuplicate is there to provide a best effort checking of any networks
|
||||||
|
// which has the same name but it is not guaranteed to catch all name collisions.
|
||||||
CheckDuplicate bool
|
CheckDuplicate bool
|
||||||
Driver string
|
Driver string
|
||||||
EnableIPv6 bool
|
EnableIPv6 bool
|
||||||
|
|
|
@ -248,6 +248,8 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nw != nil {
|
if nw != nil {
|
||||||
|
// check if user defined CheckDuplicate, if set true, return err
|
||||||
|
// otherwise prepare a warning message
|
||||||
if create.CheckDuplicate {
|
if create.CheckDuplicate {
|
||||||
return nil, libnetwork.NetworkNameError(create.Name)
|
return nil, libnetwork.NetworkNameError(create.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2836,7 +2836,12 @@ Content-Type: application/json
|
||||||
**JSON parameters**:
|
**JSON parameters**:
|
||||||
|
|
||||||
- **Name** - The new network's name. this is a mandatory field
|
- **Name** - The new network's name. this is a mandatory field
|
||||||
- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false`
|
- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false`.
|
||||||
|
Since Network is primarily keyed based on a random ID and not on the name,
|
||||||
|
and network name is strictly a user-friendly alias to the network which is uniquely identified using ID,
|
||||||
|
there is no guaranteed way to check for duplicates across a cluster of docker hosts.
|
||||||
|
This parameter CheckDuplicate is there to provide a best effort checking of any networks
|
||||||
|
which has the same name but it is not guaranteed to catch all name collisions.
|
||||||
- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver
|
- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver
|
||||||
- **IPAM** - Optional custom IP scheme for the network
|
- **IPAM** - Optional custom IP scheme for the network
|
||||||
- **Driver** - Name of the IPAM driver to use. Defaults to `default` driver
|
- **Driver** - Name of the IPAM driver to use. Defaults to `default` driver
|
||||||
|
|
|
@ -3165,7 +3165,12 @@ Content-Type: application/json
|
||||||
**JSON parameters**:
|
**JSON parameters**:
|
||||||
|
|
||||||
- **Name** - The new network's name. this is a mandatory field
|
- **Name** - The new network's name. this is a mandatory field
|
||||||
- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false`
|
- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false`.
|
||||||
|
Since Network is primarily keyed based on a random ID and not on the name,
|
||||||
|
and network name is strictly a user-friendly alias to the network
|
||||||
|
which is uniquely identified using ID, there is no guaranteed way to check for duplicates.
|
||||||
|
This parameter CheckDuplicate is there to provide a best effort checking of any networks
|
||||||
|
which has the same name but it is not guaranteed to catch all name collisions.
|
||||||
- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver
|
- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver
|
||||||
- **IPAM** - Optional custom IP scheme for the network
|
- **IPAM** - Optional custom IP scheme for the network
|
||||||
- **Driver** - Name of the IPAM driver to use. Defaults to `default` driver
|
- **Driver** - Name of the IPAM driver to use. Defaults to `default` driver
|
||||||
|
|
|
@ -3279,7 +3279,12 @@ Content-Type: application/json
|
||||||
**JSON parameters**:
|
**JSON parameters**:
|
||||||
|
|
||||||
- **Name** - The new network's name. this is a mandatory field
|
- **Name** - The new network's name. this is a mandatory field
|
||||||
- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false`
|
- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false`.
|
||||||
|
Since Network is primarily keyed based on a random ID and not on the name,
|
||||||
|
and network name is strictly a user-friendly alias to the network
|
||||||
|
which is uniquely identified using ID, there is no guaranteed way to check for duplicates.
|
||||||
|
This parameter CheckDuplicate is there to provide a best effort checking of any networks
|
||||||
|
which has the same name but it is not guaranteed to catch all name collisions.
|
||||||
- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver
|
- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver
|
||||||
- **Internal** - Restrict external access to the network
|
- **Internal** - Restrict external access to the network
|
||||||
- **IPAM** - Optional custom IP scheme for the network
|
- **IPAM** - Optional custom IP scheme for the network
|
||||||
|
|
|
@ -3344,7 +3344,12 @@ Content-Type: application/json
|
||||||
**JSON parameters**:
|
**JSON parameters**:
|
||||||
|
|
||||||
- **Name** - The new network's name. this is a mandatory field
|
- **Name** - The new network's name. this is a mandatory field
|
||||||
- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false`
|
- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false`.
|
||||||
|
Since Network is primarily keyed based on a random ID and not on the name,
|
||||||
|
and network name is strictly a user-friendly alias to the network
|
||||||
|
which is uniquely identified using ID, there is no guaranteed way to check for duplicates.
|
||||||
|
This parameter CheckDuplicate is there to provide a best effort checking of any networks
|
||||||
|
which has the same name but it is not guaranteed to catch all name collisions.
|
||||||
- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver
|
- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver
|
||||||
- **Internal** - Restrict external access to the network
|
- **Internal** - Restrict external access to the network
|
||||||
- **IPAM** - Optional custom IP scheme for the network
|
- **IPAM** - Optional custom IP scheme for the network
|
||||||
|
|
Loading…
Add table
Reference in a new issue