Пример #1
0
// IPVSGetService gets the currently configured service from the IPVS table,
// which matches the specified service.
func (ncc *SeesawNCC) IPVSGetService(si *ipvs.Service, s *ncctypes.IPVSServices) error {
	ipvsMutex.Lock()
	defer ipvsMutex.Unlock()
	so, err := ipvs.GetService(si)
	if err != nil {
		return err
	}
	s.Services = []*ipvs.Service{so}
	return nil
}
Пример #2
0
func (ipvs *Ipvs) getCurrentDestinationsSet(svc types.Service) (mapset.Set, error) {
	currentSet := mapset.NewSet()
	ipvsSvc, err := gipvs.GetService(ToIpvsService(&svc))
	if err != nil {
		return nil, err
	}

	for _, d := range ipvsSvc.Destinations {
		currentSet.Add(fromDestination(d))
	}

	return currentSet, nil
}
Пример #3
0
// 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)
			}
		}
	}
}