Skip to content

Commit a61fd4d

Browse files
committed
internal: add lldp, ipv6 handling
- add fields to registry - handle new registry fields and update crd
1 parent bb33fe0 commit a61fd4d

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

internal/api/registry/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ package registry
66
// NetworkInterface represents a network interface on a server,
77
// including its IP and MAC addresses.
88
type NetworkInterface struct {
9-
Name string `json:"name"`
10-
IPAddress string `json:"ipAddress"`
11-
MACAddress string `json:"macAddress"`
9+
Name string `json:"name"`
10+
IPAddress string `json:"ipAddress"`
11+
IPv6Addresses []string `json:"ipv6Addresses"`
12+
MACAddress string `json:"macAddress"`
13+
Status string `json:"status"`
1214
}
1315

1416
// Server represents a server with a list of network interfaces.

internal/controller/server_controller.go

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,61 @@ func (r *ServerReconciler) extractServerDetailsFromRegistry(ctx context.Context,
825825
// update network interfaces
826826
nics := make([]metalv1alpha1.NetworkInterface, 0, len(serverDetails.NetworkInterfaces))
827827
for _, s := range serverDetails.NetworkInterfaces {
828-
nics = append(nics, metalv1alpha1.NetworkInterface{
828+
nic := metalv1alpha1.NetworkInterface{
829829
Name: s.Name,
830-
IP: metalv1alpha1.MustParseIP(s.IPAddress),
831830
MACAddress: s.MACAddress,
832-
})
831+
Status: s.Status,
832+
} // Only set IP field if a valid IP address is present
833+
if s.IPAddress != "" {
834+
ip := metalv1alpha1.MustParseIP(s.IPAddress)
835+
nic.IP = &ip
836+
}
837+
// Convert IPv6 addresses from registry format to CRD format
838+
var ipv6Addresses []metalv1alpha1.IP
839+
for _, ipv6Addr := range s.IPv6Addresses {
840+
if ipv6Addr != "" {
841+
// Parse and validate the IPv6 address
842+
ip, err := metalv1alpha1.ParseIP(ipv6Addr)
843+
if err != nil {
844+
log.V(1).Info("Invalid IPv6 address, skipping", "interface", s.Name, "ipv6", ipv6Addr, "error", err)
845+
continue
846+
}
847+
ipv6Addresses = append(ipv6Addresses, ip)
848+
}
849+
}
850+
// Only set IPv6 field if the array is not empty
851+
if len(ipv6Addresses) > 0 {
852+
nic.IPv6 = ipv6Addresses
853+
}
854+
855+
nics = append(nics, nic)
833856
}
834857
server.Status.NetworkInterfaces = nics
835858

859+
// update LLDP interfaces
860+
lldpInterfaces := make([]metalv1alpha1.LLDPInterface, 0, len(serverDetails.LLDP))
861+
for _, lldpIface := range serverDetails.LLDP {
862+
neighbors := make([]metalv1alpha1.LLDPNeighbor, 0, len(lldpIface.Neighbors))
863+
for _, neighbor := range lldpIface.Neighbors {
864+
neighbors = append(neighbors, metalv1alpha1.LLDPNeighbor{
865+
MACAddress: neighbor.ChassisID,
866+
PortID: neighbor.PortID,
867+
PortDescription: neighbor.PortDescription,
868+
SystemName: neighbor.SystemName,
869+
SystemDescription: neighbor.SystemDescription,
870+
EnabledCapabilities: neighbor.EnabledCapabilities,
871+
})
872+
}
873+
lldpInterfaces = append(lldpInterfaces, metalv1alpha1.LLDPInterface{
874+
InterfaceIndex: lldpIface.InterfaceIndex,
875+
InterfaceName: lldpIface.InterfaceName,
876+
InterfaceAlternativeNames: lldpIface.InterfaceAlternativeNames,
877+
Neighbors: neighbors,
878+
})
879+
}
880+
server.Status.LLDPInterfaces = lldpInterfaces
881+
882+
log.V(1).Info("Found server information in registry", "nics", nics, "lldpInterfaces", lldpInterfaces)
836883
if err := r.Status().Patch(ctx, server, client.MergeFrom(serverBase)); err != nil {
837884
return false, fmt.Errorf("failed to patch server status: %w", err)
838885
}

0 commit comments

Comments
 (0)