MCPcopy Create free account
hub / github.com/containerd/nerdctl / NetworkFromNative

Function NetworkFromNative

pkg/inspecttypes/dockercompat/dockercompat.go:1179–1220  ·  view source on GitHub ↗
(n *native.Network)

Source from the content-addressed store, hash-verified

1177}
1178
1179func NetworkFromNative(n *native.Network) (*Network, error) {
1180 var res Network
1181
1182 sCNI := &structuredCNI{}
1183 err := json.Unmarshal(n.CNI, sCNI)
1184 if err != nil {
1185 return nil, err
1186 }
1187
1188 res.Name = sCNI.Name
1189 for _, plugin := range sCNI.Plugins {
1190 for _, ranges := range plugin.Ipam.Ranges {
1191 res.IPAM.Config = append(res.IPAM.Config, ranges...)
1192 }
1193 }
1194
1195 if n.NerdctlID != nil {
1196 res.ID = *n.NerdctlID
1197 }
1198
1199 if n.NerdctlLabels != nil {
1200 res.Labels = *n.NerdctlLabels
1201 }
1202
1203 // Parse network subnets for interface matching
1204 networkSubnets := parseNetworkSubnets(res.IPAM.Config)
1205
1206 res.Containers = make(map[string]EndpointResource)
1207 for _, container := range n.Containers {
1208 endpoint := EndpointResource{
1209 Name: container.Labels[labels.Name],
1210 }
1211
1212 if container.Process != nil && container.Process.NetNS != nil {
1213 populateEndpointFromNetNS(&endpoint, container.Process.NetNS.Interfaces, networkSubnets)
1214 }
1215
1216 res.Containers[container.ID] = endpoint
1217 }
1218
1219 return &res, nil
1220}
1221
1222func parseMounts(nerdctlMounts string) ([]MountPoint, error) {
1223 var mounts []MountPoint

Callers 1

InspectFunction · 0.92

Calls 3

parseNetworkSubnetsFunction · 0.85
UnmarshalMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…