Windows: Updates Windows Vendoring
Updates windows dependent libraries for vendoing.
This commit is contained in:
177
vendor/github.com/Microsoft/hcsshim/hcn/hcn.go
generated
vendored
Normal file
177
vendor/github.com/Microsoft/hcsshim/hcn/hcn.go
generated
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
// Package hcn is a shim for the Host Compute Networking (HCN) service, which manages networking for Windows Server
|
||||
// containers and Hyper-V containers. Previous to RS5, HCN was referred to as Host Networking Service (HNS).
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/guid"
|
||||
)
|
||||
|
||||
//go:generate go run ../mksyscall_windows.go -output zsyscall_windows.go hcn.go
|
||||
|
||||
/// HNS V1 API
|
||||
|
||||
//sys SetCurrentThreadCompartmentId(compartmentId uint32) (hr error) = iphlpapi.SetCurrentThreadCompartmentId
|
||||
//sys _hnsCall(method string, path string, object string, response **uint16) (hr error) = vmcompute.HNSCall?
|
||||
|
||||
/// HCN V2 API
|
||||
|
||||
// Network
|
||||
//sys hcnEnumerateNetworks(query string, networks **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateNetworks?
|
||||
//sys hcnCreateNetwork(id *_guid, settings string, network *hcnNetwork, result **uint16) (hr error) = computenetwork.HcnCreateNetwork?
|
||||
//sys hcnOpenNetwork(id *_guid, network *hcnNetwork, result **uint16) (hr error) = computenetwork.HcnOpenNetwork?
|
||||
//sys hcnModifyNetwork(network hcnNetwork, settings string, result **uint16) (hr error) = computenetwork.HcnModifyNetwork?
|
||||
//sys hcnQueryNetworkProperties(network hcnNetwork, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryNetworkProperties?
|
||||
//sys hcnDeleteNetwork(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteNetwork?
|
||||
//sys hcnCloseNetwork(network hcnNetwork) (hr error) = computenetwork.HcnCloseNetwork?
|
||||
|
||||
// Endpoint
|
||||
//sys hcnEnumerateEndpoints(query string, endpoints **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateEndpoints?
|
||||
//sys hcnCreateEndpoint(network hcnNetwork, id *_guid, settings string, endpoint *hcnEndpoint, result **uint16) (hr error) = computenetwork.HcnCreateEndpoint?
|
||||
//sys hcnOpenEndpoint(id *_guid, endpoint *hcnEndpoint, result **uint16) (hr error) = computenetwork.HcnOpenEndpoint?
|
||||
//sys hcnModifyEndpoint(endpoint hcnEndpoint, settings string, result **uint16) (hr error) = computenetwork.HcnModifyEndpoint?
|
||||
//sys hcnQueryEndpointProperties(endpoint hcnEndpoint, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryEndpointProperties?
|
||||
//sys hcnDeleteEndpoint(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteEndpoint?
|
||||
//sys hcnCloseEndpoint(endpoint hcnEndpoint) (hr error) = computenetwork.HcnCloseEndpoint?
|
||||
|
||||
// Namespace
|
||||
//sys hcnEnumerateNamespaces(query string, namespaces **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateNamespaces?
|
||||
//sys hcnCreateNamespace(id *_guid, settings string, namespace *hcnNamespace, result **uint16) (hr error) = computenetwork.HcnCreateNamespace?
|
||||
//sys hcnOpenNamespace(id *_guid, namespace *hcnNamespace, result **uint16) (hr error) = computenetwork.HcnOpenNamespace?
|
||||
//sys hcnModifyNamespace(namespace hcnNamespace, settings string, result **uint16) (hr error) = computenetwork.HcnModifyNamespace?
|
||||
//sys hcnQueryNamespaceProperties(namespace hcnNamespace, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryNamespaceProperties?
|
||||
//sys hcnDeleteNamespace(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteNamespace?
|
||||
//sys hcnCloseNamespace(namespace hcnNamespace) (hr error) = computenetwork.HcnCloseNamespace?
|
||||
|
||||
// LoadBalancer
|
||||
//sys hcnEnumerateLoadBalancers(query string, loadBalancers **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateLoadBalancers?
|
||||
//sys hcnCreateLoadBalancer(id *_guid, settings string, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) = computenetwork.HcnCreateLoadBalancer?
|
||||
//sys hcnOpenLoadBalancer(id *_guid, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) = computenetwork.HcnOpenLoadBalancer?
|
||||
//sys hcnModifyLoadBalancer(loadBalancer hcnLoadBalancer, settings string, result **uint16) (hr error) = computenetwork.HcnModifyLoadBalancer?
|
||||
//sys hcnQueryLoadBalancerProperties(loadBalancer hcnLoadBalancer, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryLoadBalancerProperties?
|
||||
//sys hcnDeleteLoadBalancer(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteLoadBalancer?
|
||||
//sys hcnCloseLoadBalancer(loadBalancer hcnLoadBalancer) (hr error) = computenetwork.HcnCloseLoadBalancer?
|
||||
|
||||
// Service
|
||||
//sys hcnOpenService(service *hcnService, result **uint16) (hr error) = computenetwork.HcnOpenService?
|
||||
//sys hcnRegisterServiceCallback(service hcnService, callback int32, context int32, callbackHandle *hcnCallbackHandle) (hr error) = computenetwork.HcnRegisterServiceCallback?
|
||||
//sys hcnUnregisterServiceCallback(callbackHandle hcnCallbackHandle) (hr error) = computenetwork.HcnUnregisterServiceCallback?
|
||||
//sys hcnCloseService(service hcnService) (hr error) = computenetwork.HcnCloseService?
|
||||
|
||||
type _guid = guid.GUID
|
||||
|
||||
type hcnNetwork syscall.Handle
|
||||
type hcnEndpoint syscall.Handle
|
||||
type hcnNamespace syscall.Handle
|
||||
type hcnLoadBalancer syscall.Handle
|
||||
type hcnService syscall.Handle
|
||||
type hcnCallbackHandle syscall.Handle
|
||||
|
||||
// SchemaVersion for HCN Objects/Queries.
|
||||
type SchemaVersion = Version // hcnglobals.go
|
||||
|
||||
// HostComputeQueryFlags are passed in to a HostComputeQuery to determine which
|
||||
// properties of an object are returned.
|
||||
type HostComputeQueryFlags uint32
|
||||
|
||||
var (
|
||||
// HostComputeQueryFlagsNone returns an object with the standard properties.
|
||||
HostComputeQueryFlagsNone HostComputeQueryFlags
|
||||
// HostComputeQueryFlagsDetailed returns an object with all properties.
|
||||
HostComputeQueryFlagsDetailed HostComputeQueryFlags = 1
|
||||
)
|
||||
|
||||
// HostComputeQuery is the format for HCN queries.
|
||||
type HostComputeQuery struct {
|
||||
SchemaVersion SchemaVersion `json:""`
|
||||
Flags HostComputeQueryFlags `json:",omitempty"`
|
||||
Filter string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// defaultQuery generates HCN Query.
|
||||
// Passed into get/enumerate calls to filter results.
|
||||
func defaultQuery() HostComputeQuery {
|
||||
query := HostComputeQuery{
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
Flags: HostComputeQueryFlagsNone,
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
func defaultQueryJson() string {
|
||||
query := defaultQuery()
|
||||
queryJson, err := json.Marshal(query)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(queryJson)
|
||||
}
|
||||
|
||||
// PlatformDoesNotSupportError happens when users are attempting to use a newer shim on an older OS
|
||||
func platformDoesNotSupportError(featureName string) error {
|
||||
return fmt.Errorf("Platform does not support feature %s", featureName)
|
||||
}
|
||||
|
||||
// V2ApiSupported returns an error if the HCN version does not support the V2 Apis.
|
||||
func V2ApiSupported() error {
|
||||
supported := GetSupportedFeatures()
|
||||
if supported.Api.V2 {
|
||||
return nil
|
||||
}
|
||||
return platformDoesNotSupportError("V2 Api/Schema")
|
||||
}
|
||||
|
||||
func V2SchemaVersion() SchemaVersion {
|
||||
return SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// RemoteSubnetSupported returns an error if the HCN version does not support Remote Subnet policies.
|
||||
func RemoteSubnetSupported() error {
|
||||
supported := GetSupportedFeatures()
|
||||
if supported.RemoteSubnet {
|
||||
return nil
|
||||
}
|
||||
return platformDoesNotSupportError("Remote Subnet")
|
||||
}
|
||||
|
||||
// HostRouteSupported returns an error if the HCN version does not support Host Route policies.
|
||||
func HostRouteSupported() error {
|
||||
supported := GetSupportedFeatures()
|
||||
if supported.HostRoute {
|
||||
return nil
|
||||
}
|
||||
return platformDoesNotSupportError("Host Route")
|
||||
}
|
||||
|
||||
// DSRSupported returns an error if the HCN version does not support Direct Server Return.
|
||||
func DSRSupported() error {
|
||||
supported := GetSupportedFeatures()
|
||||
if supported.DSR {
|
||||
return nil
|
||||
}
|
||||
return platformDoesNotSupportError("Direct Server Return (DSR)")
|
||||
}
|
||||
|
||||
// RequestType are the different operations performed to settings.
|
||||
// Used to update the settings of Endpoint/Namespace objects.
|
||||
type RequestType string
|
||||
|
||||
var (
|
||||
// RequestTypeAdd adds the provided settings object.
|
||||
RequestTypeAdd RequestType = "Add"
|
||||
// RequestTypeRemove removes the provided settings object.
|
||||
RequestTypeRemove RequestType = "Remove"
|
||||
// RequestTypeUpdate replaces settings with the ones provided.
|
||||
RequestTypeUpdate RequestType = "Update"
|
||||
// RequestTypeRefresh refreshes the settings provided.
|
||||
RequestTypeRefresh RequestType = "Refresh"
|
||||
)
|
366
vendor/github.com/Microsoft/hcsshim/hcn/hcnendpoint.go
generated
vendored
Normal file
366
vendor/github.com/Microsoft/hcsshim/hcn/hcnendpoint.go
generated
vendored
Normal file
@ -0,0 +1,366 @@
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/guid"
|
||||
"github.com/Microsoft/hcsshim/internal/interop"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// IpConfig is assoicated with an endpoint
|
||||
type IpConfig struct {
|
||||
IpAddress string `json:",omitempty"`
|
||||
PrefixLength uint8 `json:",omitempty"`
|
||||
}
|
||||
|
||||
// EndpointFlags are special settings on an endpoint.
|
||||
type EndpointFlags uint32
|
||||
|
||||
var (
|
||||
// EndpointFlagsNone is the default.
|
||||
EndpointFlagsNone EndpointFlags
|
||||
// EndpointFlagsRemoteEndpoint means that an endpoint is on another host.
|
||||
EndpointFlagsRemoteEndpoint EndpointFlags = 1
|
||||
)
|
||||
|
||||
// HostComputeEndpoint represents a network endpoint
|
||||
type HostComputeEndpoint struct {
|
||||
Id string `json:"ID,omitempty"`
|
||||
Name string `json:",omitempty"`
|
||||
HostComputeNetwork string `json:",omitempty"` // GUID
|
||||
HostComputeNamespace string `json:",omitempty"` // GUID
|
||||
Policies []EndpointPolicy `json:",omitempty"`
|
||||
IpConfigurations []IpConfig `json:",omitempty"`
|
||||
Dns Dns `json:",omitempty"`
|
||||
Routes []Route `json:",omitempty"`
|
||||
MacAddress string `json:",omitempty"`
|
||||
Flags EndpointFlags `json:",omitempty"`
|
||||
SchemaVersion SchemaVersion `json:",omitempty"`
|
||||
}
|
||||
|
||||
// EndpointResourceType are the two different Endpoint settings resources.
|
||||
type EndpointResourceType string
|
||||
|
||||
var (
|
||||
// EndpointResourceTypePolicy is for Endpoint Policies. Ex: ACL, NAT
|
||||
EndpointResourceTypePolicy EndpointResourceType = "Policy"
|
||||
// EndpointResourceTypePort is for Endpoint Port settings.
|
||||
EndpointResourceTypePort EndpointResourceType = "Port"
|
||||
)
|
||||
|
||||
// ModifyEndpointSettingRequest is the structure used to send request to modify an endpoint.
|
||||
// Used to update policy/port on an endpoint.
|
||||
type ModifyEndpointSettingRequest struct {
|
||||
ResourceType EndpointResourceType `json:",omitempty"` // Policy, Port
|
||||
RequestType RequestType `json:",omitempty"` // Add, Remove, Update, Refresh
|
||||
Settings json.RawMessage `json:",omitempty"`
|
||||
}
|
||||
|
||||
type PolicyEndpointRequest struct {
|
||||
Policies []EndpointPolicy `json:",omitempty"`
|
||||
}
|
||||
|
||||
func getEndpoint(endpointGuid guid.GUID, query string) (*HostComputeEndpoint, error) {
|
||||
// Open endpoint.
|
||||
var (
|
||||
endpointHandle hcnEndpoint
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
hr := hcnOpenEndpoint(&endpointGuid, &endpointHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenEndpoint", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query endpoint.
|
||||
hr = hcnQueryEndpointProperties(endpointHandle, query, &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryEndpointProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close endpoint.
|
||||
hr = hcnCloseEndpoint(endpointHandle)
|
||||
if err := checkForErrors("hcnCloseEndpoint", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeEndpoint
|
||||
var outputEndpoint HostComputeEndpoint
|
||||
if err := json.Unmarshal([]byte(properties), &outputEndpoint); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputEndpoint, nil
|
||||
}
|
||||
|
||||
func enumerateEndpoints(query string) ([]HostComputeEndpoint, error) {
|
||||
// Enumerate all Endpoint Guids
|
||||
var (
|
||||
resultBuffer *uint16
|
||||
endpointBuffer *uint16
|
||||
)
|
||||
hr := hcnEnumerateEndpoints(query, &endpointBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnEnumerateEndpoints", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
endpoints := interop.ConvertAndFreeCoTaskMemString(endpointBuffer)
|
||||
var endpointIds []guid.GUID
|
||||
err := json.Unmarshal([]byte(endpoints), &endpointIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var outputEndpoints []HostComputeEndpoint
|
||||
for _, endpointGuid := range endpointIds {
|
||||
endpoint, err := getEndpoint(endpointGuid, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
outputEndpoints = append(outputEndpoints, *endpoint)
|
||||
}
|
||||
return outputEndpoints, nil
|
||||
}
|
||||
|
||||
func createEndpoint(networkId string, endpointSettings string) (*HostComputeEndpoint, error) {
|
||||
networkGuid := guid.FromString(networkId)
|
||||
// Open network.
|
||||
var networkHandle hcnNetwork
|
||||
var resultBuffer *uint16
|
||||
hr := hcnOpenNetwork(&networkGuid, &networkHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenNetwork", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Create endpoint.
|
||||
endpointId := guid.GUID{}
|
||||
var endpointHandle hcnEndpoint
|
||||
hr = hcnCreateEndpoint(networkHandle, &endpointId, endpointSettings, &endpointHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnCreateEndpoint", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query endpoint.
|
||||
hcnQuery := defaultQuery()
|
||||
query, err := json.Marshal(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var propertiesBuffer *uint16
|
||||
hr = hcnQueryEndpointProperties(endpointHandle, string(query), &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryEndpointProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close endpoint.
|
||||
hr = hcnCloseEndpoint(endpointHandle)
|
||||
if err := checkForErrors("hcnCloseEndpoint", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Close network.
|
||||
hr = hcnCloseNetwork(networkHandle)
|
||||
if err := checkForErrors("hcnCloseNetwork", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeEndpoint
|
||||
var outputEndpoint HostComputeEndpoint
|
||||
if err := json.Unmarshal([]byte(properties), &outputEndpoint); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputEndpoint, nil
|
||||
}
|
||||
|
||||
func modifyEndpoint(endpointId string, settings string) (*HostComputeEndpoint, error) {
|
||||
endpointGuid := guid.FromString(endpointId)
|
||||
// Open endpoint
|
||||
var (
|
||||
endpointHandle hcnEndpoint
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
hr := hcnOpenEndpoint(&endpointGuid, &endpointHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenEndpoint", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Modify endpoint
|
||||
hr = hcnModifyEndpoint(endpointHandle, settings, &resultBuffer)
|
||||
if err := checkForErrors("hcnModifyEndpoint", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query endpoint.
|
||||
hcnQuery := defaultQuery()
|
||||
query, err := json.Marshal(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hr = hcnQueryEndpointProperties(endpointHandle, string(query), &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryEndpointProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close endpoint.
|
||||
hr = hcnCloseEndpoint(endpointHandle)
|
||||
if err := checkForErrors("hcnCloseEndpoint", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeEndpoint
|
||||
var outputEndpoint HostComputeEndpoint
|
||||
if err := json.Unmarshal([]byte(properties), &outputEndpoint); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputEndpoint, nil
|
||||
}
|
||||
|
||||
func deleteEndpoint(endpointId string) error {
|
||||
endpointGuid := guid.FromString(endpointId)
|
||||
var resultBuffer *uint16
|
||||
hr := hcnDeleteEndpoint(&endpointGuid, &resultBuffer)
|
||||
if err := checkForErrors("hcnDeleteEndpoint", hr, resultBuffer); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListEndpoints makes a call to list all available endpoints.
|
||||
func ListEndpoints() ([]HostComputeEndpoint, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
endpoints, err := ListEndpointsQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return endpoints, nil
|
||||
}
|
||||
|
||||
// ListEndpointsQuery makes a call to query the list of available endpoints.
|
||||
func ListEndpointsQuery(query HostComputeQuery) ([]HostComputeEndpoint, error) {
|
||||
queryJson, err := json.Marshal(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
endpoints, err := enumerateEndpoints(string(queryJson))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return endpoints, nil
|
||||
}
|
||||
|
||||
// ListEndpointsOfNetwork queries the list of endpoints on a network.
|
||||
func ListEndpointsOfNetwork(networkId string) ([]HostComputeEndpoint, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
// TODO: Once query can convert schema, change to {HostComputeNetwork:networkId}
|
||||
mapA := map[string]string{"VirtualNetwork": networkId}
|
||||
filter, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hcnQuery.Filter = string(filter)
|
||||
|
||||
return ListEndpointsQuery(hcnQuery)
|
||||
}
|
||||
|
||||
// GetEndpointByID returns an endpoint specified by Id
|
||||
func GetEndpointByID(endpointId string) (*HostComputeEndpoint, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
mapA := map[string]string{"ID": endpointId}
|
||||
filter, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hcnQuery.Filter = string(filter)
|
||||
|
||||
endpoints, err := ListEndpointsQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(endpoints) == 0 {
|
||||
return nil, EndpointNotFoundError{EndpointID: endpointId}
|
||||
}
|
||||
return &endpoints[0], err
|
||||
}
|
||||
|
||||
// GetEndpointByName returns an endpoint specified by Name
|
||||
func GetEndpointByName(endpointName string) (*HostComputeEndpoint, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
mapA := map[string]string{"Name": endpointName}
|
||||
filter, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hcnQuery.Filter = string(filter)
|
||||
|
||||
endpoints, err := ListEndpointsQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(endpoints) == 0 {
|
||||
return nil, EndpointNotFoundError{EndpointName: endpointName}
|
||||
}
|
||||
return &endpoints[0], err
|
||||
}
|
||||
|
||||
// Create Endpoint.
|
||||
func (endpoint *HostComputeEndpoint) Create() (*HostComputeEndpoint, error) {
|
||||
logrus.Debugf("hcn::HostComputeEndpoint::Create id=%s", endpoint.Id)
|
||||
|
||||
jsonString, err := json.Marshal(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debugf("hcn::HostComputeEndpoint::Create JSON: %s", jsonString)
|
||||
endpoint, hcnErr := createEndpoint(endpoint.HostComputeNetwork, string(jsonString))
|
||||
if hcnErr != nil {
|
||||
return nil, hcnErr
|
||||
}
|
||||
return endpoint, nil
|
||||
}
|
||||
|
||||
// Delete Endpoint.
|
||||
func (endpoint *HostComputeEndpoint) Delete() error {
|
||||
logrus.Debugf("hcn::HostComputeEndpoint::Delete id=%s", endpoint.Id)
|
||||
|
||||
if err := deleteEndpoint(endpoint.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ModifyEndpointSettings updates the Port/Policy of an Endpoint.
|
||||
func ModifyEndpointSettings(endpointId string, request *ModifyEndpointSettingRequest) error {
|
||||
logrus.Debugf("hcn::HostComputeEndpoint::ModifyEndpointSettings id=%s", endpointId)
|
||||
|
||||
endpointSettingsRequest, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = modifyEndpoint(endpointId, string(endpointSettingsRequest))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ApplyPolicy applies a Policy (ex: ACL) on the Endpoint.
|
||||
func (endpoint *HostComputeEndpoint) ApplyPolicy(endpointPolicy PolicyEndpointRequest) error {
|
||||
logrus.Debugf("hcn::HostComputeEndpoint::ApplyPolicy id=%s", endpoint.Id)
|
||||
|
||||
settingsJson, err := json.Marshal(endpointPolicy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
requestMessage := &ModifyEndpointSettingRequest{
|
||||
ResourceType: EndpointResourceTypePolicy,
|
||||
RequestType: RequestTypeUpdate,
|
||||
Settings: settingsJson,
|
||||
}
|
||||
|
||||
return ModifyEndpointSettings(endpoint.Id, requestMessage)
|
||||
}
|
||||
|
||||
// NamespaceAttach modifies a Namespace to add an endpoint.
|
||||
func (endpoint *HostComputeEndpoint) NamespaceAttach(namespaceId string) error {
|
||||
return AddNamespaceEndpoint(namespaceId, endpoint.Id)
|
||||
}
|
||||
|
||||
// NamespaceDetach modifies a Namespace to remove an endpoint.
|
||||
func (endpoint *HostComputeEndpoint) NamespaceDetach(namespaceId string) error {
|
||||
return RemoveNamespaceEndpoint(namespaceId, endpoint.Id)
|
||||
}
|
298
vendor/github.com/Microsoft/hcsshim/hcn/hcnendpoint_test.go
generated
vendored
Normal file
298
vendor/github.com/Microsoft/hcsshim/hcn/hcnendpoint_test.go
generated
vendored
Normal file
@ -0,0 +1,298 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateDeleteEndpoint(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jsonString, err := json.Marshal(Endpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("Endpoint JSON:\n%s \n", jsonString)
|
||||
|
||||
err = Endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEndpointById(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundEndpoint, err := GetEndpointByID(Endpoint.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if foundEndpoint == nil {
|
||||
t.Fatal("No Endpoint found")
|
||||
}
|
||||
|
||||
err = foundEndpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEndpointByName(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundEndpoint, err := GetEndpointByName(Endpoint.Name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if foundEndpoint == nil {
|
||||
t.Fatal("No Endpoint found")
|
||||
}
|
||||
|
||||
err = foundEndpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListEndpoints(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundEndpoints, err := ListEndpoints()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundEndpoints) == 0 {
|
||||
t.Fatal("No Endpoint found")
|
||||
}
|
||||
|
||||
err = Endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListEndpointsOfNetwork(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundEndpoints, err := ListEndpointsOfNetwork(network.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundEndpoints) == 0 {
|
||||
t.Fatal("No Endpoint found")
|
||||
}
|
||||
|
||||
err = Endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointNamespaceAttachDetach(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = endpoint.NamespaceAttach(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.NamespaceDetach(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = namespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateEndpointWithNamespace(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Endpoint, err := HcnCreateTestEndpointWithNamespace(network, namespace)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if Endpoint.HostComputeNamespace == "" {
|
||||
t.Fatal("No Namespace detected.")
|
||||
}
|
||||
|
||||
err = Endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyPolicyOnEndpoint(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpointPolicyList, err := HcnCreateAcls()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jsonString, err := json.Marshal(*endpointPolicyList)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("ACLS JSON:\n%s \n", jsonString)
|
||||
err = Endpoint.ApplyPolicy(*endpointPolicyList)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundEndpoint, err := GetEndpointByName(Endpoint.Name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundEndpoint.Policies) == 0 {
|
||||
t.Fatal("No Endpoint Policies found")
|
||||
}
|
||||
|
||||
err = Endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyEndpointSettings(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpointPolicy, err := HcnCreateAcls()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
settingsJson, err := json.Marshal(endpointPolicy)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
requestMessage := &ModifyEndpointSettingRequest{
|
||||
ResourceType: EndpointResourceTypePolicy,
|
||||
RequestType: RequestTypeUpdate,
|
||||
Settings: settingsJson,
|
||||
}
|
||||
|
||||
err = ModifyEndpointSettings(endpoint.Id, requestMessage)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundEndpoint, err := GetEndpointByName(endpoint.Name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundEndpoint.Policies) == 0 {
|
||||
t.Fatal("No Endpoint Policies found")
|
||||
}
|
||||
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
95
vendor/github.com/Microsoft/hcsshim/hcn/hcnerrors.go
generated
vendored
Normal file
95
vendor/github.com/Microsoft/hcsshim/hcn/hcnerrors.go
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
// Package hcn is a shim for the Host Compute Networking (HCN) service, which manages networking for Windows Server
|
||||
// containers and Hyper-V containers. Previous to RS5, HCN was referred to as Host Networking Service (HNS).
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/hcserror"
|
||||
"github.com/Microsoft/hcsshim/internal/interop"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func checkForErrors(methodName string, hr error, resultBuffer *uint16) error {
|
||||
errorFound := false
|
||||
|
||||
if hr != nil {
|
||||
errorFound = true
|
||||
}
|
||||
|
||||
result := ""
|
||||
if resultBuffer != nil {
|
||||
result = interop.ConvertAndFreeCoTaskMemString(resultBuffer)
|
||||
if result != "" {
|
||||
errorFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if errorFound {
|
||||
returnError := hcserror.New(hr, methodName, result)
|
||||
logrus.Debugf(returnError.Error()) // HCN errors logged for debugging.
|
||||
return returnError
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NetworkNotFoundError results from a failed seach for a network by Id or Name
|
||||
type NetworkNotFoundError struct {
|
||||
NetworkName string
|
||||
NetworkID string
|
||||
}
|
||||
|
||||
func (e NetworkNotFoundError) Error() string {
|
||||
if e.NetworkName == "" {
|
||||
return fmt.Sprintf("Network Name %s not found", e.NetworkName)
|
||||
}
|
||||
return fmt.Sprintf("Network Id %s not found", e.NetworkID)
|
||||
}
|
||||
|
||||
// EndpointNotFoundError results from a failed seach for an endpoint by Id or Name
|
||||
type EndpointNotFoundError struct {
|
||||
EndpointName string
|
||||
EndpointID string
|
||||
}
|
||||
|
||||
func (e EndpointNotFoundError) Error() string {
|
||||
if e.EndpointName == "" {
|
||||
return fmt.Sprintf("Endpoint Name %s not found", e.EndpointName)
|
||||
}
|
||||
return fmt.Sprintf("Endpoint Id %s not found", e.EndpointID)
|
||||
}
|
||||
|
||||
// NamespaceNotFoundError results from a failed seach for a namsepace by Id
|
||||
type NamespaceNotFoundError struct {
|
||||
NamespaceID string
|
||||
}
|
||||
|
||||
func (e NamespaceNotFoundError) Error() string {
|
||||
return fmt.Sprintf("Namespace %s not found", e.NamespaceID)
|
||||
}
|
||||
|
||||
// LoadBalancerNotFoundError results from a failed seach for a loadbalancer by Id
|
||||
type LoadBalancerNotFoundError struct {
|
||||
LoadBalancerId string
|
||||
}
|
||||
|
||||
func (e LoadBalancerNotFoundError) Error() string {
|
||||
return fmt.Sprintf("LoadBalancer %s not found", e.LoadBalancerId)
|
||||
}
|
||||
|
||||
// IsNotFoundError returns a boolean indicating whether the error was caused by
|
||||
// a resource not being found.
|
||||
func IsNotFoundError(err error) bool {
|
||||
switch err.(type) {
|
||||
case NetworkNotFoundError:
|
||||
return true
|
||||
case EndpointNotFoundError:
|
||||
return true
|
||||
case NamespaceNotFoundError:
|
||||
return true
|
||||
case LoadBalancerNotFoundError:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
34
vendor/github.com/Microsoft/hcsshim/hcn/hcnerrors_test.go
generated
vendored
Normal file
34
vendor/github.com/Microsoft/hcsshim/hcn/hcnerrors_test.go
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMissingNetworkByName(t *testing.T) {
|
||||
_, err := GetNetworkByName("Not found name")
|
||||
if err == nil {
|
||||
t.Fatal("Error was not thrown.")
|
||||
}
|
||||
if !IsNotFoundError(err) {
|
||||
t.Fatal("Unrelated error was thrown.")
|
||||
}
|
||||
if _, ok := err.(NetworkNotFoundError); !ok {
|
||||
t.Fatal("Wrong error type was thrown.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingNetworkById(t *testing.T) {
|
||||
// Random guid
|
||||
_, err := GetNetworkByID("5f0b1190-63be-4e0c-b974-bd0f55675a42")
|
||||
if err == nil {
|
||||
t.Fatal("Unrelated error was thrown.")
|
||||
}
|
||||
if !IsNotFoundError(err) {
|
||||
t.Fatal("Unrelated error was thrown.")
|
||||
}
|
||||
if _, ok := err.(NetworkNotFoundError); !ok {
|
||||
t.Fatal("Wrong error type was thrown.")
|
||||
}
|
||||
}
|
87
vendor/github.com/Microsoft/hcsshim/hcn/hcnglobals.go
generated
vendored
Normal file
87
vendor/github.com/Microsoft/hcsshim/hcn/hcnglobals.go
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/hcserror"
|
||||
"github.com/Microsoft/hcsshim/internal/interop"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Globals are all global properties of the HCN Service.
|
||||
type Globals struct {
|
||||
Version Version `json:"Version"`
|
||||
}
|
||||
|
||||
// Version is the HCN Service version.
|
||||
type Version struct {
|
||||
Major int `json:"Major"`
|
||||
Minor int `json:"Minor"`
|
||||
}
|
||||
|
||||
var (
|
||||
// HNSVersion1803 added ACL functionality.
|
||||
HNSVersion1803 = Version{Major: 7, Minor: 2}
|
||||
// V2ApiSupport allows the use of V2 Api calls and V2 Schema.
|
||||
V2ApiSupport = Version{Major: 9, Minor: 1}
|
||||
// Remote Subnet allows for Remote Subnet policies on Overlay networks
|
||||
RemoteSubnetVersion = Version{Major: 9, Minor: 2}
|
||||
// A Host Route policy allows for local container to local host communication Overlay networks
|
||||
HostRouteVersion = Version{Major: 9, Minor: 2}
|
||||
// HNS 10.2 allows for Direct Server Return for loadbalancing
|
||||
DSRVersion = Version{Major: 10, Minor: 2}
|
||||
)
|
||||
|
||||
// GetGlobals returns the global properties of the HCN Service.
|
||||
func GetGlobals() (*Globals, error) {
|
||||
var version Version
|
||||
err := hnsCall("GET", "/globals/version", "", &version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
globals := &Globals{
|
||||
Version: version,
|
||||
}
|
||||
|
||||
return globals, nil
|
||||
}
|
||||
|
||||
type hnsResponse struct {
|
||||
Success bool
|
||||
Error string
|
||||
Output json.RawMessage
|
||||
}
|
||||
|
||||
func hnsCall(method, path, request string, returnResponse interface{}) error {
|
||||
var responseBuffer *uint16
|
||||
logrus.Debugf("[%s]=>[%s] Request : %s", method, path, request)
|
||||
|
||||
err := _hnsCall(method, path, request, &responseBuffer)
|
||||
if err != nil {
|
||||
return hcserror.New(err, "hnsCall ", "")
|
||||
}
|
||||
response := interop.ConvertAndFreeCoTaskMemString(responseBuffer)
|
||||
|
||||
hnsresponse := &hnsResponse{}
|
||||
if err = json.Unmarshal([]byte(response), &hnsresponse); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !hnsresponse.Success {
|
||||
return fmt.Errorf("HNS failed with error : %s", hnsresponse.Error)
|
||||
}
|
||||
|
||||
if len(hnsresponse.Output) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
logrus.Debugf("Network Response : %s", hnsresponse.Output)
|
||||
err = json.Unmarshal(hnsresponse.Output, returnResponse)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
321
vendor/github.com/Microsoft/hcsshim/hcn/hcnloadbalancer.go
generated
vendored
Normal file
321
vendor/github.com/Microsoft/hcsshim/hcn/hcnloadbalancer.go
generated
vendored
Normal file
@ -0,0 +1,321 @@
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/guid"
|
||||
"github.com/Microsoft/hcsshim/internal/interop"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// LoadBalancerPortMapping is associated with HostComputeLoadBalancer
|
||||
type LoadBalancerPortMapping struct {
|
||||
Protocol uint32 `json:",omitempty"` // EX: TCP = 6, UDP = 17
|
||||
InternalPort uint16 `json:",omitempty"`
|
||||
ExternalPort uint16 `json:",omitempty"`
|
||||
Flags uint32 `json:",omitempty"` // 0: None, 1: EnableILB, 2: LocalRoutedVip
|
||||
}
|
||||
|
||||
// HostComputeLoadBalancer represents software load balancer.
|
||||
type HostComputeLoadBalancer struct {
|
||||
Id string `json:"ID,omitempty"`
|
||||
HostComputeEndpoints []string `json:",omitempty"`
|
||||
SourceVIP string `json:",omitempty"`
|
||||
FrontendVIPs []string `json:",omitempty"`
|
||||
PortMappings []LoadBalancerPortMapping `json:",omitempty"`
|
||||
SchemaVersion SchemaVersion `json:",omitempty"`
|
||||
Flags uint32 `json:",omitempty"` // 0: None, 1: EnableDirectServerReturn
|
||||
}
|
||||
|
||||
func getLoadBalancer(loadBalancerGuid guid.GUID, query string) (*HostComputeLoadBalancer, error) {
|
||||
// Open loadBalancer.
|
||||
var (
|
||||
loadBalancerHandle hcnLoadBalancer
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
hr := hcnOpenLoadBalancer(&loadBalancerGuid, &loadBalancerHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenLoadBalancer", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query loadBalancer.
|
||||
hr = hcnQueryLoadBalancerProperties(loadBalancerHandle, query, &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryLoadBalancerProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close loadBalancer.
|
||||
hr = hcnCloseLoadBalancer(loadBalancerHandle)
|
||||
if err := checkForErrors("hcnCloseLoadBalancer", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeLoadBalancer
|
||||
var outputLoadBalancer HostComputeLoadBalancer
|
||||
if err := json.Unmarshal([]byte(properties), &outputLoadBalancer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputLoadBalancer, nil
|
||||
}
|
||||
|
||||
func enumerateLoadBalancers(query string) ([]HostComputeLoadBalancer, error) {
|
||||
// Enumerate all LoadBalancer Guids
|
||||
var (
|
||||
resultBuffer *uint16
|
||||
loadBalancerBuffer *uint16
|
||||
)
|
||||
hr := hcnEnumerateLoadBalancers(query, &loadBalancerBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnEnumerateLoadBalancers", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
loadBalancers := interop.ConvertAndFreeCoTaskMemString(loadBalancerBuffer)
|
||||
var loadBalancerIds []guid.GUID
|
||||
if err := json.Unmarshal([]byte(loadBalancers), &loadBalancerIds); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var outputLoadBalancers []HostComputeLoadBalancer
|
||||
for _, loadBalancerGuid := range loadBalancerIds {
|
||||
loadBalancer, err := getLoadBalancer(loadBalancerGuid, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
outputLoadBalancers = append(outputLoadBalancers, *loadBalancer)
|
||||
}
|
||||
return outputLoadBalancers, nil
|
||||
}
|
||||
|
||||
func createLoadBalancer(settings string) (*HostComputeLoadBalancer, error) {
|
||||
// Create new loadBalancer.
|
||||
var (
|
||||
loadBalancerHandle hcnLoadBalancer
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
loadBalancerGuid := guid.GUID{}
|
||||
hr := hcnCreateLoadBalancer(&loadBalancerGuid, settings, &loadBalancerHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnCreateLoadBalancer", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query loadBalancer.
|
||||
hcnQuery := defaultQuery()
|
||||
query, err := json.Marshal(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hr = hcnQueryLoadBalancerProperties(loadBalancerHandle, string(query), &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryLoadBalancerProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close loadBalancer.
|
||||
hr = hcnCloseLoadBalancer(loadBalancerHandle)
|
||||
if err := checkForErrors("hcnCloseLoadBalancer", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeLoadBalancer
|
||||
var outputLoadBalancer HostComputeLoadBalancer
|
||||
if err := json.Unmarshal([]byte(properties), &outputLoadBalancer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputLoadBalancer, nil
|
||||
}
|
||||
|
||||
func modifyLoadBalancer(loadBalancerId string, settings string) (*HostComputeLoadBalancer, error) {
|
||||
loadBalancerGuid := guid.FromString(loadBalancerId)
|
||||
// Open loadBalancer.
|
||||
var (
|
||||
loadBalancerHandle hcnLoadBalancer
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
hr := hcnOpenLoadBalancer(&loadBalancerGuid, &loadBalancerHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenLoadBalancer", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Modify loadBalancer.
|
||||
hr = hcnModifyLoadBalancer(loadBalancerHandle, settings, &resultBuffer)
|
||||
if err := checkForErrors("hcnModifyLoadBalancer", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query loadBalancer.
|
||||
hcnQuery := defaultQuery()
|
||||
query, err := json.Marshal(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hr = hcnQueryLoadBalancerProperties(loadBalancerHandle, string(query), &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryLoadBalancerProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close loadBalancer.
|
||||
hr = hcnCloseLoadBalancer(loadBalancerHandle)
|
||||
if err := checkForErrors("hcnCloseLoadBalancer", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to LoadBalancer
|
||||
var outputLoadBalancer HostComputeLoadBalancer
|
||||
if err := json.Unmarshal([]byte(properties), &outputLoadBalancer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputLoadBalancer, nil
|
||||
}
|
||||
|
||||
func deleteLoadBalancer(loadBalancerId string) error {
|
||||
loadBalancerGuid := guid.FromString(loadBalancerId)
|
||||
var resultBuffer *uint16
|
||||
hr := hcnDeleteLoadBalancer(&loadBalancerGuid, &resultBuffer)
|
||||
if err := checkForErrors("hcnDeleteLoadBalancer", hr, resultBuffer); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListLoadBalancers makes a call to list all available loadBalancers.
|
||||
func ListLoadBalancers() ([]HostComputeLoadBalancer, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return loadBalancers, nil
|
||||
}
|
||||
|
||||
// ListLoadBalancersQuery makes a call to query the list of available loadBalancers.
|
||||
func ListLoadBalancersQuery(query HostComputeQuery) ([]HostComputeLoadBalancer, error) {
|
||||
queryJson, err := json.Marshal(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
loadBalancers, err := enumerateLoadBalancers(string(queryJson))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return loadBalancers, nil
|
||||
}
|
||||
|
||||
// GetLoadBalancerByID returns the LoadBalancer specified by Id.
|
||||
func GetLoadBalancerByID(loadBalancerId string) (*HostComputeLoadBalancer, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
mapA := map[string]string{"ID": loadBalancerId}
|
||||
filter, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hcnQuery.Filter = string(filter)
|
||||
|
||||
loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(loadBalancers) == 0 {
|
||||
return nil, LoadBalancerNotFoundError{LoadBalancerId: loadBalancerId}
|
||||
}
|
||||
return &loadBalancers[0], err
|
||||
}
|
||||
|
||||
// Create LoadBalancer.
|
||||
func (loadBalancer *HostComputeLoadBalancer) Create() (*HostComputeLoadBalancer, error) {
|
||||
logrus.Debugf("hcn::HostComputeLoadBalancer::Create id=%s", loadBalancer.Id)
|
||||
|
||||
jsonString, err := json.Marshal(loadBalancer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debugf("hcn::HostComputeLoadBalancer::Create JSON: %s", jsonString)
|
||||
loadBalancer, hcnErr := createLoadBalancer(string(jsonString))
|
||||
if hcnErr != nil {
|
||||
return nil, hcnErr
|
||||
}
|
||||
return loadBalancer, nil
|
||||
}
|
||||
|
||||
// Delete LoadBalancer.
|
||||
func (loadBalancer *HostComputeLoadBalancer) Delete() error {
|
||||
logrus.Debugf("hcn::HostComputeLoadBalancer::Delete id=%s", loadBalancer.Id)
|
||||
|
||||
if err := deleteLoadBalancer(loadBalancer.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddEndpoint add an endpoint to a LoadBalancer
|
||||
func (loadBalancer *HostComputeLoadBalancer) AddEndpoint(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
|
||||
logrus.Debugf("hcn::HostComputeLoadBalancer::AddEndpoint loadBalancer=%s endpoint=%s", loadBalancer.Id, endpoint.Id)
|
||||
|
||||
err := loadBalancer.Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Add Endpoint to the Existing List
|
||||
loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
|
||||
|
||||
return loadBalancer.Create()
|
||||
}
|
||||
|
||||
// RemoveEndpoint removes an endpoint from a LoadBalancer
|
||||
func (loadBalancer *HostComputeLoadBalancer) RemoveEndpoint(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
|
||||
logrus.Debugf("hcn::HostComputeLoadBalancer::RemoveEndpoint loadBalancer=%s endpoint=%s", loadBalancer.Id, endpoint.Id)
|
||||
|
||||
err := loadBalancer.Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a list of all the endpoints besides the one being removed
|
||||
var endpoints []string
|
||||
for _, endpointReference := range loadBalancer.HostComputeEndpoints {
|
||||
if endpointReference == endpoint.Id {
|
||||
continue
|
||||
}
|
||||
endpoints = append(endpoints, endpointReference)
|
||||
}
|
||||
loadBalancer.HostComputeEndpoints = endpoints
|
||||
return loadBalancer.Create()
|
||||
}
|
||||
|
||||
// AddLoadBalancer for the specified endpoints
|
||||
func AddLoadBalancer(endpoints []HostComputeEndpoint, isILB bool, isDSR bool, sourceVIP string, frontendVIPs []string, protocol uint16, internalPort uint16, externalPort uint16) (*HostComputeLoadBalancer, error) {
|
||||
logrus.Debugf("hcn::HostComputeLoadBalancer::AddLoadBalancer endpointId=%v, isILB=%v, sourceVIP=%s, frontendVIPs=%v, protocol=%v, internalPort=%v, externalPort=%v", endpoints, isILB, sourceVIP, frontendVIPs, protocol, internalPort, externalPort)
|
||||
|
||||
var portMappingFlags uint32
|
||||
portMappingFlags = 0
|
||||
if isILB {
|
||||
portMappingFlags = 1
|
||||
}
|
||||
|
||||
var lbFlags uint32
|
||||
lbFlags = 0
|
||||
if isDSR {
|
||||
lbFlags = 1 // EnableDirectServerReturn
|
||||
}
|
||||
|
||||
loadBalancer := &HostComputeLoadBalancer{
|
||||
SourceVIP: sourceVIP,
|
||||
PortMappings: []LoadBalancerPortMapping{
|
||||
{
|
||||
Protocol: uint32(protocol),
|
||||
InternalPort: internalPort,
|
||||
ExternalPort: externalPort,
|
||||
Flags: portMappingFlags,
|
||||
},
|
||||
},
|
||||
FrontendVIPs: frontendVIPs,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
Flags: lbFlags,
|
||||
}
|
||||
|
||||
for _, endpoint := range endpoints {
|
||||
loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
|
||||
}
|
||||
|
||||
return loadBalancer.Create()
|
||||
}
|
243
vendor/github.com/Microsoft/hcsshim/hcn/hcnloadbalancer_test.go
generated
vendored
Normal file
243
vendor/github.com/Microsoft/hcsshim/hcn/hcnloadbalancer_test.go
generated
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateDeleteLoadBalancer(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loadBalancer, err := HcnCreateTestLoadBalancer(endpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jsonString, err := json.Marshal(loadBalancer)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("LoadBalancer JSON:\n%s \n", jsonString)
|
||||
|
||||
err = loadBalancer.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetLoadBalancerById(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loadBalancer, err := HcnCreateTestLoadBalancer(endpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundLB, err := GetLoadBalancerByID(loadBalancer.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if foundLB == nil {
|
||||
t.Fatalf("No loadBalancer found")
|
||||
}
|
||||
err = loadBalancer.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListLoadBalancer(t *testing.T) {
|
||||
_, err := ListLoadBalancers()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadBalancerAddRemoveEndpoint(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loadBalancer, err := HcnCreateTestLoadBalancer(endpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
secondEndpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
updatedLB, err := loadBalancer.AddEndpoint(secondEndpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(updatedLB.HostComputeEndpoints) != 2 {
|
||||
t.Fatalf("Endpoint not added to loadBalancer")
|
||||
}
|
||||
updatedLB, err = loadBalancer.RemoveEndpoint(secondEndpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(updatedLB.HostComputeEndpoints) != 1 {
|
||||
t.Fatalf("Endpoint not removed from loadBalancer")
|
||||
}
|
||||
|
||||
err = loadBalancer.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = secondEndpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddLoadBalancer(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
loadBalancer, err := AddLoadBalancer([]HostComputeEndpoint{*endpoint}, false, false, "10.0.0.1", []string{"1.1.1.2", "1.1.1.3"}, 6, 8080, 80)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundLB, err := GetLoadBalancerByID(loadBalancer.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if foundLB == nil {
|
||||
t.Fatal(fmt.Errorf("No loadBalancer found"))
|
||||
}
|
||||
|
||||
err = loadBalancer.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddDSRLoadBalancer(t *testing.T) {
|
||||
network, err := CreateTestOverlayNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
loadBalancer, err := AddLoadBalancer([]HostComputeEndpoint{*endpoint}, false, true, "10.0.0.1", []string{"1.1.1.2", "1.1.1.3"}, 6, 8080, 80)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundLB, err := GetLoadBalancerByID(loadBalancer.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if foundLB == nil {
|
||||
t.Fatal(fmt.Errorf("No loadBalancer found"))
|
||||
}
|
||||
|
||||
err = loadBalancer.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddILBLoadBalancer(t *testing.T) {
|
||||
network, err := CreateTestOverlayNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
loadBalancer, err := AddLoadBalancer([]HostComputeEndpoint{*endpoint}, true, false, "10.0.0.1", []string{"1.1.1.2", "1.1.1.3"}, 6, 8080, 80)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundLB, err := GetLoadBalancerByID(loadBalancer.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if foundLB == nil {
|
||||
t.Fatal(fmt.Errorf("No loadBalancer found"))
|
||||
}
|
||||
|
||||
err = loadBalancer.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
424
vendor/github.com/Microsoft/hcsshim/hcn/hcnnamespace.go
generated
vendored
Normal file
424
vendor/github.com/Microsoft/hcsshim/hcn/hcnnamespace.go
generated
vendored
Normal file
@ -0,0 +1,424 @@
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
icni "github.com/Microsoft/hcsshim/internal/cni"
|
||||
"github.com/Microsoft/hcsshim/internal/guid"
|
||||
"github.com/Microsoft/hcsshim/internal/interop"
|
||||
"github.com/Microsoft/hcsshim/internal/regstate"
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// NamespaceResourceEndpoint represents an Endpoint attached to a Namespace.
|
||||
type NamespaceResourceEndpoint struct {
|
||||
Id string `json:"ID,"`
|
||||
}
|
||||
|
||||
// NamespaceResourceContainer represents a Container attached to a Namespace.
|
||||
type NamespaceResourceContainer struct {
|
||||
Id string `json:"ID,"`
|
||||
}
|
||||
|
||||
// NamespaceResourceType determines whether the Namespace resource is a Container or Endpoint.
|
||||
type NamespaceResourceType string
|
||||
|
||||
var (
|
||||
// NamespaceResourceTypeContainer are contianers associated with a Namespace.
|
||||
NamespaceResourceTypeContainer NamespaceResourceType = "Container"
|
||||
// NamespaceResourceTypeEndpoint are endpoints associated with a Namespace.
|
||||
NamespaceResourceTypeEndpoint NamespaceResourceType = "Endpoint"
|
||||
)
|
||||
|
||||
// NamespaceResource is associated with a namespace
|
||||
type NamespaceResource struct {
|
||||
Type NamespaceResourceType `json:","` // Container, Endpoint
|
||||
Data json.RawMessage `json:","`
|
||||
}
|
||||
|
||||
// NamespaceType determines whether the Namespace is for a Host or Guest
|
||||
type NamespaceType string
|
||||
|
||||
var (
|
||||
// NamespaceTypeHost are host namespaces.
|
||||
NamespaceTypeHost NamespaceType = "Host"
|
||||
// NamespaceTypeHostDefault are host namespaces in the default compartment.
|
||||
NamespaceTypeHostDefault NamespaceType = "HostDefault"
|
||||
// NamespaceTypeGuest are guest namespaces.
|
||||
NamespaceTypeGuest NamespaceType = "Guest"
|
||||
// NamespaceTypeGuestDefault are guest namespaces in the default compartment.
|
||||
NamespaceTypeGuestDefault NamespaceType = "GuestDefault"
|
||||
)
|
||||
|
||||
// HostComputeNamespace represents a namespace (AKA compartment) in
|
||||
type HostComputeNamespace struct {
|
||||
Id string `json:"ID,omitempty"`
|
||||
NamespaceId uint32 `json:",omitempty"`
|
||||
Type NamespaceType `json:",omitempty"` // Host, HostDefault, Guest, GuestDefault
|
||||
Resources []NamespaceResource `json:",omitempty"`
|
||||
SchemaVersion SchemaVersion `json:",omitempty"`
|
||||
}
|
||||
|
||||
// ModifyNamespaceSettingRequest is the structure used to send request to modify a namespace.
|
||||
// Used to Add/Remove an endpoints and containers to/from a namespace.
|
||||
type ModifyNamespaceSettingRequest struct {
|
||||
ResourceType NamespaceResourceType `json:",omitempty"` // Container, Endpoint
|
||||
RequestType RequestType `json:",omitempty"` // Add, Remove, Update, Refresh
|
||||
Settings json.RawMessage `json:",omitempty"`
|
||||
}
|
||||
|
||||
func getNamespace(namespaceGuid guid.GUID, query string) (*HostComputeNamespace, error) {
|
||||
// Open namespace.
|
||||
var (
|
||||
namespaceHandle hcnNamespace
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
hr := hcnOpenNamespace(&namespaceGuid, &namespaceHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenNamespace", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query namespace.
|
||||
hr = hcnQueryNamespaceProperties(namespaceHandle, query, &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryNamespaceProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close namespace.
|
||||
hr = hcnCloseNamespace(namespaceHandle)
|
||||
if err := checkForErrors("hcnCloseNamespace", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeNamespace
|
||||
var outputNamespace HostComputeNamespace
|
||||
if err := json.Unmarshal([]byte(properties), &outputNamespace); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputNamespace, nil
|
||||
}
|
||||
|
||||
func enumerateNamespaces(query string) ([]HostComputeNamespace, error) {
|
||||
// Enumerate all Namespace Guids
|
||||
var (
|
||||
resultBuffer *uint16
|
||||
namespaceBuffer *uint16
|
||||
)
|
||||
hr := hcnEnumerateNamespaces(query, &namespaceBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnEnumerateNamespaces", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
namespaces := interop.ConvertAndFreeCoTaskMemString(namespaceBuffer)
|
||||
var namespaceIds []guid.GUID
|
||||
if err := json.Unmarshal([]byte(namespaces), &namespaceIds); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var outputNamespaces []HostComputeNamespace
|
||||
for _, namespaceGuid := range namespaceIds {
|
||||
namespace, err := getNamespace(namespaceGuid, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
outputNamespaces = append(outputNamespaces, *namespace)
|
||||
}
|
||||
return outputNamespaces, nil
|
||||
}
|
||||
|
||||
func createNamespace(settings string) (*HostComputeNamespace, error) {
|
||||
// Create new namespace.
|
||||
var (
|
||||
namespaceHandle hcnNamespace
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
namespaceGuid := guid.GUID{}
|
||||
hr := hcnCreateNamespace(&namespaceGuid, settings, &namespaceHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnCreateNamespace", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query namespace.
|
||||
hcnQuery := defaultQuery()
|
||||
query, err := json.Marshal(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hr = hcnQueryNamespaceProperties(namespaceHandle, string(query), &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryNamespaceProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close namespace.
|
||||
hr = hcnCloseNamespace(namespaceHandle)
|
||||
if err := checkForErrors("hcnCloseNamespace", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeNamespace
|
||||
var outputNamespace HostComputeNamespace
|
||||
if err := json.Unmarshal([]byte(properties), &outputNamespace); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputNamespace, nil
|
||||
}
|
||||
|
||||
func modifyNamespace(namespaceId string, settings string) (*HostComputeNamespace, error) {
|
||||
namespaceGuid := guid.FromString(namespaceId)
|
||||
// Open namespace.
|
||||
var (
|
||||
namespaceHandle hcnNamespace
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
hr := hcnOpenNamespace(&namespaceGuid, &namespaceHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenNamespace", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Modify namespace.
|
||||
hr = hcnModifyNamespace(namespaceHandle, settings, &resultBuffer)
|
||||
if err := checkForErrors("hcnModifyNamespace", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query namespace.
|
||||
hcnQuery := defaultQuery()
|
||||
query, err := json.Marshal(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hr = hcnQueryNamespaceProperties(namespaceHandle, string(query), &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryNamespaceProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close namespace.
|
||||
hr = hcnCloseNamespace(namespaceHandle)
|
||||
if err := checkForErrors("hcnCloseNamespace", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to Namespace
|
||||
var outputNamespace HostComputeNamespace
|
||||
if err := json.Unmarshal([]byte(properties), &outputNamespace); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputNamespace, nil
|
||||
}
|
||||
|
||||
func deleteNamespace(namespaceId string) error {
|
||||
namespaceGuid := guid.FromString(namespaceId)
|
||||
var resultBuffer *uint16
|
||||
hr := hcnDeleteNamespace(&namespaceGuid, &resultBuffer)
|
||||
if err := checkForErrors("hcnDeleteNamespace", hr, resultBuffer); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListNamespaces makes a call to list all available namespaces.
|
||||
func ListNamespaces() ([]HostComputeNamespace, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
namespaces, err := ListNamespacesQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return namespaces, nil
|
||||
}
|
||||
|
||||
// ListNamespacesQuery makes a call to query the list of available namespaces.
|
||||
func ListNamespacesQuery(query HostComputeQuery) ([]HostComputeNamespace, error) {
|
||||
queryJson, err := json.Marshal(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
namespaces, err := enumerateNamespaces(string(queryJson))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return namespaces, nil
|
||||
}
|
||||
|
||||
// GetNamespaceByID returns the Namespace specified by Id.
|
||||
func GetNamespaceByID(namespaceId string) (*HostComputeNamespace, error) {
|
||||
return getNamespace(guid.FromString(namespaceId), defaultQueryJson())
|
||||
}
|
||||
|
||||
// GetNamespaceEndpointIds returns the endpoints of the Namespace specified by Id.
|
||||
func GetNamespaceEndpointIds(namespaceId string) ([]string, error) {
|
||||
namespace, err := GetNamespaceByID(namespaceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var endpointsIds []string
|
||||
for _, resource := range namespace.Resources {
|
||||
if resource.Type == "Endpoint" {
|
||||
var endpointResource NamespaceResourceEndpoint
|
||||
if err := json.Unmarshal([]byte(resource.Data), &endpointResource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpointsIds = append(endpointsIds, endpointResource.Id)
|
||||
}
|
||||
}
|
||||
return endpointsIds, nil
|
||||
}
|
||||
|
||||
// GetNamespaceContainerIds returns the containers of the Namespace specified by Id.
|
||||
func GetNamespaceContainerIds(namespaceId string) ([]string, error) {
|
||||
namespace, err := GetNamespaceByID(namespaceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var containerIds []string
|
||||
for _, resource := range namespace.Resources {
|
||||
if resource.Type == "Container" {
|
||||
var contaienrResource NamespaceResourceContainer
|
||||
if err := json.Unmarshal([]byte(resource.Data), &contaienrResource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
containerIds = append(containerIds, contaienrResource.Id)
|
||||
}
|
||||
}
|
||||
return containerIds, nil
|
||||
}
|
||||
|
||||
// NewNamespace creates a new Namespace object
|
||||
func NewNamespace(nsType NamespaceType) *HostComputeNamespace {
|
||||
return &HostComputeNamespace{
|
||||
Type: nsType,
|
||||
SchemaVersion: V2SchemaVersion(),
|
||||
}
|
||||
}
|
||||
|
||||
// Create Namespace.
|
||||
func (namespace *HostComputeNamespace) Create() (*HostComputeNamespace, error) {
|
||||
logrus.Debugf("hcn::HostComputeNamespace::Create id=%s", namespace.Id)
|
||||
|
||||
jsonString, err := json.Marshal(namespace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debugf("hcn::HostComputeNamespace::Create JSON: %s", jsonString)
|
||||
namespace, hcnErr := createNamespace(string(jsonString))
|
||||
if hcnErr != nil {
|
||||
return nil, hcnErr
|
||||
}
|
||||
return namespace, nil
|
||||
}
|
||||
|
||||
// Delete Namespace.
|
||||
func (namespace *HostComputeNamespace) Delete() error {
|
||||
logrus.Debugf("hcn::HostComputeNamespace::Delete id=%s", namespace.Id)
|
||||
|
||||
if err := deleteNamespace(namespace.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sync Namespace endpoints with the appropriate sandbox container holding the
|
||||
// network namespace open. If no sandbox container is found for this namespace
|
||||
// this method is determined to be a success and will not return an error in
|
||||
// this case. If the sandbox container is found and a sync is initiated any
|
||||
// failures will be returned via this method.
|
||||
//
|
||||
// This call initiates a sync between endpoints and the matching UtilityVM
|
||||
// hosting those endpoints. It is safe to call for any `NamespaceType` but
|
||||
// `NamespaceTypeGuest` is the only case when a sync will actually occur. For
|
||||
// `NamespaceTypeHost` the process container will be automatically synchronized
|
||||
// when the the endpoint is added via `AddNamespaceEndpoint`.
|
||||
//
|
||||
// Note: This method sync's both additions and removals of endpoints from a
|
||||
// `NamespaceTypeGuest` namespace.
|
||||
func (namespace *HostComputeNamespace) Sync() error {
|
||||
logrus.WithField("id", namespace.Id).Debugf("hcs::HostComputeNamespace::Sync")
|
||||
|
||||
// We only attempt a sync for namespace guest.
|
||||
if namespace.Type != NamespaceTypeGuest {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Look in the registry for the key to map from namespace id to pod-id
|
||||
cfg, err := icni.LoadPersistedNamespaceConfig(namespace.Id)
|
||||
if err != nil {
|
||||
if regstate.IsNotFoundError(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
req := runhcs.VMRequest{
|
||||
ID: cfg.ContainerID,
|
||||
Op: runhcs.OpSyncNamespace,
|
||||
}
|
||||
shimPath := runhcs.VMPipePath(cfg.HostUniqueID)
|
||||
if err := runhcs.IssueVMRequest(shimPath, &req); err != nil {
|
||||
// The shim is likey gone. Simply ignore the sync as if it didn't exist.
|
||||
if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ERROR_FILE_NOT_FOUND {
|
||||
// Remove the reg key there is no point to try again
|
||||
cfg.Remove()
|
||||
return nil
|
||||
}
|
||||
f := map[string]interface{}{
|
||||
"id": namespace.Id,
|
||||
"container-id": cfg.ContainerID,
|
||||
}
|
||||
logrus.WithFields(f).
|
||||
WithError(err).
|
||||
Debugf("hcs::HostComputeNamespace::Sync failed to connect to shim pipe: '%s'", shimPath)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ModifyNamespaceSettings updates the Endpoints/Containers of a Namespace.
|
||||
func ModifyNamespaceSettings(namespaceId string, request *ModifyNamespaceSettingRequest) error {
|
||||
logrus.Debugf("hcn::HostComputeNamespace::ModifyNamespaceSettings id=%s", namespaceId)
|
||||
|
||||
namespaceSettings, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = modifyNamespace(namespaceId, string(namespaceSettings))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddNamespaceEndpoint adds an endpoint to a Namespace.
|
||||
func AddNamespaceEndpoint(namespaceId string, endpointId string) error {
|
||||
logrus.Debugf("hcn::HostComputeEndpoint::AddNamespaceEndpoint id=%s", endpointId)
|
||||
|
||||
mapA := map[string]string{"EndpointId": endpointId}
|
||||
settingsJson, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
requestMessage := &ModifyNamespaceSettingRequest{
|
||||
ResourceType: NamespaceResourceTypeEndpoint,
|
||||
RequestType: RequestTypeAdd,
|
||||
Settings: settingsJson,
|
||||
}
|
||||
|
||||
return ModifyNamespaceSettings(namespaceId, requestMessage)
|
||||
}
|
||||
|
||||
// RemoveNamespaceEndpoint removes an endpoint from a Namespace.
|
||||
func RemoveNamespaceEndpoint(namespaceId string, endpointId string) error {
|
||||
logrus.Debugf("hcn::HostComputeNamespace::RemoveNamespaceEndpoint id=%s", endpointId)
|
||||
|
||||
mapA := map[string]string{"EndpointId": endpointId}
|
||||
settingsJson, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
requestMessage := &ModifyNamespaceSettingRequest{
|
||||
ResourceType: NamespaceResourceTypeEndpoint,
|
||||
RequestType: RequestTypeRemove,
|
||||
Settings: settingsJson,
|
||||
}
|
||||
|
||||
return ModifyNamespaceSettings(namespaceId, requestMessage)
|
||||
}
|
451
vendor/github.com/Microsoft/hcsshim/hcn/hcnnamespace_test.go
generated
vendored
Normal file
451
vendor/github.com/Microsoft/hcsshim/hcn/hcnnamespace_test.go
generated
vendored
Normal file
@ -0,0 +1,451 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/cni"
|
||||
"github.com/Microsoft/hcsshim/internal/guid"
|
||||
)
|
||||
|
||||
func TestNewNamespace(t *testing.T) {
|
||||
_ = NewNamespace(NamespaceTypeHost)
|
||||
_ = NewNamespace(NamespaceTypeHostDefault)
|
||||
_ = NewNamespace(NamespaceTypeGuest)
|
||||
_ = NewNamespace(NamespaceTypeGuestDefault)
|
||||
}
|
||||
|
||||
func TestCreateDeleteNamespace(t *testing.T) {
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
jsonString, err := json.Marshal(namespace)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("Namespace JSON:\n%s \n", jsonString)
|
||||
|
||||
err = namespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateDeleteNamespaceGuest(t *testing.T) {
|
||||
namespace := &HostComputeNamespace{
|
||||
Type: NamespaceTypeGuestDefault,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
hnsNamespace, err := namespace.Create()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = hnsNamespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNamespaceById(t *testing.T) {
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundNamespace, err := GetNamespaceByID(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if foundNamespace == nil {
|
||||
t.Fatal("No namespace found")
|
||||
}
|
||||
|
||||
err = namespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListNamespaces(t *testing.T) {
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundNamespaces, err := ListNamespaces()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundNamespaces) == 0 {
|
||||
t.Fatal("No Namespaces found")
|
||||
}
|
||||
|
||||
err = namespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNamespaceEndpointIds(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = endpoint.NamespaceAttach(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundEndpoints, err := GetNamespaceEndpointIds(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundEndpoints) == 0 {
|
||||
t.Fatal("No Endpoint found")
|
||||
}
|
||||
err = endpoint.NamespaceDetach(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = namespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNamespaceContainers(t *testing.T) {
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foundEndpoints, err := GetNamespaceContainerIds(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundEndpoints) != 0 {
|
||||
t.Fatal("Found containers when none should exist")
|
||||
}
|
||||
|
||||
err = namespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddRemoveNamespaceEndpoint(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = AddNamespaceEndpoint(namespace.Id, endpoint.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundEndpoints, err := GetNamespaceEndpointIds(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundEndpoints) == 0 {
|
||||
t.Fatal("No Endpoint found")
|
||||
}
|
||||
err = RemoveNamespaceEndpoint(namespace.Id, endpoint.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = namespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyNamespaceSettings(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endpoint, err := HcnCreateTestEndpoint(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
namespace, err := HcnCreateTestNamespace()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mapA := map[string]string{"EndpointId": endpoint.Id}
|
||||
settingsJson, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
requestMessage := &ModifyNamespaceSettingRequest{
|
||||
ResourceType: NamespaceResourceTypeEndpoint,
|
||||
RequestType: RequestTypeAdd,
|
||||
Settings: settingsJson,
|
||||
}
|
||||
|
||||
err = ModifyNamespaceSettings(namespace.Id, requestMessage)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundEndpoints, err := GetNamespaceEndpointIds(namespace.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(foundEndpoints) == 0 {
|
||||
t.Fatal("No Endpoint found")
|
||||
}
|
||||
err = RemoveNamespaceEndpoint(namespace.Id, endpoint.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = namespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Sync Tests
|
||||
|
||||
func TestSyncNamespaceHostDefault(t *testing.T) {
|
||||
namespace := &HostComputeNamespace{
|
||||
Type: NamespaceTypeHostDefault,
|
||||
NamespaceId: 5,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
hnsNamespace, err := namespace.Create()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Host namespace types should be no-op success
|
||||
err = hnsNamespace.Sync()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = hnsNamespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncNamespaceHost(t *testing.T) {
|
||||
namespace := &HostComputeNamespace{
|
||||
Type: NamespaceTypeHost,
|
||||
NamespaceId: 5,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
hnsNamespace, err := namespace.Create()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Host namespace types should be no-op success
|
||||
err = hnsNamespace.Sync()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = hnsNamespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncNamespaceGuestNoReg(t *testing.T) {
|
||||
namespace := &HostComputeNamespace{
|
||||
Type: NamespaceTypeGuest,
|
||||
NamespaceId: 5,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
hnsNamespace, err := namespace.Create()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Guest namespace type with out reg state should be no-op success
|
||||
err = hnsNamespace.Sync()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = hnsNamespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncNamespaceGuestDefaultNoReg(t *testing.T) {
|
||||
namespace := &HostComputeNamespace{
|
||||
Type: NamespaceTypeGuestDefault,
|
||||
NamespaceId: 5,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
hnsNamespace, err := namespace.Create()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Guest namespace type with out reg state should be no-op success
|
||||
err = hnsNamespace.Sync()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = hnsNamespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncNamespaceGuest(t *testing.T) {
|
||||
namespace := &HostComputeNamespace{
|
||||
Type: NamespaceTypeGuest,
|
||||
NamespaceId: 5,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
hnsNamespace, err := namespace.Create()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Create registry state
|
||||
pnc := cni.NewPersistedNamespaceConfig(t.Name(), "test-container", guid.New())
|
||||
err = pnc.Store()
|
||||
if err != nil {
|
||||
pnc.Remove()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Guest namespace type with reg state but not Vm shim should pass...
|
||||
// after trying to connect to VM shim that it doesn't find and remove the Key so it doesn't look again.
|
||||
err = hnsNamespace.Sync()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = pnc.Remove()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = hnsNamespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncNamespaceGuestDefault(t *testing.T) {
|
||||
namespace := &HostComputeNamespace{
|
||||
Type: NamespaceTypeGuestDefault,
|
||||
NamespaceId: 5,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
hnsNamespace, err := namespace.Create()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Create registry state
|
||||
pnc := cni.NewPersistedNamespaceConfig(t.Name(), "test-container", guid.New())
|
||||
err = pnc.Store()
|
||||
if err != nil {
|
||||
pnc.Remove()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Guest namespace type with reg state but not Vm shim should pass...
|
||||
// after trying to connect to VM shim that it doesn't find and remove the Key so it doesn't look again.
|
||||
err = hnsNamespace.Sync()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = pnc.Remove()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = hnsNamespace.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
418
vendor/github.com/Microsoft/hcsshim/hcn/hcnnetwork.go
generated
vendored
Normal file
418
vendor/github.com/Microsoft/hcsshim/hcn/hcnnetwork.go
generated
vendored
Normal file
@ -0,0 +1,418 @@
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/guid"
|
||||
"github.com/Microsoft/hcsshim/internal/interop"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Route is assoicated with a subnet.
|
||||
type Route struct {
|
||||
NextHop string `json:",omitempty"`
|
||||
DestinationPrefix string `json:",omitempty"`
|
||||
Metric uint16 `json:",omitempty"`
|
||||
}
|
||||
|
||||
// Subnet is assoicated with a Ipam.
|
||||
type Subnet struct {
|
||||
IpAddressPrefix string `json:",omitempty"`
|
||||
Policies []json.RawMessage `json:",omitempty"`
|
||||
Routes []Route `json:",omitempty"`
|
||||
}
|
||||
|
||||
// Ipam (Internet Protocol Addres Management) is assoicated with a network
|
||||
// and represents the address space(s) of a network.
|
||||
type Ipam struct {
|
||||
Type string `json:",omitempty"` // Ex: Static, DHCP
|
||||
Subnets []Subnet `json:",omitempty"`
|
||||
}
|
||||
|
||||
// MacRange is associated with MacPool and respresents the start and end addresses.
|
||||
type MacRange struct {
|
||||
StartMacAddress string `json:",omitempty"`
|
||||
EndMacAddress string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// MacPool is assoicated with a network and represents pool of MacRanges.
|
||||
type MacPool struct {
|
||||
Ranges []MacRange `json:",omitempty"`
|
||||
}
|
||||
|
||||
// Dns (Domain Name System is associated with a network.
|
||||
type Dns struct {
|
||||
Domain string `json:",omitempty"`
|
||||
Search []string `json:",omitempty"`
|
||||
ServerList []string `json:",omitempty"`
|
||||
Options []string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// NetworkType are various networks.
|
||||
type NetworkType string
|
||||
|
||||
// NetworkType const
|
||||
const (
|
||||
NAT NetworkType = "NAT"
|
||||
Transparent NetworkType = "Transparent"
|
||||
L2Bridge NetworkType = "L2Bridge"
|
||||
L2Tunnel NetworkType = "L2Tunnel"
|
||||
ICS NetworkType = "ICS"
|
||||
Private NetworkType = "Private"
|
||||
Overlay NetworkType = "Overlay"
|
||||
)
|
||||
|
||||
// NetworkFlags are various network flags.
|
||||
type NetworkFlags uint32
|
||||
|
||||
// NetworkFlags const
|
||||
const (
|
||||
None NetworkFlags = 0
|
||||
EnableNonPersistent NetworkFlags = 8
|
||||
)
|
||||
|
||||
// HostComputeNetwork represents a network
|
||||
type HostComputeNetwork struct {
|
||||
Id string `json:"ID,omitempty"`
|
||||
Name string `json:",omitempty"`
|
||||
Type NetworkType `json:",omitempty"`
|
||||
Policies []NetworkPolicy `json:",omitempty"`
|
||||
MacPool MacPool `json:",omitempty"`
|
||||
Dns Dns `json:",omitempty"`
|
||||
Ipams []Ipam `json:",omitempty"`
|
||||
Flags NetworkFlags `json:",omitempty"` // 0: None
|
||||
SchemaVersion SchemaVersion `json:",omitempty"`
|
||||
}
|
||||
|
||||
// NetworkResourceType are the 3 different Network settings resources.
|
||||
type NetworkResourceType string
|
||||
|
||||
var (
|
||||
// NetworkResourceTypePolicy is for Network's policies. Ex: RemoteSubnet
|
||||
NetworkResourceTypePolicy NetworkResourceType = "Policy"
|
||||
// NetworkResourceTypeDNS is for Network's DNS settings.
|
||||
NetworkResourceTypeDNS NetworkResourceType = "DNS"
|
||||
// NetworkResourceTypeExtension is for Network's extension settings.
|
||||
NetworkResourceTypeExtension NetworkResourceType = "Extension"
|
||||
)
|
||||
|
||||
// ModifyNetworkSettingRequest is the structure used to send request to modify an network.
|
||||
// Used to update DNS/extension/policy on an network.
|
||||
type ModifyNetworkSettingRequest struct {
|
||||
ResourceType NetworkResourceType `json:",omitempty"` // Policy, DNS, Extension
|
||||
RequestType RequestType `json:",omitempty"` // Add, Remove, Update, Refresh
|
||||
Settings json.RawMessage `json:",omitempty"`
|
||||
}
|
||||
|
||||
type PolicyNetworkRequest struct {
|
||||
Policies []NetworkPolicy `json:",omitempty"`
|
||||
}
|
||||
|
||||
func getNetwork(networkGuid guid.GUID, query string) (*HostComputeNetwork, error) {
|
||||
// Open network.
|
||||
var (
|
||||
networkHandle hcnNetwork
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
hr := hcnOpenNetwork(&networkGuid, &networkHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenNetwork", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query network.
|
||||
hr = hcnQueryNetworkProperties(networkHandle, query, &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryNetworkProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close network.
|
||||
hr = hcnCloseNetwork(networkHandle)
|
||||
if err := checkForErrors("hcnCloseNetwork", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeNetwork
|
||||
var outputNetwork HostComputeNetwork
|
||||
if err := json.Unmarshal([]byte(properties), &outputNetwork); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputNetwork, nil
|
||||
}
|
||||
|
||||
func enumerateNetworks(query string) ([]HostComputeNetwork, error) {
|
||||
// Enumerate all Network Guids
|
||||
var (
|
||||
resultBuffer *uint16
|
||||
networkBuffer *uint16
|
||||
)
|
||||
hr := hcnEnumerateNetworks(query, &networkBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnEnumerateNetworks", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
networks := interop.ConvertAndFreeCoTaskMemString(networkBuffer)
|
||||
var networkIds []guid.GUID
|
||||
if err := json.Unmarshal([]byte(networks), &networkIds); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var outputNetworks []HostComputeNetwork
|
||||
for _, networkGuid := range networkIds {
|
||||
network, err := getNetwork(networkGuid, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
outputNetworks = append(outputNetworks, *network)
|
||||
}
|
||||
return outputNetworks, nil
|
||||
}
|
||||
|
||||
func createNetwork(settings string) (*HostComputeNetwork, error) {
|
||||
// Create new network.
|
||||
var (
|
||||
networkHandle hcnNetwork
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
networkGuid := guid.GUID{}
|
||||
hr := hcnCreateNetwork(&networkGuid, settings, &networkHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnCreateNetwork", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query network.
|
||||
hcnQuery := defaultQuery()
|
||||
query, err := json.Marshal(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hr = hcnQueryNetworkProperties(networkHandle, string(query), &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryNetworkProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close network.
|
||||
hr = hcnCloseNetwork(networkHandle)
|
||||
if err := checkForErrors("hcnCloseNetwork", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeNetwork
|
||||
var outputNetwork HostComputeNetwork
|
||||
if err := json.Unmarshal([]byte(properties), &outputNetwork); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputNetwork, nil
|
||||
}
|
||||
|
||||
func modifyNetwork(networkId string, settings string) (*HostComputeNetwork, error) {
|
||||
networkGuid := guid.FromString(networkId)
|
||||
// Open Network
|
||||
var (
|
||||
networkHandle hcnNetwork
|
||||
resultBuffer *uint16
|
||||
propertiesBuffer *uint16
|
||||
)
|
||||
hr := hcnOpenNetwork(&networkGuid, &networkHandle, &resultBuffer)
|
||||
if err := checkForErrors("hcnOpenNetwork", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Modify Network
|
||||
hr = hcnModifyNetwork(networkHandle, settings, &resultBuffer)
|
||||
if err := checkForErrors("hcnModifyNetwork", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query network.
|
||||
hcnQuery := defaultQuery()
|
||||
query, err := json.Marshal(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hr = hcnQueryNetworkProperties(networkHandle, string(query), &propertiesBuffer, &resultBuffer)
|
||||
if err := checkForErrors("hcnQueryNetworkProperties", hr, resultBuffer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
|
||||
// Close network.
|
||||
hr = hcnCloseNetwork(networkHandle)
|
||||
if err := checkForErrors("hcnCloseNetwork", hr, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Convert output to HostComputeNetwork
|
||||
var outputNetwork HostComputeNetwork
|
||||
if err := json.Unmarshal([]byte(properties), &outputNetwork); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &outputNetwork, nil
|
||||
}
|
||||
|
||||
func deleteNetwork(networkId string) error {
|
||||
networkGuid := guid.FromString(networkId)
|
||||
var resultBuffer *uint16
|
||||
hr := hcnDeleteNetwork(&networkGuid, &resultBuffer)
|
||||
if err := checkForErrors("hcnDeleteNetwork", hr, resultBuffer); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListNetworks makes a call to list all available networks.
|
||||
func ListNetworks() ([]HostComputeNetwork, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
networks, err := ListNetworksQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return networks, nil
|
||||
}
|
||||
|
||||
// ListNetworksQuery makes a call to query the list of available networks.
|
||||
func ListNetworksQuery(query HostComputeQuery) ([]HostComputeNetwork, error) {
|
||||
queryJson, err := json.Marshal(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
networks, err := enumerateNetworks(string(queryJson))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return networks, nil
|
||||
}
|
||||
|
||||
// GetNetworkByID returns the network specified by Id.
|
||||
func GetNetworkByID(networkID string) (*HostComputeNetwork, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
mapA := map[string]string{"ID": networkID}
|
||||
filter, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hcnQuery.Filter = string(filter)
|
||||
|
||||
networks, err := ListNetworksQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(networks) == 0 {
|
||||
return nil, NetworkNotFoundError{NetworkID: networkID}
|
||||
}
|
||||
return &networks[0], err
|
||||
}
|
||||
|
||||
// GetNetworkByName returns the network specified by Name.
|
||||
func GetNetworkByName(networkName string) (*HostComputeNetwork, error) {
|
||||
hcnQuery := defaultQuery()
|
||||
mapA := map[string]string{"Name": networkName}
|
||||
filter, err := json.Marshal(mapA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hcnQuery.Filter = string(filter)
|
||||
|
||||
networks, err := ListNetworksQuery(hcnQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(networks) == 0 {
|
||||
return nil, NetworkNotFoundError{NetworkName: networkName}
|
||||
}
|
||||
return &networks[0], err
|
||||
}
|
||||
|
||||
// Create Network.
|
||||
func (network *HostComputeNetwork) Create() (*HostComputeNetwork, error) {
|
||||
logrus.Debugf("hcn::HostComputeNetwork::Create id=%s", network.Id)
|
||||
|
||||
jsonString, err := json.Marshal(network)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debugf("hcn::HostComputeNetwork::Create JSON: %s", jsonString)
|
||||
network, hcnErr := createNetwork(string(jsonString))
|
||||
if hcnErr != nil {
|
||||
return nil, hcnErr
|
||||
}
|
||||
return network, nil
|
||||
}
|
||||
|
||||
// Delete Network.
|
||||
func (network *HostComputeNetwork) Delete() error {
|
||||
logrus.Debugf("hcn::HostComputeNetwork::Delete id=%s", network.Id)
|
||||
|
||||
if err := deleteNetwork(network.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ModifyNetworkSettings updates the Policy for a network.
|
||||
func (network *HostComputeNetwork) ModifyNetworkSettings(request *ModifyNetworkSettingRequest) error {
|
||||
logrus.Debugf("hcn::HostComputeNetwork::ModifyNetworkSettings id=%s", network.Id)
|
||||
|
||||
networkSettingsRequest, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = modifyNetwork(network.Id, string(networkSettingsRequest))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddPolicy applies a Policy (ex: RemoteSubnet) on the Network.
|
||||
func (network *HostComputeNetwork) AddPolicy(networkPolicy PolicyNetworkRequest) error {
|
||||
logrus.Debugf("hcn::HostComputeNetwork::AddPolicy id=%s", network.Id)
|
||||
|
||||
settingsJson, err := json.Marshal(networkPolicy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
requestMessage := &ModifyNetworkSettingRequest{
|
||||
ResourceType: NetworkResourceTypePolicy,
|
||||
RequestType: RequestTypeAdd,
|
||||
Settings: settingsJson,
|
||||
}
|
||||
|
||||
return network.ModifyNetworkSettings(requestMessage)
|
||||
}
|
||||
|
||||
// RemovePolicy removes a Policy (ex: RemoteSubnet) from the Network.
|
||||
func (network *HostComputeNetwork) RemovePolicy(networkPolicy PolicyNetworkRequest) error {
|
||||
logrus.Debugf("hcn::HostComputeNetwork::RemovePolicy id=%s", network.Id)
|
||||
|
||||
settingsJson, err := json.Marshal(networkPolicy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
requestMessage := &ModifyNetworkSettingRequest{
|
||||
ResourceType: NetworkResourceTypePolicy,
|
||||
RequestType: RequestTypeRemove,
|
||||
Settings: settingsJson,
|
||||
}
|
||||
|
||||
return network.ModifyNetworkSettings(requestMessage)
|
||||
}
|
||||
|
||||
// CreateEndpoint creates an endpoint on the Network.
|
||||
func (network *HostComputeNetwork) CreateEndpoint(endpoint *HostComputeEndpoint) (*HostComputeEndpoint, error) {
|
||||
isRemote := endpoint.Flags&EndpointFlagsRemoteEndpoint != 0
|
||||
logrus.Debugf("hcn::HostComputeNetwork::CreatEndpoint, networkId=%s remote=%t", network.Id, isRemote)
|
||||
|
||||
endpoint.HostComputeNetwork = network.Id
|
||||
endpointSettings, err := json.Marshal(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newEndpoint, err := createEndpoint(network.Id, string(endpointSettings))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newEndpoint, nil
|
||||
}
|
||||
|
||||
// CreateRemoteEndpoint creates a remote endpoint on the Network.
|
||||
func (network *HostComputeNetwork) CreateRemoteEndpoint(endpoint *HostComputeEndpoint) (*HostComputeEndpoint, error) {
|
||||
endpoint.Flags = EndpointFlagsRemoteEndpoint | endpoint.Flags
|
||||
return network.CreateEndpoint(endpoint)
|
||||
}
|
165
vendor/github.com/Microsoft/hcsshim/hcn/hcnnetwork_test.go
generated
vendored
Normal file
165
vendor/github.com/Microsoft/hcsshim/hcn/hcnnetwork_test.go
generated
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateDeleteNetwork(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jsonString, err := json.Marshal(network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("Network JSON:\n%s \n", jsonString)
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNetworkByName(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
network, err = GetNetworkByName(network.Name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if network == nil {
|
||||
t.Fatal("No Network found")
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNetworkById(t *testing.T) {
|
||||
network, err := HcnCreateTestNATNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
network, err = GetNetworkByID(network.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if network == nil {
|
||||
t.Fatal("No Network found")
|
||||
}
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListNetwork(t *testing.T) {
|
||||
_, err := ListNetworks()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testNetworkPolicy(t *testing.T, policiesToTest *PolicyNetworkRequest) {
|
||||
network, err := CreateTestOverlayNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
network.AddPolicy(*policiesToTest)
|
||||
|
||||
//Reload the network object from HNS.
|
||||
network, err = GetNetworkByID(network.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, policyToTest := range policiesToTest.Policies {
|
||||
foundPolicy := false
|
||||
for _, policy := range network.Policies {
|
||||
if policy.Type == policyToTest.Type {
|
||||
foundPolicy = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundPolicy {
|
||||
t.Fatalf("Could not find %s policy on network.", policyToTest.Type)
|
||||
}
|
||||
}
|
||||
|
||||
network.RemovePolicy(*policiesToTest)
|
||||
|
||||
//Reload the network object from HNS.
|
||||
network, err = GetNetworkByID(network.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, policyToTest := range policiesToTest.Policies {
|
||||
foundPolicy := false
|
||||
for _, policy := range network.Policies {
|
||||
if policy.Type == policyToTest.Type {
|
||||
foundPolicy = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if foundPolicy {
|
||||
t.Fatalf("Found %s policy on network when it should have been deleted.", policyToTest.Type)
|
||||
}
|
||||
}
|
||||
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddRemoveRemoteSubnetRoutePolicy(t *testing.T) {
|
||||
|
||||
remoteSubnetRoutePolicy, err := HcnCreateTestRemoteSubnetRoute()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testNetworkPolicy(t, remoteSubnetRoutePolicy)
|
||||
}
|
||||
|
||||
func TestAddRemoveHostRoutePolicy(t *testing.T) {
|
||||
|
||||
hostRoutePolicy, err := HcnCreateTestHostRoute()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testNetworkPolicy(t, hostRoutePolicy)
|
||||
}
|
||||
|
||||
func TestNetworkFlags(t *testing.T) {
|
||||
|
||||
network, err := CreateTestOverlayNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
//Reload the network object from HNS.
|
||||
network, err = GetNetworkByID(network.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if network.Flags != EnableNonPersistent {
|
||||
t.Errorf("EnableNonPersistent flag (%d) is not set on network", EnableNonPersistent)
|
||||
}
|
||||
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
217
vendor/github.com/Microsoft/hcsshim/hcn/hcnpolicy.go
generated
vendored
Normal file
217
vendor/github.com/Microsoft/hcsshim/hcn/hcnpolicy.go
generated
vendored
Normal file
@ -0,0 +1,217 @@
|
||||
package hcn
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// EndpointPolicyType are the potential Policies that apply to Endpoints.
|
||||
type EndpointPolicyType string
|
||||
|
||||
// EndpointPolicyType const
|
||||
const (
|
||||
PortMapping EndpointPolicyType = "PortMapping"
|
||||
ACL EndpointPolicyType = "ACL"
|
||||
QOS EndpointPolicyType = "QOS"
|
||||
L2Driver EndpointPolicyType = "L2Driver"
|
||||
OutBoundNAT EndpointPolicyType = "OutBoundNAT"
|
||||
SDNRoute EndpointPolicyType = "SDNRoute"
|
||||
L4Proxy EndpointPolicyType = "L4Proxy"
|
||||
PortName EndpointPolicyType = "PortName"
|
||||
EncapOverhead EndpointPolicyType = "EncapOverhead"
|
||||
// Endpoint and Network have InterfaceConstraint and ProviderAddress
|
||||
NetworkProviderAddress EndpointPolicyType = "ProviderAddress"
|
||||
NetworkInterfaceConstraint EndpointPolicyType = "InterfaceConstraint"
|
||||
)
|
||||
|
||||
// EndpointPolicy is a collection of Policy settings for an Endpoint.
|
||||
type EndpointPolicy struct {
|
||||
Type EndpointPolicyType `json:""`
|
||||
Settings json.RawMessage `json:",omitempty"`
|
||||
}
|
||||
|
||||
// NetworkPolicyType are the potential Policies that apply to Networks.
|
||||
type NetworkPolicyType string
|
||||
|
||||
// NetworkPolicyType const
|
||||
const (
|
||||
SourceMacAddress NetworkPolicyType = "SourceMacAddress"
|
||||
NetAdapterName NetworkPolicyType = "NetAdapterName"
|
||||
VSwitchExtension NetworkPolicyType = "VSwitchExtension"
|
||||
DrMacAddress NetworkPolicyType = "DrMacAddress"
|
||||
AutomaticDNS NetworkPolicyType = "AutomaticDNS"
|
||||
InterfaceConstraint NetworkPolicyType = "InterfaceConstraint"
|
||||
ProviderAddress NetworkPolicyType = "ProviderAddress"
|
||||
RemoteSubnetRoute NetworkPolicyType = "RemoteSubnetRoute"
|
||||
HostRoute NetworkPolicyType = "HostRoute"
|
||||
)
|
||||
|
||||
// NetworkPolicy is a collection of Policy settings for a Network.
|
||||
type NetworkPolicy struct {
|
||||
Type NetworkPolicyType `json:""`
|
||||
Settings json.RawMessage `json:",omitempty"`
|
||||
}
|
||||
|
||||
// SubnetPolicyType are the potential Policies that apply to Subnets.
|
||||
type SubnetPolicyType string
|
||||
|
||||
// SubnetPolicyType const
|
||||
const (
|
||||
VLAN SubnetPolicyType = "VLAN"
|
||||
VSID SubnetPolicyType = "VSID"
|
||||
)
|
||||
|
||||
// SubnetPolicy is a collection of Policy settings for a Subnet.
|
||||
type SubnetPolicy struct {
|
||||
Type SubnetPolicyType `json:""`
|
||||
Settings json.RawMessage `json:",omitempty"`
|
||||
}
|
||||
|
||||
/// Endpoint Policy objects
|
||||
|
||||
// PortMappingPolicySetting defines Port Mapping (NAT)
|
||||
type PortMappingPolicySetting struct {
|
||||
Protocol uint32 `json:",omitempty"` // EX: TCP = 6, UDP = 17
|
||||
InternalPort uint16 `json:",omitempty"`
|
||||
ExternalPort uint16 `json:",omitempty"`
|
||||
VIP string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// ActionType associated with ACLs. Value is either Allow or Block.
|
||||
type ActionType string
|
||||
|
||||
// DirectionType associated with ACLs. Value is either In or Out.
|
||||
type DirectionType string
|
||||
|
||||
// RuleType associated with ACLs. Value is either Host (WFP) or Switch (VFP).
|
||||
type RuleType string
|
||||
|
||||
const (
|
||||
// Allow traffic
|
||||
ActionTypeAllow ActionType = "Allow"
|
||||
// Block traffic
|
||||
ActionTypeBlock ActionType = "Block"
|
||||
|
||||
// In is traffic coming to the Endpoint
|
||||
DirectionTypeIn DirectionType = "In"
|
||||
// Out is traffic leaving the Endpoint
|
||||
DirectionTypeOut DirectionType = "Out"
|
||||
|
||||
// Host creates WFP (Windows Firewall) rules
|
||||
RuleTypeHost RuleType = "Host"
|
||||
// Switch creates VFP (Virtual Filter Platform) rules
|
||||
RuleTypeSwitch RuleType = "Switch"
|
||||
)
|
||||
|
||||
// AclPolicySetting creates firewall rules on an endpoint
|
||||
type AclPolicySetting struct {
|
||||
Protocols string `json:",omitempty"` // EX: 6 (TCP), 17 (UDP), 1 (ICMPv4), 58 (ICMPv6), 2 (IGMP)
|
||||
Action ActionType `json:","`
|
||||
Direction DirectionType `json:","`
|
||||
LocalAddresses string `json:",omitempty"`
|
||||
RemoteAddresses string `json:",omitempty"`
|
||||
LocalPorts string `json:",omitempty"`
|
||||
RemotePorts string `json:",omitempty"`
|
||||
RuleType RuleType `json:",omitempty"`
|
||||
Priority uint16 `json:",omitempty"`
|
||||
}
|
||||
|
||||
// QosPolicySetting sets Quality of Service bandwidth caps on an Endpoint.
|
||||
type QosPolicySetting struct {
|
||||
MaximumOutgoingBandwidthInBytes uint64
|
||||
}
|
||||
|
||||
// OutboundNatPolicySetting sets outbound Network Address Translation on an Endpoint.
|
||||
type OutboundNatPolicySetting struct {
|
||||
VirtualIP string `json:",omitempty"`
|
||||
Exceptions []string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// SDNRoutePolicySetting sets SDN Route on an Endpoint.
|
||||
type SDNRoutePolicySetting struct {
|
||||
DestinationPrefix string `json:",omitempty"`
|
||||
NextHop string `json:",omitempty"`
|
||||
NeedEncap bool `json:",omitempty"`
|
||||
}
|
||||
|
||||
// L4ProxyPolicySetting sets Layer-4 Proxy on an endpoint.
|
||||
type L4ProxyPolicySetting struct {
|
||||
IP string `json:",omitempty"`
|
||||
Port string `json:",omitempty"`
|
||||
Protocol uint32 `json:",omitempty"` // EX: TCP = 6, UDP = 17
|
||||
ExceptionList []string `json:",omitempty"`
|
||||
Destination string `json:","`
|
||||
OutboundNat bool `json:",omitempty"`
|
||||
}
|
||||
|
||||
// PortnameEndpointPolicySetting sets the port name for an endpoint.
|
||||
type PortnameEndpointPolicySetting struct {
|
||||
Name string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// EncapOverheadEndpointPolicySetting sets the encap overhead for an endpoint.
|
||||
type EncapOverheadEndpointPolicySetting struct {
|
||||
Overhead uint16 `json:",omitempty"`
|
||||
}
|
||||
|
||||
/// Endpoint and Network Policy objects
|
||||
|
||||
// ProviderAddressEndpointPolicySetting sets the PA for an endpoint.
|
||||
type ProviderAddressEndpointPolicySetting struct {
|
||||
ProviderAddress string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// InterfaceConstraintPolicySetting limits an Endpoint or Network to a specific Nic.
|
||||
type InterfaceConstraintPolicySetting struct {
|
||||
InterfaceGuid string `json:",omitempty"`
|
||||
InterfaceLuid uint64 `json:",omitempty"`
|
||||
InterfaceIndex uint32 `json:",omitempty"`
|
||||
InterfaceMediaType uint32 `json:",omitempty"`
|
||||
InterfaceAlias string `json:",omitempty"`
|
||||
InterfaceDescription string `json:",omitempty"`
|
||||
}
|
||||
|
||||
/// Network Policy objects
|
||||
|
||||
// SourceMacAddressNetworkPolicySetting sets source MAC for a network.
|
||||
type SourceMacAddressNetworkPolicySetting struct {
|
||||
SourceMacAddress string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// NetAdapterNameNetworkPolicySetting sets network adapter of a network.
|
||||
type NetAdapterNameNetworkPolicySetting struct {
|
||||
NetworkAdapterName string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// VSwitchExtensionNetworkPolicySetting enables/disabled VSwitch extensions for a network.
|
||||
type VSwitchExtensionNetworkPolicySetting struct {
|
||||
ExtensionID string `json:",omitempty"`
|
||||
Enable bool `json:",omitempty"`
|
||||
}
|
||||
|
||||
// DrMacAddressNetworkPolicySetting sets the DR MAC for a network.
|
||||
type DrMacAddressNetworkPolicySetting struct {
|
||||
Address string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// AutomaticDNSNetworkPolicySetting enables/disables automatic DNS on a network.
|
||||
type AutomaticDNSNetworkPolicySetting struct {
|
||||
Enable bool `json:",omitempty"`
|
||||
}
|
||||
|
||||
/// Subnet Policy objects
|
||||
|
||||
// VlanPolicySetting isolates a subnet with VLAN tagging.
|
||||
type VlanPolicySetting struct {
|
||||
IsolationId uint32 `json:","`
|
||||
}
|
||||
|
||||
// VsidPolicySetting isolates a subnet with VSID tagging.
|
||||
type VsidPolicySetting struct {
|
||||
IsolationId uint32 `json:","`
|
||||
}
|
||||
|
||||
// RemoteSubnetRoutePolicySetting creates remote subnet route rules on a network
|
||||
type RemoteSubnetRoutePolicySetting struct {
|
||||
DestinationPrefix string
|
||||
IsolationId uint16
|
||||
ProviderAddress string
|
||||
DistributedRouterMacAddress string
|
||||
}
|
71
vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go
generated
vendored
Normal file
71
vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport.go
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// SupportedFeatures are the features provided by the Service.
|
||||
type SupportedFeatures struct {
|
||||
Acl AclFeatures `json:"ACL"`
|
||||
Api ApiSupport `json:"API"`
|
||||
RemoteSubnet bool `json:"RemoteSubnet"`
|
||||
HostRoute bool `json:"HostRoute"`
|
||||
DSR bool `json:"DSR"`
|
||||
}
|
||||
|
||||
// AclFeatures are the supported ACL possibilities.
|
||||
type AclFeatures struct {
|
||||
AclAddressLists bool `json:"AclAddressLists"`
|
||||
AclNoHostRulePriority bool `json:"AclHostRulePriority"`
|
||||
AclPortRanges bool `json:"AclPortRanges"`
|
||||
AclRuleId bool `json:"AclRuleId"`
|
||||
}
|
||||
|
||||
// ApiSupport lists the supported API versions.
|
||||
type ApiSupport struct {
|
||||
V1 bool `json:"V1"`
|
||||
V2 bool `json:"V2"`
|
||||
}
|
||||
|
||||
// GetSupportedFeatures returns the features supported by the Service.
|
||||
func GetSupportedFeatures() SupportedFeatures {
|
||||
var features SupportedFeatures
|
||||
|
||||
globals, err := GetGlobals()
|
||||
if err != nil {
|
||||
// Expected on pre-1803 builds, all features will be false/unsupported
|
||||
logrus.Debugf("Unable to obtain globals: %s", err)
|
||||
return features
|
||||
}
|
||||
|
||||
features.Acl = AclFeatures{
|
||||
AclAddressLists: isFeatureSupported(globals.Version, HNSVersion1803),
|
||||
AclNoHostRulePriority: isFeatureSupported(globals.Version, HNSVersion1803),
|
||||
AclPortRanges: isFeatureSupported(globals.Version, HNSVersion1803),
|
||||
AclRuleId: isFeatureSupported(globals.Version, HNSVersion1803),
|
||||
}
|
||||
|
||||
features.Api = ApiSupport{
|
||||
V2: isFeatureSupported(globals.Version, V2ApiSupport),
|
||||
V1: true, // HNSCall is still available.
|
||||
}
|
||||
|
||||
features.RemoteSubnet = isFeatureSupported(globals.Version, RemoteSubnetVersion)
|
||||
features.HostRoute = isFeatureSupported(globals.Version, HostRouteVersion)
|
||||
features.DSR = isFeatureSupported(globals.Version, DSRVersion)
|
||||
|
||||
return features
|
||||
}
|
||||
|
||||
func isFeatureSupported(currentVersion Version, minVersionSupported Version) bool {
|
||||
if currentVersion.Major < minVersionSupported.Major {
|
||||
return false
|
||||
}
|
||||
if currentVersion.Major > minVersionSupported.Major {
|
||||
return true
|
||||
}
|
||||
if currentVersion.Minor < minVersionSupported.Minor {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
62
vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport_test.go
generated
vendored
Normal file
62
vendor/github.com/Microsoft/hcsshim/hcn/hcnsupport_test.go
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSupportedFeatures(t *testing.T) {
|
||||
supportedFeatures := GetSupportedFeatures()
|
||||
jsonString, err := json.Marshal(supportedFeatures)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("Supported Features:\n%s \n", jsonString)
|
||||
}
|
||||
|
||||
func TestV2ApiSupport(t *testing.T) {
|
||||
supportedFeatures := GetSupportedFeatures()
|
||||
err := V2ApiSupported()
|
||||
if supportedFeatures.Api.V2 && err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !supportedFeatures.Api.V2 && err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteSubnetSupport(t *testing.T) {
|
||||
supportedFeatures := GetSupportedFeatures()
|
||||
err := RemoteSubnetSupported()
|
||||
if supportedFeatures.RemoteSubnet && err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !supportedFeatures.RemoteSubnet && err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHostRouteSupport(t *testing.T) {
|
||||
supportedFeatures := GetSupportedFeatures()
|
||||
err := HostRouteSupported()
|
||||
if supportedFeatures.HostRoute && err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !supportedFeatures.HostRoute && err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDSRSupport(t *testing.T) {
|
||||
supportedFeatures := GetSupportedFeatures()
|
||||
err := DSRSupported()
|
||||
if supportedFeatures.DSR && err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !supportedFeatures.DSR && err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
267
vendor/github.com/Microsoft/hcsshim/hcn/hcnutils_test.go
generated
vendored
Normal file
267
vendor/github.com/Microsoft/hcsshim/hcn/hcnutils_test.go
generated
vendored
Normal file
@ -0,0 +1,267 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func cleanup(networkName string) {
|
||||
// Delete test network (if exists)
|
||||
testNetwork, err := GetNetworkByName(networkName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if testNetwork != nil {
|
||||
err := testNetwork.Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func HcnCreateTestNATNetwork() (*HostComputeNetwork, error) {
|
||||
cleanup(NatTestNetworkName)
|
||||
network := &HostComputeNetwork{
|
||||
Type: "NAT",
|
||||
Name: NatTestNetworkName,
|
||||
MacPool: MacPool{
|
||||
Ranges: []MacRange{
|
||||
{
|
||||
StartMacAddress: "00-15-5D-52-C0-00",
|
||||
EndMacAddress: "00-15-5D-52-CF-FF",
|
||||
},
|
||||
},
|
||||
},
|
||||
Ipams: []Ipam{
|
||||
{
|
||||
Type: "Static",
|
||||
Subnets: []Subnet{
|
||||
{
|
||||
IpAddressPrefix: "192.168.100.0/24",
|
||||
Routes: []Route{
|
||||
{
|
||||
NextHop: "192.168.100.1",
|
||||
DestinationPrefix: "0.0.0.0",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
return network.Create()
|
||||
}
|
||||
|
||||
func CreateTestOverlayNetwork() (*HostComputeNetwork, error) {
|
||||
cleanup(OverlayTestNetworkName)
|
||||
network := &HostComputeNetwork{
|
||||
Type: "Overlay",
|
||||
Name: OverlayTestNetworkName,
|
||||
MacPool: MacPool{
|
||||
Ranges: []MacRange{
|
||||
{
|
||||
StartMacAddress: "00-15-5D-52-C0-00",
|
||||
EndMacAddress: "00-15-5D-52-CF-FF",
|
||||
},
|
||||
},
|
||||
},
|
||||
Ipams: []Ipam{
|
||||
{
|
||||
Type: "Static",
|
||||
Subnets: []Subnet{
|
||||
{
|
||||
IpAddressPrefix: "192.168.100.0/24",
|
||||
Routes: []Route{
|
||||
{
|
||||
NextHop: "192.168.100.1",
|
||||
DestinationPrefix: "0.0.0.0/0",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Flags: EnableNonPersistent,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
vsid := &VsidPolicySetting{
|
||||
IsolationId: 5000,
|
||||
}
|
||||
vsidJson, err := json.Marshal(vsid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sp := &SubnetPolicy{
|
||||
Type: VSID,
|
||||
}
|
||||
sp.Settings = vsidJson
|
||||
|
||||
spJson, err := json.Marshal(sp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
network.Ipams[0].Subnets[0].Policies = append(network.Ipams[0].Subnets[0].Policies, spJson)
|
||||
|
||||
return network.Create()
|
||||
}
|
||||
|
||||
func HcnCreateTestEndpoint(network *HostComputeNetwork) (*HostComputeEndpoint, error) {
|
||||
if network == nil {
|
||||
|
||||
}
|
||||
Endpoint := &HostComputeEndpoint{
|
||||
Name: NatTestEndpointName,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
return network.CreateEndpoint(Endpoint)
|
||||
}
|
||||
|
||||
func HcnCreateTestEndpointWithNamespace(network *HostComputeNetwork, namespace *HostComputeNamespace) (*HostComputeEndpoint, error) {
|
||||
Endpoint := &HostComputeEndpoint{
|
||||
Name: NatTestEndpointName,
|
||||
HostComputeNamespace: namespace.Id,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
return network.CreateEndpoint(Endpoint)
|
||||
}
|
||||
|
||||
func HcnCreateTestNamespace() (*HostComputeNamespace, error) {
|
||||
namespace := &HostComputeNamespace{
|
||||
Type: NamespaceTypeHostDefault,
|
||||
NamespaceId: 5,
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
return namespace.Create()
|
||||
}
|
||||
|
||||
func HcnCreateAcls() (*PolicyEndpointRequest, error) {
|
||||
in := AclPolicySetting{
|
||||
Protocols: "6",
|
||||
Action: ActionTypeAllow,
|
||||
Direction: DirectionTypeIn,
|
||||
LocalAddresses: "192.168.100.0/24,10.0.0.21",
|
||||
RemoteAddresses: "192.168.100.0/24,10.0.0.21",
|
||||
LocalPorts: "80,8080",
|
||||
RemotePorts: "80,8080",
|
||||
RuleType: RuleTypeSwitch,
|
||||
Priority: 200,
|
||||
}
|
||||
|
||||
rawJSON, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inPolicy := EndpointPolicy{
|
||||
Type: ACL,
|
||||
Settings: rawJSON,
|
||||
}
|
||||
|
||||
out := AclPolicySetting{
|
||||
Protocols: "6",
|
||||
Action: ActionTypeAllow,
|
||||
Direction: DirectionTypeOut,
|
||||
LocalAddresses: "192.168.100.0/24,10.0.0.21",
|
||||
RemoteAddresses: "192.168.100.0/24,10.0.0.21",
|
||||
LocalPorts: "80,8080",
|
||||
RemotePorts: "80,8080",
|
||||
RuleType: RuleTypeSwitch,
|
||||
Priority: 200,
|
||||
}
|
||||
|
||||
rawJSON, err = json.Marshal(out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
outPolicy := EndpointPolicy{
|
||||
Type: ACL,
|
||||
Settings: rawJSON,
|
||||
}
|
||||
|
||||
endpointRequest := PolicyEndpointRequest{
|
||||
Policies: []EndpointPolicy{inPolicy, outPolicy},
|
||||
}
|
||||
|
||||
return &endpointRequest, nil
|
||||
}
|
||||
|
||||
func HcnCreateTestLoadBalancer(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
|
||||
loadBalancer := &HostComputeLoadBalancer{
|
||||
HostComputeEndpoints: []string{endpoint.Id},
|
||||
SourceVIP: "10.0.0.1",
|
||||
PortMappings: []LoadBalancerPortMapping{
|
||||
{
|
||||
Protocol: 6, // TCP
|
||||
InternalPort: 8080,
|
||||
ExternalPort: 8090,
|
||||
},
|
||||
},
|
||||
FrontendVIPs: []string{"1.1.1.2", "1.1.1.3"},
|
||||
SchemaVersion: SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
}
|
||||
|
||||
return loadBalancer.Create()
|
||||
}
|
||||
|
||||
func HcnCreateTestRemoteSubnetRoute() (*PolicyNetworkRequest, error) {
|
||||
rsr := RemoteSubnetRoutePolicySetting{
|
||||
DestinationPrefix: "192.168.2.0/24",
|
||||
IsolationId: 5000,
|
||||
ProviderAddress: "1.1.1.1",
|
||||
DistributedRouterMacAddress: "00-12-34-56-78-9a",
|
||||
}
|
||||
|
||||
rawJSON, err := json.Marshal(rsr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rsrPolicy := NetworkPolicy{
|
||||
Type: RemoteSubnetRoute,
|
||||
Settings: rawJSON,
|
||||
}
|
||||
|
||||
networkRequest := PolicyNetworkRequest{
|
||||
Policies: []NetworkPolicy{rsrPolicy},
|
||||
}
|
||||
|
||||
return &networkRequest, nil
|
||||
}
|
||||
|
||||
func HcnCreateTestHostRoute() (*PolicyNetworkRequest, error) {
|
||||
hostRoutePolicy := NetworkPolicy{
|
||||
Type: HostRoute,
|
||||
Settings: []byte("{}"),
|
||||
}
|
||||
|
||||
networkRequest := PolicyNetworkRequest{
|
||||
Policies: []NetworkPolicy{hostRoutePolicy},
|
||||
}
|
||||
|
||||
return &networkRequest, nil
|
||||
}
|
111
vendor/github.com/Microsoft/hcsshim/hcn/hcnv1schema_test.go
generated
vendored
Normal file
111
vendor/github.com/Microsoft/hcsshim/hcn/hcnv1schema_test.go
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
)
|
||||
|
||||
func TestV1Network(t *testing.T) {
|
||||
cleanup(NatTestNetworkName)
|
||||
|
||||
v1network := hcsshim.HNSNetwork{
|
||||
Type: "NAT",
|
||||
Name: NatTestNetworkName,
|
||||
MacPools: []hcsshim.MacPool{
|
||||
{
|
||||
StartMacAddress: "00-15-5D-52-C0-00",
|
||||
EndMacAddress: "00-15-5D-52-CF-FF",
|
||||
},
|
||||
},
|
||||
Subnets: []hcsshim.Subnet{
|
||||
{
|
||||
AddressPrefix: "192.168.100.0/24",
|
||||
GatewayAddress: "192.168.100.1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
jsonString, err := json.Marshal(v1network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
network, err := createNetwork(string(jsonString))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1Endpoint(t *testing.T) {
|
||||
cleanup(NatTestNetworkName)
|
||||
|
||||
v1network := hcsshim.HNSNetwork{
|
||||
Type: "NAT",
|
||||
Name: NatTestNetworkName,
|
||||
MacPools: []hcsshim.MacPool{
|
||||
{
|
||||
StartMacAddress: "00-15-5D-52-C0-00",
|
||||
EndMacAddress: "00-15-5D-52-CF-FF",
|
||||
},
|
||||
},
|
||||
Subnets: []hcsshim.Subnet{
|
||||
{
|
||||
AddressPrefix: "192.168.100.0/24",
|
||||
GatewayAddress: "192.168.100.1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
jsonString, err := json.Marshal(v1network)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
network, err := createNetwork(string(jsonString))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
v1endpoint := hcsshim.HNSEndpoint{
|
||||
Name: NatTestEndpointName,
|
||||
VirtualNetwork: network.Id,
|
||||
}
|
||||
|
||||
jsonString, err = json.Marshal(v1endpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
endpoint, err := createEndpoint(network.Id, string(jsonString))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
err = endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
97
vendor/github.com/Microsoft/hcsshim/hcn/hnsv1_test.go
generated
vendored
Normal file
97
vendor/github.com/Microsoft/hcsshim/hcn/hnsv1_test.go
generated
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
// +build integration
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
)
|
||||
|
||||
const (
|
||||
NatTestNetworkName string = "GoTestNat"
|
||||
NatTestEndpointName string = "GoTestNatEndpoint"
|
||||
OverlayTestNetworkName string = "GoTestOverlay"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func CreateTestNetwork() (*hcsshim.HNSNetwork, error) {
|
||||
network := &hcsshim.HNSNetwork{
|
||||
Type: "NAT",
|
||||
Name: NatTestNetworkName,
|
||||
Subnets: []hcsshim.Subnet{
|
||||
{
|
||||
AddressPrefix: "192.168.100.0/24",
|
||||
GatewayAddress: "192.168.100.1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return network.Create()
|
||||
}
|
||||
|
||||
func TestEndpoint(t *testing.T) {
|
||||
|
||||
network, err := CreateTestNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Endpoint := &hcsshim.HNSEndpoint{
|
||||
Name: NatTestEndpointName,
|
||||
}
|
||||
|
||||
Endpoint, err = network.CreateEndpoint(Endpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = Endpoint.HostAttach(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = Endpoint.HostDetach()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = Endpoint.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointGetAll(t *testing.T) {
|
||||
_, err := hcsshim.HNSListEndpointRequest()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetworkGetAll(t *testing.T) {
|
||||
_, err := hcsshim.HNSListNetworkRequest("GET", "", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetwork(t *testing.T) {
|
||||
network, err := CreateTestNetwork()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = network.Delete()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
714
vendor/github.com/Microsoft/hcsshim/hcn/zsyscall_windows.go
generated
vendored
Normal file
714
vendor/github.com/Microsoft/hcsshim/hcn/zsyscall_windows.go
generated
vendored
Normal file
@ -0,0 +1,714 @@
|
||||
// Code generated mksyscall_windows.exe DO NOT EDIT
|
||||
|
||||
package hcn
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
// Do the interface allocations only once for common
|
||||
// Errno values.
|
||||
const (
|
||||
errnoERROR_IO_PENDING = 997
|
||||
)
|
||||
|
||||
var (
|
||||
errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
|
||||
)
|
||||
|
||||
// errnoErr returns common boxed Errno values, to prevent
|
||||
// allocations at runtime.
|
||||
func errnoErr(e syscall.Errno) error {
|
||||
switch e {
|
||||
case 0:
|
||||
return nil
|
||||
case errnoERROR_IO_PENDING:
|
||||
return errERROR_IO_PENDING
|
||||
}
|
||||
// TODO: add more here, after collecting data on the common
|
||||
// error values see on Windows. (perhaps when running
|
||||
// all.bat?)
|
||||
return e
|
||||
}
|
||||
|
||||
var (
|
||||
modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll")
|
||||
modvmcompute = windows.NewLazySystemDLL("vmcompute.dll")
|
||||
modcomputenetwork = windows.NewLazySystemDLL("computenetwork.dll")
|
||||
|
||||
procSetCurrentThreadCompartmentId = modiphlpapi.NewProc("SetCurrentThreadCompartmentId")
|
||||
procHNSCall = modvmcompute.NewProc("HNSCall")
|
||||
procHcnEnumerateNetworks = modcomputenetwork.NewProc("HcnEnumerateNetworks")
|
||||
procHcnCreateNetwork = modcomputenetwork.NewProc("HcnCreateNetwork")
|
||||
procHcnOpenNetwork = modcomputenetwork.NewProc("HcnOpenNetwork")
|
||||
procHcnModifyNetwork = modcomputenetwork.NewProc("HcnModifyNetwork")
|
||||
procHcnQueryNetworkProperties = modcomputenetwork.NewProc("HcnQueryNetworkProperties")
|
||||
procHcnDeleteNetwork = modcomputenetwork.NewProc("HcnDeleteNetwork")
|
||||
procHcnCloseNetwork = modcomputenetwork.NewProc("HcnCloseNetwork")
|
||||
procHcnEnumerateEndpoints = modcomputenetwork.NewProc("HcnEnumerateEndpoints")
|
||||
procHcnCreateEndpoint = modcomputenetwork.NewProc("HcnCreateEndpoint")
|
||||
procHcnOpenEndpoint = modcomputenetwork.NewProc("HcnOpenEndpoint")
|
||||
procHcnModifyEndpoint = modcomputenetwork.NewProc("HcnModifyEndpoint")
|
||||
procHcnQueryEndpointProperties = modcomputenetwork.NewProc("HcnQueryEndpointProperties")
|
||||
procHcnDeleteEndpoint = modcomputenetwork.NewProc("HcnDeleteEndpoint")
|
||||
procHcnCloseEndpoint = modcomputenetwork.NewProc("HcnCloseEndpoint")
|
||||
procHcnEnumerateNamespaces = modcomputenetwork.NewProc("HcnEnumerateNamespaces")
|
||||
procHcnCreateNamespace = modcomputenetwork.NewProc("HcnCreateNamespace")
|
||||
procHcnOpenNamespace = modcomputenetwork.NewProc("HcnOpenNamespace")
|
||||
procHcnModifyNamespace = modcomputenetwork.NewProc("HcnModifyNamespace")
|
||||
procHcnQueryNamespaceProperties = modcomputenetwork.NewProc("HcnQueryNamespaceProperties")
|
||||
procHcnDeleteNamespace = modcomputenetwork.NewProc("HcnDeleteNamespace")
|
||||
procHcnCloseNamespace = modcomputenetwork.NewProc("HcnCloseNamespace")
|
||||
procHcnEnumerateLoadBalancers = modcomputenetwork.NewProc("HcnEnumerateLoadBalancers")
|
||||
procHcnCreateLoadBalancer = modcomputenetwork.NewProc("HcnCreateLoadBalancer")
|
||||
procHcnOpenLoadBalancer = modcomputenetwork.NewProc("HcnOpenLoadBalancer")
|
||||
procHcnModifyLoadBalancer = modcomputenetwork.NewProc("HcnModifyLoadBalancer")
|
||||
procHcnQueryLoadBalancerProperties = modcomputenetwork.NewProc("HcnQueryLoadBalancerProperties")
|
||||
procHcnDeleteLoadBalancer = modcomputenetwork.NewProc("HcnDeleteLoadBalancer")
|
||||
procHcnCloseLoadBalancer = modcomputenetwork.NewProc("HcnCloseLoadBalancer")
|
||||
procHcnOpenService = modcomputenetwork.NewProc("HcnOpenService")
|
||||
procHcnRegisterServiceCallback = modcomputenetwork.NewProc("HcnRegisterServiceCallback")
|
||||
procHcnUnregisterServiceCallback = modcomputenetwork.NewProc("HcnUnregisterServiceCallback")
|
||||
procHcnCloseService = modcomputenetwork.NewProc("HcnCloseService")
|
||||
)
|
||||
|
||||
func SetCurrentThreadCompartmentId(compartmentId uint32) (hr error) {
|
||||
r0, _, _ := syscall.Syscall(procSetCurrentThreadCompartmentId.Addr(), 1, uintptr(compartmentId), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func _hnsCall(method string, path string, object string, response **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(method)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
var _p1 *uint16
|
||||
_p1, hr = syscall.UTF16PtrFromString(path)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
var _p2 *uint16
|
||||
_p2, hr = syscall.UTF16PtrFromString(object)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return __hnsCall(_p0, _p1, _p2, response)
|
||||
}
|
||||
|
||||
func __hnsCall(method *uint16, path *uint16, object *uint16, response **uint16) (hr error) {
|
||||
if hr = procHNSCall.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHNSCall.Addr(), 4, uintptr(unsafe.Pointer(method)), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(object)), uintptr(unsafe.Pointer(response)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnEnumerateNetworks(query string, networks **uint16, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(query)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnEnumerateNetworks(_p0, networks, result)
|
||||
}
|
||||
|
||||
func _hcnEnumerateNetworks(query *uint16, networks **uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnEnumerateNetworks.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnEnumerateNetworks.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(networks)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCreateNetwork(id *_guid, settings string, network *hcnNetwork, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnCreateNetwork(id, _p0, network, result)
|
||||
}
|
||||
|
||||
func _hcnCreateNetwork(id *_guid, settings *uint16, network *hcnNetwork, result **uint16) (hr error) {
|
||||
if hr = procHcnCreateNetwork.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnCreateNetwork.Addr(), 4, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(network)), uintptr(unsafe.Pointer(result)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnOpenNetwork(id *_guid, network *hcnNetwork, result **uint16) (hr error) {
|
||||
if hr = procHcnOpenNetwork.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnOpenNetwork.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(network)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnModifyNetwork(network hcnNetwork, settings string, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnModifyNetwork(network, _p0, result)
|
||||
}
|
||||
|
||||
func _hcnModifyNetwork(network hcnNetwork, settings *uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnModifyNetwork.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnModifyNetwork.Addr(), 3, uintptr(network), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnQueryNetworkProperties(network hcnNetwork, query string, properties **uint16, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(query)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnQueryNetworkProperties(network, _p0, properties, result)
|
||||
}
|
||||
|
||||
func _hcnQueryNetworkProperties(network hcnNetwork, query *uint16, properties **uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnQueryNetworkProperties.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnQueryNetworkProperties.Addr(), 4, uintptr(network), uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnDeleteNetwork(id *_guid, result **uint16) (hr error) {
|
||||
if hr = procHcnDeleteNetwork.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnDeleteNetwork.Addr(), 2, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(result)), 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCloseNetwork(network hcnNetwork) (hr error) {
|
||||
if hr = procHcnCloseNetwork.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnCloseNetwork.Addr(), 1, uintptr(network), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnEnumerateEndpoints(query string, endpoints **uint16, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(query)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnEnumerateEndpoints(_p0, endpoints, result)
|
||||
}
|
||||
|
||||
func _hcnEnumerateEndpoints(query *uint16, endpoints **uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnEnumerateEndpoints.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnEnumerateEndpoints.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(endpoints)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCreateEndpoint(network hcnNetwork, id *_guid, settings string, endpoint *hcnEndpoint, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnCreateEndpoint(network, id, _p0, endpoint, result)
|
||||
}
|
||||
|
||||
func _hcnCreateEndpoint(network hcnNetwork, id *_guid, settings *uint16, endpoint *hcnEndpoint, result **uint16) (hr error) {
|
||||
if hr = procHcnCreateEndpoint.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnCreateEndpoint.Addr(), 5, uintptr(network), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(endpoint)), uintptr(unsafe.Pointer(result)), 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnOpenEndpoint(id *_guid, endpoint *hcnEndpoint, result **uint16) (hr error) {
|
||||
if hr = procHcnOpenEndpoint.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnOpenEndpoint.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(endpoint)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnModifyEndpoint(endpoint hcnEndpoint, settings string, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnModifyEndpoint(endpoint, _p0, result)
|
||||
}
|
||||
|
||||
func _hcnModifyEndpoint(endpoint hcnEndpoint, settings *uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnModifyEndpoint.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnModifyEndpoint.Addr(), 3, uintptr(endpoint), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnQueryEndpointProperties(endpoint hcnEndpoint, query string, properties **uint16, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(query)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnQueryEndpointProperties(endpoint, _p0, properties, result)
|
||||
}
|
||||
|
||||
func _hcnQueryEndpointProperties(endpoint hcnEndpoint, query *uint16, properties **uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnQueryEndpointProperties.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnQueryEndpointProperties.Addr(), 4, uintptr(endpoint), uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnDeleteEndpoint(id *_guid, result **uint16) (hr error) {
|
||||
if hr = procHcnDeleteEndpoint.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnDeleteEndpoint.Addr(), 2, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(result)), 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCloseEndpoint(endpoint hcnEndpoint) (hr error) {
|
||||
if hr = procHcnCloseEndpoint.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnCloseEndpoint.Addr(), 1, uintptr(endpoint), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnEnumerateNamespaces(query string, namespaces **uint16, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(query)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnEnumerateNamespaces(_p0, namespaces, result)
|
||||
}
|
||||
|
||||
func _hcnEnumerateNamespaces(query *uint16, namespaces **uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnEnumerateNamespaces.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnEnumerateNamespaces.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(namespaces)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCreateNamespace(id *_guid, settings string, namespace *hcnNamespace, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnCreateNamespace(id, _p0, namespace, result)
|
||||
}
|
||||
|
||||
func _hcnCreateNamespace(id *_guid, settings *uint16, namespace *hcnNamespace, result **uint16) (hr error) {
|
||||
if hr = procHcnCreateNamespace.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnCreateNamespace.Addr(), 4, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(namespace)), uintptr(unsafe.Pointer(result)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnOpenNamespace(id *_guid, namespace *hcnNamespace, result **uint16) (hr error) {
|
||||
if hr = procHcnOpenNamespace.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnOpenNamespace.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(namespace)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnModifyNamespace(namespace hcnNamespace, settings string, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnModifyNamespace(namespace, _p0, result)
|
||||
}
|
||||
|
||||
func _hcnModifyNamespace(namespace hcnNamespace, settings *uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnModifyNamespace.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnModifyNamespace.Addr(), 3, uintptr(namespace), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnQueryNamespaceProperties(namespace hcnNamespace, query string, properties **uint16, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(query)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnQueryNamespaceProperties(namespace, _p0, properties, result)
|
||||
}
|
||||
|
||||
func _hcnQueryNamespaceProperties(namespace hcnNamespace, query *uint16, properties **uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnQueryNamespaceProperties.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnQueryNamespaceProperties.Addr(), 4, uintptr(namespace), uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnDeleteNamespace(id *_guid, result **uint16) (hr error) {
|
||||
if hr = procHcnDeleteNamespace.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnDeleteNamespace.Addr(), 2, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(result)), 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCloseNamespace(namespace hcnNamespace) (hr error) {
|
||||
if hr = procHcnCloseNamespace.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnCloseNamespace.Addr(), 1, uintptr(namespace), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnEnumerateLoadBalancers(query string, loadBalancers **uint16, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(query)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnEnumerateLoadBalancers(_p0, loadBalancers, result)
|
||||
}
|
||||
|
||||
func _hcnEnumerateLoadBalancers(query *uint16, loadBalancers **uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnEnumerateLoadBalancers.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnEnumerateLoadBalancers.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(loadBalancers)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCreateLoadBalancer(id *_guid, settings string, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnCreateLoadBalancer(id, _p0, loadBalancer, result)
|
||||
}
|
||||
|
||||
func _hcnCreateLoadBalancer(id *_guid, settings *uint16, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) {
|
||||
if hr = procHcnCreateLoadBalancer.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnCreateLoadBalancer.Addr(), 4, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(loadBalancer)), uintptr(unsafe.Pointer(result)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnOpenLoadBalancer(id *_guid, loadBalancer *hcnLoadBalancer, result **uint16) (hr error) {
|
||||
if hr = procHcnOpenLoadBalancer.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnOpenLoadBalancer.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(loadBalancer)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnModifyLoadBalancer(loadBalancer hcnLoadBalancer, settings string, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(settings)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnModifyLoadBalancer(loadBalancer, _p0, result)
|
||||
}
|
||||
|
||||
func _hcnModifyLoadBalancer(loadBalancer hcnLoadBalancer, settings *uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnModifyLoadBalancer.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnModifyLoadBalancer.Addr(), 3, uintptr(loadBalancer), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnQueryLoadBalancerProperties(loadBalancer hcnLoadBalancer, query string, properties **uint16, result **uint16) (hr error) {
|
||||
var _p0 *uint16
|
||||
_p0, hr = syscall.UTF16PtrFromString(query)
|
||||
if hr != nil {
|
||||
return
|
||||
}
|
||||
return _hcnQueryLoadBalancerProperties(loadBalancer, _p0, properties, result)
|
||||
}
|
||||
|
||||
func _hcnQueryLoadBalancerProperties(loadBalancer hcnLoadBalancer, query *uint16, properties **uint16, result **uint16) (hr error) {
|
||||
if hr = procHcnQueryLoadBalancerProperties.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnQueryLoadBalancerProperties.Addr(), 4, uintptr(loadBalancer), uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnDeleteLoadBalancer(id *_guid, result **uint16) (hr error) {
|
||||
if hr = procHcnDeleteLoadBalancer.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnDeleteLoadBalancer.Addr(), 2, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(result)), 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCloseLoadBalancer(loadBalancer hcnLoadBalancer) (hr error) {
|
||||
if hr = procHcnCloseLoadBalancer.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnCloseLoadBalancer.Addr(), 1, uintptr(loadBalancer), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnOpenService(service *hcnService, result **uint16) (hr error) {
|
||||
if hr = procHcnOpenService.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnOpenService.Addr(), 2, uintptr(unsafe.Pointer(service)), uintptr(unsafe.Pointer(result)), 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnRegisterServiceCallback(service hcnService, callback int32, context int32, callbackHandle *hcnCallbackHandle) (hr error) {
|
||||
if hr = procHcnRegisterServiceCallback.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall6(procHcnRegisterServiceCallback.Addr(), 4, uintptr(service), uintptr(callback), uintptr(context), uintptr(unsafe.Pointer(callbackHandle)), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnUnregisterServiceCallback(callbackHandle hcnCallbackHandle) (hr error) {
|
||||
if hr = procHcnUnregisterServiceCallback.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnUnregisterServiceCallback.Addr(), 1, uintptr(callbackHandle), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func hcnCloseService(service hcnService) (hr error) {
|
||||
if hr = procHcnCloseService.Find(); hr != nil {
|
||||
return
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procHcnCloseService.Addr(), 1, uintptr(service), 0, 0)
|
||||
if int32(r0) < 0 {
|
||||
if r0&0x1fff0000 == 0x00070000 {
|
||||
r0 &= 0xffff
|
||||
}
|
||||
hr = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user