Skip to content

Commit

Permalink
Create controlplane API to enable HA CloudAgent without FailOver Clus…
Browse files Browse the repository at this point in the history
…ter (#12)

* add cloudagent/cloud/controlplane API

* update cloudagent/cloud/controlplane API

* use ip instead of fqdn

* enable dhcp and static ip addresses to coexist

* use fqdn rather than ip and remove isLeader

* avoid introducing new dependencies on moc-pkg

* add netsh command for deleting ip address (it works when PS command fails)

* move code to staticip in moc-pkg

* remove certificate and authport

* add state parameter to controlplane to track active/leader/unknown

* currently only exposing leader/nonleader

* retrieve the network interface corresponding to getipaddress

* fix typo

* rename type conversion variable

* add comments to controlplane proto
  • Loading branch information
bfjelds authored Dec 11, 2020
1 parent 2bb56e2 commit 83cb180
Show file tree
Hide file tree
Showing 4 changed files with 476 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package net

import (
"fmt"
"math/big"
"net"
)
Expand Down Expand Up @@ -111,3 +112,56 @@ func PrefixesOverlap(cidr1 net.IPNet, cidr2 net.IPNet) bool {
}
return false
}

func GetNetworkInterface() (string, error) {
// get primary public IP address
primaryPublicIP, err := GetIPAddress()
if err != nil {
return "", err
}

networkInterfaces, err := net.Interfaces()
if err != nil {
return "", err
}

for _, networkInterface := range networkInterfaces {
// return this interface iff it contains the
// primary public IP address

// skip down interface
if networkInterface.Flags&net.FlagUp == 0 {
continue
}
// skip loopback
if networkInterface.Flags&net.FlagLoopback != 0 {
continue
}
// list of unicast interface addresses for specific interface
addresses, err := networkInterface.Addrs()
if err != nil {
return "", err
}
// network end point address
for _, address := range addresses {
var ip net.IP
switch typedAddress := address.(type) {
case *net.IPNet:
ip = typedAddress.IP
case *net.IPAddr:
ip = typedAddress.IP
}
// skip loopback or wrong type
if ip == nil || ip.IsLoopback() {
continue
}

if ip.String() == primaryPublicIP {
// return this interface
return networkInterface.Name, nil
}
}
}

return "", fmt.Errorf("No network interfaces found")
}
Loading

0 comments on commit 83cb180

Please sign in to comment.