mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00
podman network inspect: include running containers
Like docker podman network inspect should output the information of running container with their ip/mac address on this network. However the output format is not docker compatible as this cannot include all the info we have and the previous output was already not compatible so this is not new. New example output: ``` [ { ... "containers": { "7c0d295779cee4a6db7adc07a99e635909413a390eeab9f951edbc4aac406bf1": { "name": "c2", "interfaces": { "eth0": { "subnets": [ { "ipnet": "10.89.0.4/24", "gateway": "10.89.0.1" }, { "ipnet": "fda3:b4da:da1e:7e9d::4/64", "gateway": "fda3:b4da:da1e:7e9d::1" } ], "mac_address": "1a:bd:ca:ea:4b:3a" } } }, "b17c6651ae6d9cc7d5825968e01d6b1e67f44460bb0c140bcc32bd9d436ac11d": { "name": "c1", "interfaces": { "eth0": { "subnets": [ { "ipnet": "10.89.0.3/24", "gateway": "10.89.0.1" }, { "ipnet": "fda3:b4da:da1e:7e9d::3/64", "gateway": "fda3:b4da:da1e:7e9d::1" } ], "mac_address": "f6:50:e6:22:d9:55" } } } } } ] ``` Fixes #14126 Fixes https://issues.redhat.com/browse/RHEL-3153 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -22,36 +22,6 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type containerNetStatus struct {
|
||||
name string
|
||||
id string
|
||||
status map[string]nettypes.StatusBlock
|
||||
}
|
||||
|
||||
func getContainerNetStatuses(rt *libpod.Runtime) ([]containerNetStatus, error) {
|
||||
cons, err := rt.GetAllContainers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
statuses := make([]containerNetStatus, 0, len(cons))
|
||||
for _, con := range cons {
|
||||
status, err := con.GetNetworkStatus()
|
||||
if err != nil {
|
||||
if errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, define.ErrCtrRemoved) {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
statuses = append(statuses, containerNetStatus{
|
||||
id: con.ID(),
|
||||
name: con.Name(),
|
||||
status: status,
|
||||
})
|
||||
}
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
func normalizeNetworkName(rt *libpod.Runtime, name string) (string, bool) {
|
||||
if name == nettypes.BridgeNetworkDriver {
|
||||
return rt.Network().DefaultNetworkName(), true
|
||||
@ -86,7 +56,8 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
utils.NetworkNotFound(w, name, err)
|
||||
return
|
||||
}
|
||||
statuses, err := getContainerNetStatuses(runtime)
|
||||
ic := abi.ContainerEngine{Libpod: runtime}
|
||||
statuses, err := ic.GetContainerNetStatuses()
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
@ -95,10 +66,10 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
utils.WriteResponse(w, http.StatusOK, report)
|
||||
}
|
||||
|
||||
func convertLibpodNetworktoDockerNetwork(runtime *libpod.Runtime, statuses []containerNetStatus, network *nettypes.Network, changeDefaultName bool) *types.NetworkResource {
|
||||
func convertLibpodNetworktoDockerNetwork(runtime *libpod.Runtime, statuses []abi.ContainerNetStatus, network *nettypes.Network, changeDefaultName bool) *types.NetworkResource {
|
||||
containerEndpoints := make(map[string]types.EndpointResource, len(statuses))
|
||||
for _, st := range statuses {
|
||||
if netData, ok := st.status[network.Name]; ok {
|
||||
if netData, ok := st.Status[network.Name]; ok {
|
||||
ipv4Address := ""
|
||||
ipv6Address := ""
|
||||
macAddr := ""
|
||||
@ -116,12 +87,12 @@ func convertLibpodNetworktoDockerNetwork(runtime *libpod.Runtime, statuses []con
|
||||
break
|
||||
}
|
||||
containerEndpoint := types.EndpointResource{
|
||||
Name: st.name,
|
||||
Name: st.Name,
|
||||
MacAddress: macAddr,
|
||||
IPv4Address: ipv4Address,
|
||||
IPv6Address: ipv6Address,
|
||||
}
|
||||
containerEndpoints[st.id] = containerEndpoint
|
||||
containerEndpoints[st.ID] = containerEndpoint
|
||||
}
|
||||
}
|
||||
ipamConfigs := make([]dockerNetwork.IPAMConfig, 0, len(network.Subnets))
|
||||
@ -192,7 +163,7 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
statuses, err := getContainerNetStatuses(runtime)
|
||||
statuses, err := ic.GetContainerNetStatuses()
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
|
@ -434,7 +434,7 @@ type networkRmResponse struct {
|
||||
// swagger:response
|
||||
type networkInspectResponse struct {
|
||||
// in:body
|
||||
Body types.Network
|
||||
Body entities.NetworkInspectReport
|
||||
}
|
||||
|
||||
// Network list
|
||||
|
Reference in New Issue
Block a user