Go-based network automation with YANG models, gRPC, Ansible, Terraform, and Kubernetes integration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 lines
1 KiB
Go
36 lines
1 KiB
Go
package cni
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/containernetworking/cni/pkg/types"
|
|
)
|
|
|
|
// NetConf is the CNI network configuration parsed from the NetworkAttachmentDefinition.
|
|
type NetConf struct {
|
|
types.NetConf
|
|
|
|
// MeshConfig is the path to the mesh topology file (e.g., /etc/kedge/mesh.json).
|
|
MeshConfig string `json:"meshConfig"`
|
|
|
|
// UnderlayRoutes are subnets reachable via VLAN bridge interfaces (underlay mode).
|
|
UnderlayRoutes []SubnetRoute `json:"underlayRoutes,omitempty"`
|
|
|
|
// OverlayRoutes are subnets reachable via WireGuard/VXLAN tunnels (overlay mode).
|
|
OverlayRoutes []SubnetRoute `json:"overlayRoutes,omitempty"`
|
|
}
|
|
|
|
// SubnetRoute maps a destination CIDR to a network interface.
|
|
type SubnetRoute struct {
|
|
Dst string `json:"dst"` // e.g., "172.16.0.0/24"
|
|
Via string `json:"via"` // e.g., "vlan100" or "wg0"
|
|
}
|
|
|
|
// ParseNetConf parses the CNI network configuration from raw bytes.
|
|
func ParseNetConf(data []byte) (*NetConf, error) {
|
|
conf := &NetConf{}
|
|
if err := json.Unmarshal(data, conf); err != nil {
|
|
return nil, err
|
|
}
|
|
return conf, nil
|
|
}
|