コード例 #1
0
ファイル: ipvs.go プロジェクト: Cepave/lvs-metrics
// IPVSUpdateService updates the specified service in the IPVS table.
func (ncc *SeesawNCC) IPVSUpdateService(svc *ipvs.Service, out *int) error {
	ipvsMutex.Lock()
	defer ipvsMutex.Unlock()
	return ipvs.UpdateService(*svc)
}
コード例 #2
0
ファイル: main.go プロジェクト: Cepave/lvs-metrics
// testIPVSModification adds, updates and deletes services and destinations
// from the test configurations. At each step the service or destination is
// retrieved from IPVS and compared against what should be configured.
func testIPVSModification() {
	log.Println("Testing IPVS modifications...")

	// Make sure we have a clean slate.
	if err := ipvs.Flush(); err != nil {
		log.Fatalf("Failed to flush IPVS table: %v\n", err)
	}

	for _, test := range ipvsTests {
		var svc *ipvs.Service
		var err error
		testSvc := test.service
		testDst := test.destinations[0]

		// Add service.
		log.Printf("=> Adding service %s\n", testSvc)
		if err = ipvs.AddService(testSvc); err != nil {
			log.Fatalf("ipvs.AddService() failed: %v\n", err)
		}
		if svc, err = ipvs.GetService(&testSvc); err != nil {
			log.Fatalf("ipvs.GetService() failed: %v\n", err)
		}
		compareSvc(&testSvc, []*ipvs.Service{svc})

		// Add destination.
		log.Printf("--> Adding destination %s\n", testDst)
		if err = ipvs.AddDestination(testSvc, testDst); err != nil {
			log.Fatalf("ipvs.AddDestination() failed: %v\n", err)
		}
		if svc, err = ipvs.GetService(&testSvc); err != nil {
			log.Fatalf("ipvs.GetService() failed: %v\n", err)
		}
		compareSvc(&testSvc, []*ipvs.Service{svc})
		compareDst(&testDst, svc.Destinations)

		// Update service.
		testSvc.Scheduler = "lc"
		if err = ipvs.UpdateService(testSvc); err != nil {
			log.Fatalf("ipvs.UpdateService() failed: %v\n", err)
		}
		if svc, err = ipvs.GetService(&testSvc); err != nil {
			log.Fatalf("ipvs.GetService() failed: %v\n", err)
		}
		compareSvc(&testSvc, []*ipvs.Service{svc})
		compareDst(&testDst, svc.Destinations)

		// Update destination.
		testDst.Weight = 1000
		if err = ipvs.UpdateDestination(testSvc, testDst); err != nil {
			log.Fatalf("ipvs.UpdateDestination() failed: %v\n", err)
		}
		if svc, err = ipvs.GetService(&testSvc); err != nil {
			log.Fatalf("ipvs.GetService() failed: %v\n", err)
		}
		compareSvc(&testSvc, []*ipvs.Service{svc})
		compareDst(&testDst, svc.Destinations)

		// Delete destination.
		if err = ipvs.DeleteDestination(testSvc, testDst); err != nil {
			log.Fatalf("ipvs.DeleteDestination() failed: %v\n", err)
		}
		if svc, err = ipvs.GetService(&testSvc); err != nil {
			log.Fatalf("ipvs.GetService() failed: %v\n", err)
		}
		if len(svc.Destinations) != 0 {
			log.Printf("ERROR: Service still has destinations\n")
		}

		// Delete service.
		if err = ipvs.DeleteService(testSvc); err != nil {
			log.Fatalf("ipvs.DeleteService() failed: %v\n", err)
		}

		// Make sure there is nothing left behind.
		svcs, err := ipvs.GetServices()
		if err != nil {
			log.Fatalf("ipvs.GetServices() failed: %v\n", err)
		}
		if len(svcs) != 0 {
			log.Printf("ERROR: IPVS services still exist!\n")
			for _, svc = range svcs {
				log.Printf("=> Got service %s\n", svc)
			}
		}
	}
}