コード例 #1
0
func (b *CommandBuilder) AddRoutes(interfaceName string, ipConfig *types.IPConfig) executor.Command {
	var routeCommands []executor.Command
	for _, route := range ipConfig.Routes {
		routeCommand := commands.AddRoute{
			Interface:   interfaceName,
			Destination: route.Dst,
			Gateway:     route.GW,
		}

		if routeCommand.Gateway == nil {
			routeCommand.Gateway = ipConfig.Gateway
		}

		routeCommands = append(routeCommands, routeCommand)
	}

	return commands.All(routeCommands...)
}
コード例 #2
0
package commands_test

import (
	"errors"
	"net"

	"github.com/cloudfoundry-incubator/ducati-daemon/executor/commands"
	"github.com/cloudfoundry-incubator/ducati-daemon/fakes"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("AddRoute", func() {
	var (
		routeManager *fakes.RouteManager
		context      *fakes.Context
		addRoute     commands.AddRoute
	)

	BeforeEach(func() {
		context = &fakes.Context{}
		routeManager = &fakes.RouteManager{}
		context.RouteManagerReturns(routeManager)

		addRoute = commands.AddRoute{
			Interface: "my-interface",
			Destination: net.IPNet{
				IP:   net.ParseIP("192.168.1.1"),
				Mask: net.CIDRMask(24, 32),
			},
			Gateway: net.ParseIP("192.168.1.4"),