(n *native.Network)
| 1177 | } |
| 1178 | |
| 1179 | func 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 | |
| 1222 | func parseMounts(nerdctlMounts string) ([]MountPoint, error) { |
| 1223 | var mounts []MountPoint |
no test coverage detected
searching dependent graphs…