github.com/Cloud-Foundations/Dominator@v0.3.4/fleetmanager/topology/impl.go (about)

     1  package topology
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/Cloud-Foundations/Dominator/lib/repowatch"
     7  	hyper_proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor"
     8  )
     9  
    10  func watch(params WatchParams) (<-chan *Topology, error) {
    11  	if params.MetricsDirectory == "" {
    12  		params.MetricsDirectory = "fleet-manager/topology-watcher"
    13  	}
    14  	directoryChannel, err := repowatch.Watch(params.TopologyRepository,
    15  		params.LocalRepositoryDir, params.CheckInterval,
    16  		params.MetricsDirectory, params.Logger)
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  	topologyChannel := make(chan *Topology, 1)
    21  	go handleNotifications(directoryChannel, topologyChannel, params.Params)
    22  	return topologyChannel, nil
    23  }
    24  
    25  func handleNotifications(directoryChannel <-chan string,
    26  	topologyChannel chan<- *Topology, params Params) {
    27  	var prevTopology *Topology
    28  	for dir := range directoryChannel {
    29  		loadParams := params
    30  		loadParams.TopologyDir = filepath.Join(dir, params.TopologyDir)
    31  		loadParams.VariablesDir = filepath.Join(dir, params.VariablesDir)
    32  		if topology, err := load(loadParams); err != nil {
    33  			params.Logger.Println(err)
    34  		} else if prevTopology.equal(topology) {
    35  			params.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  }