Ejemplo n.º 1
0
func createCNIReply(ipamConf *ipam.IPAMRep) error {
	v6Routes := []cniTypes.Route{}
	v4Routes := []cniTypes.Route{}
	for _, r := range ipamConf.IP6.Routes {
		newRoute := cniTypes.Route{
			Dst: r.Destination,
		}
		if r.NextHop != nil {
			newRoute.GW = r.NextHop
		}
		v6Routes = append(v6Routes, newRoute)
	}

	r := cniTypes.Result{
		IP6: &cniTypes.IPConfig{
			IP:      ipamConf.IP6.IP,
			Gateway: ipamConf.IP6.Gateway,
			Routes:  v6Routes,
		},
	}

	if ipamConf.IP4 != nil {
		for _, r := range ipamConf.IP4.Routes {
			newRoute := cniTypes.Route{
				Dst: r.Destination,
			}
			if r.NextHop != nil {
				newRoute.GW = r.NextHop
			}
			v4Routes = append(v4Routes, newRoute)
		}
		r.IP4 = &cniTypes.IPConfig{
			IP:      ipamConf.IP4.IP,
			Gateway: ipamConf.IP4.Gateway,
			Routes:  v4Routes,
		}
	}

	return r.Print()
}