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

     1  package topology
     2  
     3  import (
     4  	"github.com/Cloud-Foundations/Dominator/proto/hypervisor"
     5  )
     6  
     7  func compareMaps(left, right map[string]string) bool {
     8  	for key, leftValue := range left {
     9  		if right[key] != leftValue {
    10  			return false
    11  		}
    12  	}
    13  	return true
    14  }
    15  
    16  func (left *Topology) equal(right *Topology) bool {
    17  	if left == nil || right == nil {
    18  		return false
    19  	}
    20  	if len(left.machineParents) != len(right.machineParents) {
    21  		return false
    22  	}
    23  	if len(left.Variables) != len(right.Variables) {
    24  		return false
    25  	}
    26  	if !left.Root.equal(right.Root) {
    27  		return false
    28  	}
    29  	if !compareMaps(left.Variables, right.Variables) {
    30  		return false
    31  	}
    32  	return true
    33  }
    34  
    35  func (left *Directory) equal(right *Directory) bool {
    36  	if left.Name != right.Name {
    37  		return false
    38  	}
    39  	if len(left.Directories) != len(right.Directories) {
    40  		return false
    41  	}
    42  	if len(left.Machines) != len(right.Machines) {
    43  		return false
    44  	}
    45  	if len(left.Subnets) != len(right.Subnets) {
    46  		return false
    47  	}
    48  	for index, leftSubdir := range left.Directories {
    49  		if !leftSubdir.equal(right.Directories[index]) {
    50  			return false
    51  		}
    52  	}
    53  	for index, leftMachine := range left.Machines {
    54  		if !leftMachine.Equal(right.Machines[index]) {
    55  			return false
    56  		}
    57  	}
    58  	for index, leftSubnet := range left.Subnets {
    59  		if !leftSubnet.equal(right.Subnets[index]) {
    60  			return false
    61  		}
    62  	}
    63  	if !left.Tags.Equal(right.Tags) {
    64  		return false
    65  	}
    66  	return true
    67  }
    68  
    69  func (left *Subnet) equal(right *Subnet) bool {
    70  	if !left.Subnet.Equal(&right.Subnet) {
    71  		return false
    72  	}
    73  	if !hypervisor.CompareIPs(left.FirstAutoIP, right.FirstAutoIP) {
    74  		return false
    75  	}
    76  	if !hypervisor.CompareIPs(left.LastAutoIP, right.LastAutoIP) {
    77  		return false
    78  	}
    79  	return hypervisor.IpListsEqual(left.ReservedIPs, right.ReservedIPs)
    80  }