Skip to content

Commit b35cd63

Browse files
fix formatting errors
1 parent 94e969b commit b35cd63

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

cns/restserver/internalapi.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727

2828
const (
2929
// Known API names we care about
30-
nmAgentSwiftV2API = "EnableSwiftV2NCGoalStateSupport"
30+
nmAgentSwiftV2API = "EnableSwiftV2NCGoalStateSupport"
3131
expectedIMDSAPIVersion = "2025-07-24"
32-
PrefixOnNicNCVersion = "1"
32+
PrefixOnNicNCVersion = "1"
3333
)
3434

3535
// This file contains the internal functions called by either HTTP APIs (api.go) or
@@ -229,7 +229,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
229229
}
230230

231231
// Get IMDS NC versions for delegated NIC scenarios
232-
imdsNCVersions, err := service.GetIMDSNCVersions(ctx)
232+
imdsNCVersions, err := service.GetIMDSNCs(ctx)
233233
if err != nil {
234234
// If any of the NMA API check calls, imds calls fails assume that nma build doesn't have the latest changes and create empty map
235235
imdsNCVersions = make(map[string]string)
@@ -247,7 +247,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
247247
}
248248
for ncID, version := range imdsNCVersions {
249249
if _, exists := nmaProgrammedNCs[ncID]; !exists {
250-
nmaProgrammedNCs[strings.ToLower(ncID)] = version
250+
nmaProgrammedNCs[strings.ToLower(ncID)] = version
251251
} else {
252252
logger.Warnf("NC %s exists in both NMA and IMDS responses, which is not expected for NC %s", ncID)
253253
}
@@ -695,59 +695,59 @@ func (service *HTTPRestService) isSwiftV2NCSupported(ctx context.Context) bool {
695695
}
696696

697697
func (service *HTTPRestService) isNCDetailsAPIExists(ctx context.Context) bool {
698-
if service.imdsClient == nil {
699-
logger.Errorf("IMDS client is not available")
700-
return false
701-
}
702-
703-
versionsResp, err := service.imdsClient.GetIMDSVersions(ctx)
704-
if err != nil {
705-
logger.Errorf("Failed to get IMDS versions: %v", err)
706-
return false
707-
}
708-
709-
// Check if the expected API version exists in the response
710-
for _, version := range versionsResp.APIVersions {
711-
if version == expectedIMDSAPIVersion {
712-
return true
713-
}
714-
}
715-
return false
698+
if service.imdsClient == nil {
699+
logger.Errorf("IMDS client is not available")
700+
return false
701+
}
702+
703+
versionsResp, err := service.imdsClient.GetIMDSVersions(ctx)
704+
if err != nil {
705+
logger.Errorf("Failed to get IMDS versions: %v", err)
706+
return false
707+
}
708+
709+
// Check if the expected API version exists in the response
710+
for _, version := range versionsResp.APIVersions {
711+
if version == expectedIMDSAPIVersion {
712+
return true
713+
}
714+
}
715+
return false
716716
}
717717

718718
// GetIMDSNCs gets NC versions from IMDS and returns them as a map
719719
func (service *HTTPRestService) GetIMDSNCs(ctx context.Context) (map[string]string, error) {
720-
// Check NMAgent API support for SwiftV2, if it fails return empty map assuming support might not be available in that nma build
721-
if !service.isSwiftV2NCSupported(ctx) || !service.isNCDetailsAPIExists(ctx) {
722-
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
723-
logger.Errorf("NMAgent does not support SwiftV2 API or IMDS does not support NC details API")
724-
return make(map[string]string), nil
725-
}
726-
727-
imdsClient := service.imdsClient
728-
if imdsClient == nil {
729-
logger.Errorf("IMDS client is not available")
730-
return make(map[string]string), nil
731-
}
732-
733-
// Get all network interfaces from IMDS
734-
networkInterfaces, err := imdsClient.GetNetworkInterfaces(ctx)
735-
if err != nil {
736-
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
737-
logger.Errorf("Failed to get network interfaces from IMDS: %v", err)
738-
return make(map[string]string), nil
739-
}
740-
741-
// Build ncs map from the network interfaces
742-
ncs := make(map[string]string)
743-
for _, iface := range networkInterfaces {
744-
// IMDS returns interfaceCompartmentID, as nc id guid has different context on nma. We map these to NC ID
745-
ncID := iface.InterfaceCompartmentID
746-
747-
if ncID != "" {
748-
ncs[ncID] = PrefixOnNicNCVersion // for prefix on nic version scenario nc version is 1
749-
}
750-
}
751-
752-
return ncs, nil
720+
// Check NMAgent API support for SwiftV2, if it fails return empty map assuming support might not be available in that nma build
721+
if !service.isSwiftV2NCSupported(ctx) || !service.isNCDetailsAPIExists(ctx) {
722+
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
723+
logger.Errorf("NMAgent does not support SwiftV2 API or IMDS does not support NC details API")
724+
return make(map[string]string), nil
725+
}
726+
727+
imdsClient := service.imdsClient
728+
if imdsClient == nil {
729+
logger.Errorf("IMDS client is not available")
730+
return make(map[string]string), nil
731+
}
732+
733+
// Get all network interfaces from IMDS
734+
networkInterfaces, err := imdsClient.GetNetworkInterfaces(ctx)
735+
if err != nil {
736+
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
737+
logger.Errorf("Failed to get network interfaces from IMDS: %v", err)
738+
return make(map[string]string), nil
739+
}
740+
741+
// Build ncs map from the network interfaces
742+
ncs := make(map[string]string)
743+
for _, iface := range networkInterfaces {
744+
// IMDS returns interfaceCompartmentID, as nc id guid has different context on nma. We map these to NC ID
745+
ncID := iface.InterfaceCompartmentID
746+
747+
if ncID != "" {
748+
ncs[ncID] = PrefixOnNicNCVersion // for prefix on nic version scenario nc version is 1
749+
}
750+
}
751+
752+
return ncs, nil
753753
}

0 commit comments

Comments
 (0)