github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/fleetmanager/topology/impl.go (about) 1 package topology 2 3 import ( 4 "path/filepath" 5 "time" 6 7 "github.com/Cloud-Foundations/Dominator/lib/log" 8 "github.com/Cloud-Foundations/Dominator/lib/repowatch" 9 hyper_proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor" 10 ) 11 12 func watch(topologyRepository, localRepositoryDir, topologyDir string, 13 checkInterval time.Duration, 14 logger log.DebugLogger) (<-chan *Topology, error) { 15 directoryChannel, err := repowatch.Watch(topologyRepository, 16 localRepositoryDir, checkInterval, "fleet-manager/topology-watcher", 17 logger) 18 if err != nil { 19 return nil, err 20 } 21 topologyChannel := make(chan *Topology, 1) 22 go handleNotifications(directoryChannel, topologyChannel, topologyDir, 23 logger) 24 return topologyChannel, nil 25 } 26 27 func handleNotifications(directoryChannel <-chan string, 28 topologyChannel chan<- *Topology, topologyDir string, 29 logger log.DebugLogger) { 30 var prevTopology *Topology 31 for dir := range directoryChannel { 32 if topology, err := load(filepath.Join(dir, topologyDir)); err != nil { 33 logger.Println(err) 34 } else if prevTopology.equal(topology) { 35 logger.Debugln(1, "Ignoring unchanged configuration") 36 } else { 37 topologyChannel <- topology 38 prevTopology = topology 39 } 40 } 41 } 42 43 func (subnet *Subnet) shrink() { 44 subnet.Subnet.Shrink() 45 subnet.FirstAutoIP = hyper_proto.ShrinkIP(subnet.FirstAutoIP) 46 subnet.LastAutoIP = hyper_proto.ShrinkIP(subnet.LastAutoIP) 47 for index, ip := range subnet.ReservedIPs { 48 if len(ip) == 16 { 49 ip = ip.To4() 50 if ip != nil { 51 subnet.ReservedIPs[index] = ip 52 } 53 } 54 } 55 }