-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hcsshim wrapper over HNS API needed for exclusion of management mac a…
…ddresses for VF reassignment. Signed-off-by: Prince Pereira <[email protected]>
- Loading branch information
1 parent
3b5bd8a
commit 4f77a09
Showing
6 changed files
with
172 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//go:build windows | ||
|
||
package hcsshim | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/Microsoft/hcsshim/internal/hns" | ||
) | ||
|
||
// HNSNnvManagementMacAddress represents management mac address | ||
// which needs to be excluded from VF reassignment | ||
type HNSNnvManagementMacAddress = hns.HNSNnvManagementMacAddress | ||
|
||
// HNSNnvManagementMacList represents a list of management | ||
// mac addresses for exclusion from VF reassignment | ||
type HNSNnvManagementMacList = hns.HNSNnvManagementMacList | ||
|
||
var ( | ||
ErrorEmptyMacAddressList = errors.New("management mac_address list is empty") | ||
) | ||
|
||
// SetNnvManagementMacAddresses sets a list of | ||
// management mac addresses in hns for exclusion from VF reassignment. | ||
func SetNnvManagementMacAddresses(managementMacAddresses []string) (*HNSNnvManagementMacList, error) { | ||
if len(managementMacAddresses) == 0 { | ||
return nil, ErrorEmptyMacAddressList | ||
} | ||
nnvManagementMacList := &HNSNnvManagementMacList{} | ||
for _, mac := range managementMacAddresses { | ||
nnvManagementMacList.MacAddressList = append(nnvManagementMacList.MacAddressList, HNSNnvManagementMacAddress{MacAddress: mac}) | ||
} | ||
return nnvManagementMacList.Set() | ||
} | ||
|
||
// GetNnvManagementMacAddresses retrieves a list of | ||
// management mac addresses in hns for exclusion from VF reassignment. | ||
func GetNnvManagementMacAddresses() (*HNSNnvManagementMacList, error) { | ||
return hns.GetNnvManagementMacAddressList() | ||
} | ||
|
||
// DeleteNnvManagementMacAddresses delete list of | ||
// management mac addresses in hns which are excluded from VF reassignment. | ||
func DeleteNnvManagementMacAddresses() (*HNSNnvManagementMacList, error) { | ||
return hns.DeleteNnvManagementMacAddressList() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//go:build windows | ||
|
||
package hns | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// HNSNnvManagementMacAddress represents management mac address | ||
// which needs to be excluded from VF reassignment | ||
type HNSNnvManagementMacAddress struct { | ||
MacAddress string `json:",omitempty"` | ||
} | ||
|
||
// HNSNnvManagementMacList represents a list of management | ||
// mac addresses for exclusion from VF reassignment | ||
type HNSNnvManagementMacList struct { | ||
MacAddressList []HNSNnvManagementMacAddress `json:",omitempty"` | ||
} | ||
|
||
// HNSNnvManagementMacRequest makes a HNS call to modify/query NnvManagementMacList | ||
func HNSNnvManagementMacRequest(method, path, request string) (*HNSNnvManagementMacList, error) { | ||
nnvManagementMacList := &HNSNnvManagementMacList{} | ||
err := hnsCall(method, "/accelnet/"+path, request, &nnvManagementMacList) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return nnvManagementMacList, nil | ||
} | ||
|
||
// Set ManagementMacAddressList by sending "POST" NnvManagementMacRequest to HNS. | ||
func (nnvManagementMacList *HNSNnvManagementMacList) Set() (*HNSNnvManagementMacList, error) { | ||
operation := "Set" | ||
title := "hcsshim::nnvManagementMacList::" + operation | ||
logrus.Debugf(title+" id=%s", nnvManagementMacList.MacAddressList) | ||
|
||
jsonString, err := json.Marshal(nnvManagementMacList) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return HNSNnvManagementMacRequest("POST", "", string(jsonString)) | ||
} | ||
|
||
// Get ManagementMacAddressList by sending "GET" NnvManagementMacRequest to HNS. | ||
func GetNnvManagementMacAddressList() (*HNSNnvManagementMacList, error) { | ||
operation := "Get" | ||
title := "hcsshim::nnvManagementMacList::" + operation | ||
logrus.Debugf(title) | ||
return HNSNnvManagementMacRequest("GET", "", "") | ||
} | ||
|
||
// Delete ManagementMacAddressList by sending "DELETE" NnvManagementMacRequest to HNS. | ||
func DeleteNnvManagementMacAddressList() (*HNSNnvManagementMacList, error) { | ||
operation := "Delete" | ||
title := "hcsshim::nnvManagementMacList::" + operation | ||
logrus.Debugf(title) | ||
return HNSNnvManagementMacRequest("DELETE", "", "") | ||
} |