add function to s3
This commit is contained in:
@@ -648,6 +648,40 @@ func (s *Service) ListNetworkInterfaces(ctx context.Context) ([]NetworkInterface
|
||||
return interfaces, nil
|
||||
}
|
||||
|
||||
// GetManagementIPAddress returns the IP address of the management interface
|
||||
func (s *Service) GetManagementIPAddress(ctx context.Context) (string, error) {
|
||||
interfaces, err := s.ListNetworkInterfaces(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to list network interfaces: %w", err)
|
||||
}
|
||||
|
||||
// First, try to find interface with Role "Management"
|
||||
for _, iface := range interfaces {
|
||||
if iface.Role == "Management" && iface.IPAddress != "" && iface.Status == "Connected" {
|
||||
s.logger.Info("Found management interface", "interface", iface.Name, "ip", iface.IPAddress)
|
||||
return iface.IPAddress, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: use interface with default route (primary interface)
|
||||
for _, iface := range interfaces {
|
||||
if iface.Gateway != "" && iface.IPAddress != "" && iface.Status == "Connected" {
|
||||
s.logger.Info("Using primary interface as management", "interface", iface.Name, "ip", iface.IPAddress)
|
||||
return iface.IPAddress, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Final fallback: use first connected interface with IP
|
||||
for _, iface := range interfaces {
|
||||
if iface.IPAddress != "" && iface.Status == "Connected" && iface.Name != "lo" {
|
||||
s.logger.Info("Using first connected interface as management", "interface", iface.Name, "ip", iface.IPAddress)
|
||||
return iface.IPAddress, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("no management interface found")
|
||||
}
|
||||
|
||||
// UpdateNetworkInterfaceRequest represents the request to update a network interface
|
||||
type UpdateNetworkInterfaceRequest struct {
|
||||
IPAddress string `json:"ip_address"`
|
||||
|
||||
Reference in New Issue
Block a user