@@ -27,9 +27,7 @@ func createOrUpdateInterface(createNetworkContainerRequest cns.CreateNetworkCont
2727 return nil
2828 }
2929
30- exists , _ := interfaceExists (createNetworkContainerRequest .NetworkContainerid )
31-
32- if ! exists {
30+ if exists , _ := interfaceExists (createNetworkContainerRequest .NetworkContainerid ); ! exists {
3331 return createOrUpdateWithOperation (createNetworkContainerRequest , "CREATE" )
3432 }
3533
@@ -40,7 +38,7 @@ func updateInterface(createNetworkContainerRequest cns.CreateNetworkContainerReq
4038 return nil
4139}
4240
43- func setWeakHostOnInterface (ipAddress string ) error {
41+ func setWeakHostOnInterface (ipAddress , ncID string ) error {
4442 interfaces , err := net .Interfaces ()
4543 if err != nil {
4644 log .Printf ("[Azure CNS] Unable to retrieve interfaces on machine. %+v" , err )
@@ -76,7 +74,6 @@ func setWeakHostOnInterface(ipAddress string) error {
7674 }
7775
7876 ethIndexString := strconv .Itoa (targetIface .Index )
79- log .Printf ("[Azure CNS] Going to setup weak host routing for interface with index[%v, %v]\n " , targetIface .Index , ethIndexString )
8077
8178 args := []string {"/C" , "AzureNetworkContainer.exe" , "/logpath" , log .GetLogDirectory (),
8279 "/index" ,
@@ -88,17 +85,17 @@ func setWeakHostOnInterface(ipAddress string) error {
8885 "/weakhostreceive" ,
8986 "true" }
9087
91- log .Printf ("[Azure CNS] Going to enable weak host send/receive on interface: %v" , args )
88+ log .Printf ("[Azure CNS] Going to enable weak host send/receive on interface: %v for NC: %s " , args , ncID )
9289 c := exec .Command ("cmd" , args ... )
9390
94- loopbackOperationLock .Lock ()
9591 bytes , err := c .Output ()
96- loopbackOperationLock .Unlock ()
9792
9893 if err == nil {
99- log .Printf ("[Azure CNS] Successfully updated weak host send/receive on interface %v.\n " , string (bytes ))
94+ log .Printf ("[Azure CNS] Successfully updated weak host send/receive for NC: %s on interface %v" ,
95+ ncID , string (bytes ))
10096 } else {
101- log .Printf ("[Azure CNS] Received error while enable weak host send/receive on interface. %v - %v" , err .Error (), string (bytes ))
97+ log .Printf ("[Azure CNS] Failed to update weak host send/receive for NC: %s. Error: %v. Output: %v" ,
98+ ncID , err .Error (), string (bytes ))
10299 return err
103100 }
104101
@@ -140,17 +137,23 @@ func createOrUpdateWithOperation(createNetworkContainerRequest cns.CreateNetwork
140137 "/weakhostreceive" ,
141138 "true" }
142139
143- log .Printf ("[Azure CNS] Going to create/update network loopback adapter: %v" , args )
144140 c := exec .Command ("cmd" , args ... )
145141
146142 loopbackOperationLock .Lock ()
143+ log .Printf ("[Azure CNS] Going to create/update network loopback adapter: %v" , args )
147144 bytes , err := c .Output ()
145+ if err == nil {
146+ err = setWeakHostOnInterface (createNetworkContainerRequest .PrimaryInterfaceIdentifier ,
147+ createNetworkContainerRequest .NetworkContainerid )
148+ }
148149 loopbackOperationLock .Unlock ()
149150
150151 if err == nil {
151- log .Printf ("[Azure CNS] Successfully created network loopback adapter %v.\n " , string (bytes ))
152+ log .Printf ("[Azure CNS] Successfully created network loopback adapter for NC: %s. Output:%v." ,
153+ createNetworkContainerRequest .NetworkContainerid , string (bytes ))
152154 } else {
153- log .Printf ("Received error while Creating a Network Container %v %v" , err .Error (), string (bytes ))
155+ log .Printf ("Failed to create/update Network Container: %s. Error: %v. Output: %v" ,
156+ createNetworkContainerRequest .NetworkContainerid , err .Error (), string (bytes ))
154157 }
155158
156159 return err
@@ -174,17 +177,19 @@ func deleteInterface(networkContainerID string) error {
174177 "/operation" ,
175178 "DELETE" }
176179
177- log .Printf ("[Azure CNS] Going to delete network loopback adapter: %v" , args )
178180 c := exec .Command ("cmd" , args ... )
179181
180182 loopbackOperationLock .Lock ()
183+ log .Printf ("[Azure CNS] Going to delete network loopback adapter: %v" , args )
181184 bytes , err := c .Output ()
182185 loopbackOperationLock .Unlock ()
183186
184187 if err == nil {
185- log .Printf ("[Azure CNS] Successfully deleted network container %v.\n " , string (bytes ))
188+ log .Printf ("[Azure CNS] Successfully deleted network container: %s. Output: %v." ,
189+ networkContainerID , string (bytes ))
186190 } else {
187- log .Printf ("Received error while deleting a Network Container %v %v" , err .Error (), string (bytes ))
191+ log .Printf ("Failed to delete Network Container: %s. Error:%v. Output:%v" ,
192+ networkContainerID , err .Error (), string (bytes ))
188193 return err
189194 }
190195 return nil
0 commit comments