Skip to content

Commit

Permalink
smdclient: implement xname lookup from IP address
Browse files Browse the repository at this point in the history
  • Loading branch information
LRitzdorf committed Jul 19, 2024
1 parent 19d0ce6 commit ff87935
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/smdclient/SMDclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ func (s *SMDClient) IDfromMAC(mac string) (string, error) {
return "", errors.New("MAC " + mac + " not found for an xname in EthernetInterfaces")
}

// IDfromMAC returns the ID of the xname that has the MAC address
func (s *SMDClient) IDfromIP(ipaddr string) (string, error) {
endpointData := new(CompEthInterfaceV2Array)
ep := "/hsm/v2/Inventory/EthernetInterfaces/"
s.getSMD(ep, endpointData)

for _, ep := range endpointData.Array {
for _, v := range ep.IPAddrs {
if strings.EqualFold(ipaddr, v.IPAddr) {
return ep.CompID, nil
}
}
}
return "", errors.New("IP address " + ipaddr + " not found for an xname in EthernetInterfaces")
}

// GroupMembership returns the group labels for the xname with the given ID
func (s *SMDClient) GroupMembership(id string) ([]string, error) {
ml := new(sm.Membership)
Expand Down

0 comments on commit ff87935

Please # to comment.