...
1
2
3 package hcsshim
4
5 import (
6 "github.com/Microsoft/hcsshim/internal/hns"
7 )
8
9
10 type HNSEndpoint = hns.HNSEndpoint
11
12
13 type HNSEndpointStats = hns.EndpointStats
14
15
16 type Namespace = hns.Namespace
17
18
19 type SystemType string
20
21
22 const (
23 ContainerType SystemType = "Container"
24 VirtualMachineType SystemType = "VirtualMachine"
25 HostType SystemType = "Host"
26 )
27
28
29
30 type EndpointAttachDetachRequest = hns.EndpointAttachDetachRequest
31
32
33 type EndpointResquestResponse = hns.EndpointResquestResponse
34
35
36 func HNSEndpointRequest(method, path, request string) (*HNSEndpoint, error) {
37 return hns.HNSEndpointRequest(method, path, request)
38 }
39
40
41 func HNSListEndpointRequest() ([]HNSEndpoint, error) {
42 return hns.HNSListEndpointRequest()
43 }
44
45
46 func HotAttachEndpoint(containerID string, endpointID string) error {
47 endpoint, err := GetHNSEndpointByID(endpointID)
48 if err != nil {
49 return err
50 }
51 isAttached, err := endpoint.IsAttached(containerID)
52 if isAttached {
53 return err
54 }
55 return modifyNetworkEndpoint(containerID, endpointID, Add)
56 }
57
58
59 func HotDetachEndpoint(containerID string, endpointID string) error {
60 endpoint, err := GetHNSEndpointByID(endpointID)
61 if err != nil {
62 return err
63 }
64 isAttached, err := endpoint.IsAttached(containerID)
65 if !isAttached {
66 return err
67 }
68 return modifyNetworkEndpoint(containerID, endpointID, Remove)
69 }
70
71
72 func modifyContainer(id string, request *ResourceModificationRequestResponse) error {
73 container, err := OpenContainer(id)
74 if err != nil {
75 if IsNotExist(err) {
76 return ErrComputeSystemDoesNotExist
77 }
78 return getInnerError(err)
79 }
80 defer container.Close()
81 err = container.Modify(request)
82 if err != nil {
83 if IsNotSupported(err) {
84 return ErrPlatformNotSupported
85 }
86 return getInnerError(err)
87 }
88
89 return nil
90 }
91
92 func modifyNetworkEndpoint(containerID string, endpointID string, request RequestType) error {
93 requestMessage := &ResourceModificationRequestResponse{
94 Resource: Network,
95 Request: request,
96 Data: endpointID,
97 }
98 err := modifyContainer(containerID, requestMessage)
99
100 if err != nil {
101 return err
102 }
103
104 return nil
105 }
106
107
108 func GetHNSEndpointByID(endpointID string) (*HNSEndpoint, error) {
109 return hns.GetHNSEndpointByID(endpointID)
110 }
111
112
113 func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
114 return hns.GetHNSEndpointByName(endpointName)
115 }
116
117
118 func GetHNSEndpointStats(endpointName string) (*HNSEndpointStats, error) {
119 return hns.GetHNSEndpointStats(endpointName)
120 }
121
View as plain text