1
+ // +build windows
2
+
3
+ // Copyright 2017 CNI authors
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS,
13
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ // See the License for the specific language governing permissions and
15
+ // limitations under the License.
16
+
1
17
package hns
2
18
3
19
import (
@@ -8,6 +24,9 @@ import (
8
24
"strings"
9
25
)
10
26
27
+ // ConstructEndpointName constructs enpointId which is used to identify an endpoint from HNS
28
+ // There is a special consideration for netNs name here, which is required for Windows Server 1709
29
+ // containerID is the Id of the container on which the endpoint is worked on
11
30
func ConstructEndpointName (containerID string , netNs string , networkName string ) string {
12
31
if netNs != "" {
13
32
splits := strings .Split (netNs , ":" )
@@ -19,6 +38,9 @@ func ConstructEndpointName(containerID string, netNs string, networkName string)
19
38
return epName
20
39
}
21
40
41
+ // DeprovisionEndpoint removes an endpoint from the container by sending a Detach request to HNS
42
+ // For shared endpoint, ContainerDetach is used
43
+ // for removing the endpoint completely, HotDetachEndpoint is used
22
44
func DeprovisionEndpoint (epName string , netns string , containerID string ) error {
23
45
hnsEndpoint , err := hcsshim .GetHNSEndpointByName (epName )
24
46
if err != nil {
@@ -52,6 +74,9 @@ func DeprovisionEndpoint(epName string, netns string, containerID string) error
52
74
53
75
type EndpointMakerFunc func () (* hcsshim.HNSEndpoint , error )
54
76
77
+ // ProvisionEndpoint provisions an endpoint to a container specified by containerID.
78
+ // If an endpoint already exists, the endpoint is reused.
79
+ // This call is idempotent
55
80
func ProvisionEndpoint (epName string , expectedNetworkId string , containerID string , makeEndpoint EndpointMakerFunc ) (* hcsshim.HNSEndpoint , error ) {
56
81
// check if endpoint already exists
57
82
createEndpoint := true
@@ -87,6 +112,7 @@ func ProvisionEndpoint(epName string, expectedNetworkId string, containerID stri
87
112
return hnsEndpoint , nil
88
113
}
89
114
115
+ // ConstructResult constructs the CNI result for the endpoint
90
116
func ConstructResult (hnsNetwork * hcsshim.HNSNetwork , hnsEndpoint * hcsshim.HNSEndpoint ) (* current.Result , error ) {
91
117
resultInterface := & current.Interface {
92
118
Name : hnsEndpoint .Name ,
0 commit comments