77
88 "github.com/Microsoft/hcsshim"
99 "github.com/Sirupsen/logrus"
10- "github.com/docker/libnetwork/datastore"
1110 "github.com/docker/libnetwork/driverapi"
12- "github.com/docker/libnetwork/types"
1311)
1412
1513type endpointTable map [string ]* endpoint
@@ -23,8 +21,6 @@ type endpoint struct {
2321 remote bool
2422 mac net.HardwareAddr
2523 addr * net.IPNet
26- dbExists bool
27- dbIndex uint64
2824}
2925
3026func validateID (nid , eid string ) error {
@@ -67,6 +63,7 @@ func (n *network) removeEndpointWithAddress(addr *net.IPNet) {
6763 break
6864 }
6965 }
66+
7067 if networkEndpoint != nil {
7168 delete (n .endpoints , networkEndpoint .id )
7269 }
@@ -79,10 +76,6 @@ func (n *network) removeEndpointWithAddress(addr *net.IPNet) {
7976 if err != nil {
8077 logrus .Debugf ("Failed to delete stale overlay endpoint (%s) from hns" , networkEndpoint .id [0 :7 ])
8178 }
82-
83- if err := n .driver .deleteEndpointFromStore (networkEndpoint ); err != nil {
84- logrus .Debugf ("Failed to delete stale overlay endpoint (%s) from store" , networkEndpoint .id [0 :7 ])
85- }
8679 }
8780}
8881
@@ -93,19 +86,23 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
9386 return err
9487 }
9588
96- // Since we perform lazy configuration make sure we try
97- // configuring the driver when we enter CreateEndpoint since
98- // CreateNetwork may not be called in every node.
99- if err := d .configure (); err != nil {
100- return err
101- }
102-
10389 n := d .network (nid )
10490 if n == nil {
10591 return fmt .Errorf ("network id %q not found" , nid )
10692 }
10793
108- ep := & endpoint {
94+ ep := n .endpoint (eid )
95+ if ep != nil {
96+ logrus .Debugf ("Deleting stale endpoint %s" , eid )
97+ n .deleteEndpoint (eid )
98+
99+ _ , err := hcsshim .HNSEndpointRequest ("DELETE" , ep .profileId , "" )
100+ if err != nil {
101+ return err
102+ }
103+ }
104+
105+ ep = & endpoint {
109106 id : eid ,
110107 nid : n .id ,
111108 addr : ifInfo .Address (),
@@ -123,6 +120,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
123120 // Todo: Add port bindings and qos policies here
124121
125122 hnsEndpoint := & hcsshim.HNSEndpoint {
123+ Name : eid ,
126124 VirtualNetwork : n .hnsId ,
127125 IPAddress : ep .addr .IP ,
128126 EnableInternalDNS : true ,
@@ -167,9 +165,6 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
167165 }
168166
169167 n .addEndpoint (ep )
170- if err := d .writeEndpointToStore (ep ); err != nil {
171- return fmt .Errorf ("failed to update overlay endpoint %s to local store: %v" , ep .id [0 :7 ], err )
172- }
173168
174169 return nil
175170}
@@ -191,10 +186,6 @@ func (d *driver) DeleteEndpoint(nid, eid string) error {
191186
192187 n .deleteEndpoint (eid )
193188
194- if err := d .deleteEndpointFromStore (ep ); err != nil {
195- logrus .Warnf ("Failed to delete overlay endpoint %s from local store: %v" , ep .id [0 :7 ], err )
196- }
197-
198189 _ , err := hcsshim .HNSEndpointRequest ("DELETE" , ep .profileId , "" )
199190 if err != nil {
200191 return err
@@ -223,124 +214,3 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro
223214 data ["AllowUnqualifiedDNSQuery" ] = true
224215 return data , nil
225216}
226-
227- func (d * driver ) deleteEndpointFromStore (e * endpoint ) error {
228- if d .localStore == nil {
229- return fmt .Errorf ("overlay local store not initialized, ep not deleted" )
230- }
231-
232- if err := d .localStore .DeleteObjectAtomic (e ); err != nil {
233- return err
234- }
235-
236- return nil
237- }
238-
239- func (d * driver ) writeEndpointToStore (e * endpoint ) error {
240- if d .localStore == nil {
241- return fmt .Errorf ("overlay local store not initialized, ep not added" )
242- }
243-
244- if err := d .localStore .PutObjectAtomic (e ); err != nil {
245- return err
246- }
247- return nil
248- }
249-
250- func (ep * endpoint ) DataScope () string {
251- return datastore .LocalScope
252- }
253-
254- func (ep * endpoint ) New () datastore.KVObject {
255- return & endpoint {}
256- }
257-
258- func (ep * endpoint ) CopyTo (o datastore.KVObject ) error {
259- dstep := o .(* endpoint )
260- * dstep = * ep
261- return nil
262- }
263-
264- func (ep * endpoint ) Key () []string {
265- return []string {overlayEndpointPrefix , ep .id }
266- }
267-
268- func (ep * endpoint ) KeyPrefix () []string {
269- return []string {overlayEndpointPrefix }
270- }
271-
272- func (ep * endpoint ) Index () uint64 {
273- return ep .dbIndex
274- }
275-
276- func (ep * endpoint ) SetIndex (index uint64 ) {
277- ep .dbIndex = index
278- ep .dbExists = true
279- }
280-
281- func (ep * endpoint ) Exists () bool {
282- return ep .dbExists
283- }
284-
285- func (ep * endpoint ) Skip () bool {
286- return false
287- }
288-
289- func (ep * endpoint ) Value () []byte {
290- b , err := json .Marshal (ep )
291- if err != nil {
292- return nil
293- }
294- return b
295- }
296-
297- func (ep * endpoint ) SetValue (value []byte ) error {
298- return json .Unmarshal (value , ep )
299- }
300-
301- func (ep * endpoint ) MarshalJSON () ([]byte , error ) {
302- epMap := make (map [string ]interface {})
303-
304- epMap ["id" ] = ep .id
305- epMap ["nid" ] = ep .nid
306- epMap ["remote" ] = ep .remote
307- if ep .profileId != "" {
308- epMap ["profileId" ] = ep .profileId
309- }
310-
311- if ep .addr != nil {
312- epMap ["addr" ] = ep .addr .String ()
313- }
314- if len (ep .mac ) != 0 {
315- epMap ["mac" ] = ep .mac .String ()
316- }
317-
318- return json .Marshal (epMap )
319- }
320-
321- func (ep * endpoint ) UnmarshalJSON (value []byte ) error {
322- var (
323- err error
324- epMap map [string ]interface {}
325- )
326-
327- json .Unmarshal (value , & epMap )
328-
329- ep .id = epMap ["id" ].(string )
330- ep .nid = epMap ["nid" ].(string )
331- ep .remote = epMap ["remote" ].(bool )
332- if v , ok := epMap ["profileId" ]; ok {
333- ep .profileId = v .(string )
334- }
335- if v , ok := epMap ["mac" ]; ok {
336- if ep .mac , err = net .ParseMAC (v .(string )); err != nil {
337- return types .InternalErrorf ("failed to decode endpoint interface mac address after json unmarshal: %s" , v .(string ))
338- }
339- }
340- if v , ok := epMap ["addr" ]; ok {
341- if ep .addr , err = types .ParseCIDR (v .(string )); err != nil {
342- return types .InternalErrorf ("failed to decode endpoint interface ipv4 address after json unmarshal: %v" , err )
343- }
344- }
345- return nil
346- }
0 commit comments