Merge pull request #10919 from vikas-goel/macvlan
Return macvlan object in /network REST API response
This commit is contained in:
commit
1568247ec8
|
|
@ -25,6 +25,12 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type pluginInterface struct {
|
||||||
|
PluginType string `json:"type"`
|
||||||
|
IPAM network.IPAMConfig `json:"ipam"`
|
||||||
|
IsGW bool `json:"isGateway"`
|
||||||
|
}
|
||||||
|
|
||||||
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
|
|
||||||
|
|
@ -103,12 +109,12 @@ func getNetworkResourceByNameOrID(nameOrID string, runtime *libpod.Runtime, filt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No Bridge plugin means we bail
|
plugin, err := getPlugin(conf.Plugins)
|
||||||
bridge, err := genericPluginsToBridge(conf.Plugins, network.DefaultNetworkDriver)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, outer := range bridge.IPAM.Ranges {
|
|
||||||
|
for _, outer := range plugin.IPAM.Ranges {
|
||||||
for _, n := range outer {
|
for _, n := range outer {
|
||||||
ipamConfig := dockerNetwork.IPAMConfig{
|
ipamConfig := dockerNetwork.IPAMConfig{
|
||||||
Subnet: n.Subnet,
|
Subnet: n.Subnet,
|
||||||
|
|
@ -140,19 +146,26 @@ func getNetworkResourceByNameOrID(nameOrID string, runtime *libpod.Runtime, filt
|
||||||
labels = map[string]string{}
|
labels = map[string]string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isInternal := false
|
||||||
|
dockerDriver := plugin.PluginType
|
||||||
|
if plugin.PluginType == network.DefaultNetworkDriver {
|
||||||
|
isInternal = !plugin.IsGW
|
||||||
|
dockerDriver = "default"
|
||||||
|
}
|
||||||
|
|
||||||
report := types.NetworkResource{
|
report := types.NetworkResource{
|
||||||
Name: conf.Name,
|
Name: conf.Name,
|
||||||
ID: networkid.GetNetworkID(conf.Name),
|
ID: networkid.GetNetworkID(conf.Name),
|
||||||
Created: time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec)), // nolint: unconvert
|
Created: time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec)), // nolint: unconvert
|
||||||
Scope: "local",
|
Scope: "local",
|
||||||
Driver: network.DefaultNetworkDriver,
|
Driver: plugin.PluginType,
|
||||||
EnableIPv6: false,
|
EnableIPv6: false,
|
||||||
IPAM: dockerNetwork.IPAM{
|
IPAM: dockerNetwork.IPAM{
|
||||||
Driver: "default",
|
Driver: dockerDriver,
|
||||||
Options: map[string]string{},
|
Options: map[string]string{},
|
||||||
Config: ipamConfigs,
|
Config: ipamConfigs,
|
||||||
},
|
},
|
||||||
Internal: !bridge.IsGW,
|
Internal: isInternal,
|
||||||
Attachable: false,
|
Attachable: false,
|
||||||
Ingress: false,
|
Ingress: false,
|
||||||
ConfigFrom: dockerNetwork.ConfigReference{},
|
ConfigFrom: dockerNetwork.ConfigReference{},
|
||||||
|
|
@ -166,23 +179,19 @@ func getNetworkResourceByNameOrID(nameOrID string, runtime *libpod.Runtime, filt
|
||||||
return &report, nil
|
return &report, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genericPluginsToBridge(plugins []*libcni.NetworkConfig, pluginType string) (network.HostLocalBridge, error) {
|
func getPlugin(plugins []*libcni.NetworkConfig) (pluginInterface, error) {
|
||||||
var bridge network.HostLocalBridge
|
var plugin pluginInterface
|
||||||
generic, err := findPluginByName(plugins, pluginType)
|
|
||||||
if err != nil {
|
|
||||||
return bridge, err
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(generic, &bridge)
|
|
||||||
return bridge, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func findPluginByName(plugins []*libcni.NetworkConfig, pluginType string) ([]byte, error) {
|
|
||||||
for _, p := range plugins {
|
for _, p := range plugins {
|
||||||
if pluginType == p.Network.Type {
|
for _, pluginType := range network.SupportedNetworkDrivers {
|
||||||
return p.Bytes, nil
|
if pluginType == p.Network.Type {
|
||||||
|
err := json.Unmarshal(p.Bytes, &plugin)
|
||||||
|
return plugin, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, errors.New("unable to find bridge plugin")
|
|
||||||
|
return plugin, errors.New("unable to find supported plugin")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListNetworks(w http.ResponseWriter, r *http.Request) {
|
func ListNetworks(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -142,4 +142,18 @@ t GET networks?filters='{"label":["zaq"]}' 200 length=1
|
||||||
t POST networks/prune?filters='{"until":["5000000000"]}' 200
|
t POST networks/prune?filters='{"until":["5000000000"]}' 200
|
||||||
t GET networks?filters='{"label":["zaq"]}' 200 length=0
|
t GET networks?filters='{"label":["zaq"]}' 200 length=0
|
||||||
|
|
||||||
|
# test macvlan network response
|
||||||
|
podman network create --driver macvlan macvlan1
|
||||||
|
|
||||||
|
# libpod api inspect the macvlan network
|
||||||
|
t GET libpod/networks/macvlan1/json 200 .name="macvlan1"
|
||||||
|
|
||||||
|
# compat api inspect the macvlan network
|
||||||
|
t GET networks/macvlan1 200 .Name="macvlan1"
|
||||||
|
|
||||||
|
# clean the macvlan network
|
||||||
|
t DELETE libpod/networks/macvlan1 200 \
|
||||||
|
.[0].Name~macvlan1 \
|
||||||
|
.[0].Err=null
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue