-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch primary mac for hns accelnet (#2857)
* fetch primary mac for hns accelnet * downgrade winio module * revert winio to 0.6.2 * remove replace winio old version & separate hns call into windows-only file * fix lint errors * rename files * go fmt locally * add build tags * moving method to platform package * refactor files to restserver fix fmt issues, linter * minor comment edit * undo azure-ipam go.mod, edit minor comments * add log line & format better main.go * address review comments, change ctx todo * undo temp pipeline changes * fix: gofumpt the file linter error
- Loading branch information
Showing
5 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,65 @@ | ||
package restserver | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/Azure/azure-container-networking/cns" | ||
"github.com/Azure/azure-container-networking/cns/types" | ||
"github.com/Microsoft/hcsshim" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
const ( | ||
// timeout for powershell command to return the interfaces list | ||
pwshTimeout = 120 * time.Second | ||
) | ||
|
||
// nolint | ||
func (service *HTTPRestService) programSNATRules(req *cns.CreateNetworkContainerRequest) (types.ResponseCode, string) { | ||
return types.Success, "" | ||
} | ||
|
||
// setVFForAccelnetNICs is used in SWIFTV2 mode to set VF on accelnet nics | ||
func (service *HTTPRestService) setVFForAccelnetNICs() error { | ||
// supply the primary MAC address to HNS api | ||
macAddress, err := service.getPrimaryNICMACAddress() | ||
if err != nil { | ||
return err | ||
} | ||
macAddresses := []string{macAddress} | ||
if _, err := hcsshim.SetNnvManagementMacAddresses(macAddresses); err != nil { | ||
return errors.Wrap(err, "Failed to set primary NIC MAC address") | ||
} | ||
return nil | ||
} | ||
|
||
// getPrimaryNICMacAddress fetches the MAC address of the primary NIC on the node. | ||
func (service *HTTPRestService) getPrimaryNICMACAddress() (string, error) { | ||
// Create a new context and add a timeout to it | ||
ctx, cancel := context.WithTimeout(context.Background(), pwshTimeout) | ||
defer cancel() // The cancel should be deferred so resources are cleaned up | ||
|
||
res, err := service.wscli.GetInterfaces(ctx) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to find primary interface info: %w", err) | ||
} | ||
var macAddress string | ||
for _, i := range res.Interface { | ||
// skip if not primary | ||
if !i.IsPrimary { | ||
continue | ||
} | ||
// skip if no subnets | ||
if len(i.IPSubnet) == 0 { | ||
continue | ||
} | ||
macAddress = i.MacAddress | ||
} | ||
|
||
if macAddress == "" { | ||
return "", errors.New("MAC address not found(empty) from wireserver") | ||
} | ||
return macAddress, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters