2018-03-19 18:57:30 -04:00
|
|
|
package hcsshim
|
|
|
|
|
|
|
|
import (
|
2018-09-05 14:54:38 -04:00
|
|
|
"github.com/Microsoft/hcsshim/internal/hns"
|
2018-03-19 18:57:30 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// HNSEndpoint represents a network endpoint in HNS
|
2018-09-05 14:54:38 -04:00
|
|
|
type HNSEndpoint = hns.HNSEndpoint
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
//SystemType represents the type of the system on which actions are done
|
|
|
|
type SystemType string
|
|
|
|
|
|
|
|
// SystemType const
|
|
|
|
const (
|
|
|
|
ContainerType SystemType = "Container"
|
|
|
|
VirtualMachineType SystemType = "VirtualMachine"
|
|
|
|
HostType SystemType = "Host"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EndpointAttachDetachRequest is the structure used to send request to the container to modify the system
|
|
|
|
// Supported resource types are Network and Request Types are Add/Remove
|
2018-09-05 14:54:38 -04:00
|
|
|
type EndpointAttachDetachRequest = hns.EndpointAttachDetachRequest
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
// EndpointResquestResponse is object to get the endpoint request response
|
2018-09-05 14:54:38 -04:00
|
|
|
type EndpointResquestResponse = hns.EndpointResquestResponse
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
// HNSEndpointRequest makes a HNS call to modify/query a network endpoint
|
|
|
|
func HNSEndpointRequest(method, path, request string) (*HNSEndpoint, error) {
|
2018-09-05 14:54:38 -04:00
|
|
|
return hns.HNSEndpointRequest(method, path, request)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// HNSListEndpointRequest makes a HNS call to query the list of available endpoints
|
|
|
|
func HNSListEndpointRequest() ([]HNSEndpoint, error) {
|
2018-09-05 14:54:38 -04:00
|
|
|
return hns.HNSListEndpointRequest()
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// HotAttachEndpoint makes a HCS Call to attach the endpoint to the container
|
|
|
|
func HotAttachEndpoint(containerID string, endpointID string) error {
|
|
|
|
return modifyNetworkEndpoint(containerID, endpointID, Add)
|
|
|
|
}
|
|
|
|
|
|
|
|
// HotDetachEndpoint makes a HCS Call to detach the endpoint from the container
|
|
|
|
func HotDetachEndpoint(containerID string, endpointID string) error {
|
|
|
|
return modifyNetworkEndpoint(containerID, endpointID, Remove)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModifyContainer corresponding to the container id, by sending a request
|
|
|
|
func modifyContainer(id string, request *ResourceModificationRequestResponse) error {
|
|
|
|
container, err := OpenContainer(id)
|
|
|
|
if err != nil {
|
|
|
|
if IsNotExist(err) {
|
|
|
|
return ErrComputeSystemDoesNotExist
|
|
|
|
}
|
|
|
|
return getInnerError(err)
|
|
|
|
}
|
|
|
|
defer container.Close()
|
|
|
|
err = container.Modify(request)
|
|
|
|
if err != nil {
|
|
|
|
if IsNotSupported(err) {
|
|
|
|
return ErrPlatformNotSupported
|
|
|
|
}
|
|
|
|
return getInnerError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func modifyNetworkEndpoint(containerID string, endpointID string, request RequestType) error {
|
|
|
|
requestMessage := &ResourceModificationRequestResponse{
|
|
|
|
Resource: Network,
|
|
|
|
Request: request,
|
|
|
|
Data: endpointID,
|
|
|
|
}
|
|
|
|
err := modifyContainer(containerID, requestMessage)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetHNSEndpointByID get the Endpoint by ID
|
|
|
|
func GetHNSEndpointByID(endpointID string) (*HNSEndpoint, error) {
|
2018-09-05 14:54:38 -04:00
|
|
|
return hns.GetHNSEndpointByID(endpointID)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetHNSEndpointByName gets the endpoint filtered by Name
|
|
|
|
func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
|
2018-09-05 14:54:38 -04:00
|
|
|
return hns.GetHNSEndpointByName(endpointName)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|