-
Notifications
You must be signed in to change notification settings - Fork 260
Optimize call flow to complete loopback adapter creation #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ashvindeodhar
merged 2 commits into
Azure:master
from
ashvindeodhar:networkcontainer-optimization
Sep 30, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,7 @@ func createOrUpdateInterface(createNetworkContainerRequest cns.CreateNetworkCont | |
| return nil | ||
| } | ||
|
|
||
| exists, _ := interfaceExists(createNetworkContainerRequest.NetworkContainerid) | ||
|
|
||
| if !exists { | ||
| if exists, _ := interfaceExists(createNetworkContainerRequest.NetworkContainerid); !exists { | ||
| return createOrUpdateWithOperation(createNetworkContainerRequest, "CREATE") | ||
| } | ||
|
|
||
|
|
@@ -40,7 +38,7 @@ func updateInterface(createNetworkContainerRequest cns.CreateNetworkContainerReq | |
| return nil | ||
| } | ||
|
|
||
| func setWeakHostOnInterface(ipAddress string) error { | ||
| func setWeakHostOnInterface(ipAddress, ncID string) error { | ||
| interfaces, err := net.Interfaces() | ||
| if err != nil { | ||
| log.Printf("[Azure CNS] Unable to retrieve interfaces on machine. %+v", err) | ||
|
|
@@ -76,7 +74,6 @@ func setWeakHostOnInterface(ipAddress string) error { | |
| } | ||
|
|
||
| ethIndexString := strconv.Itoa(targetIface.Index) | ||
| log.Printf("[Azure CNS] Going to setup weak host routing for interface with index[%v, %v]\n", targetIface.Index, ethIndexString) | ||
|
|
||
| args := []string{"/C", "AzureNetworkContainer.exe", "/logpath", log.GetLogDirectory(), | ||
| "/index", | ||
|
|
@@ -88,17 +85,17 @@ func setWeakHostOnInterface(ipAddress string) error { | |
| "/weakhostreceive", | ||
| "true"} | ||
|
|
||
| log.Printf("[Azure CNS] Going to enable weak host send/receive on interface: %v", args) | ||
| log.Printf("[Azure CNS] Going to enable weak host send/receive on interface: %v for NC: %s", args, ncID) | ||
| c := exec.Command("cmd", args...) | ||
|
|
||
| loopbackOperationLock.Lock() | ||
| bytes, err := c.Output() | ||
| loopbackOperationLock.Unlock() | ||
|
|
||
| if err == nil { | ||
| log.Printf("[Azure CNS] Successfully updated weak host send/receive on interface %v.\n", string(bytes)) | ||
| log.Printf("[Azure CNS] Successfully updated weak host send/receive for NC: %s on interface %v", | ||
| ncID, string(bytes)) | ||
| } else { | ||
| log.Printf("[Azure CNS] Received error while enable weak host send/receive on interface. %v - %v", err.Error(), string(bytes)) | ||
| log.Printf("[Azure CNS] Failed to update weak host send/receive for NC: %s. Error: %v. Output: %v", | ||
| ncID, err.Error(), string(bytes)) | ||
| return err | ||
| } | ||
|
|
||
|
|
@@ -140,17 +137,23 @@ func createOrUpdateWithOperation(createNetworkContainerRequest cns.CreateNetwork | |
| "/weakhostreceive", | ||
| "true"} | ||
|
|
||
| log.Printf("[Azure CNS] Going to create/update network loopback adapter: %v", args) | ||
| c := exec.Command("cmd", args...) | ||
|
|
||
| loopbackOperationLock.Lock() | ||
| log.Printf("[Azure CNS] Going to create/update network loopback adapter: %v", args) | ||
| bytes, err := c.Output() | ||
| if err == nil { | ||
| err = setWeakHostOnInterface(createNetworkContainerRequest.PrimaryInterfaceIdentifier, | ||
| createNetworkContainerRequest.NetworkContainerid) | ||
| } | ||
| loopbackOperationLock.Unlock() | ||
|
|
||
| if err == nil { | ||
| log.Printf("[Azure CNS] Successfully created network loopback adapter %v.\n", string(bytes)) | ||
| log.Printf("[Azure CNS] Successfully created network loopback adapter for NC: %s. Output:%v.", | ||
| createNetworkContainerRequest.NetworkContainerid, string(bytes)) | ||
| } else { | ||
| log.Printf("Received error while Creating a Network Container %v %v", err.Error(), string(bytes)) | ||
| log.Printf("Failed to create/update Network Container: %s. Error: %v. Output: %v", | ||
| createNetworkContainerRequest.NetworkContainerid, err.Error(), string(bytes)) | ||
| } | ||
|
|
||
| return err | ||
|
|
@@ -174,17 +177,19 @@ func deleteInterface(networkContainerID string) error { | |
| "/operation", | ||
| "DELETE"} | ||
|
|
||
| log.Printf("[Azure CNS] Going to delete network loopback adapter: %v", args) | ||
| c := exec.Command("cmd", args...) | ||
|
|
||
| loopbackOperationLock.Lock() | ||
| log.Printf("[Azure CNS] Going to delete network loopback adapter: %v", args) | ||
| bytes, err := c.Output() | ||
| loopbackOperationLock.Unlock() | ||
|
|
||
| if err == nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you think we can just combine this? a single line?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which lines are you suggesting to combine? |
||
| log.Printf("[Azure CNS] Successfully deleted network container %v.\n", string(bytes)) | ||
| log.Printf("[Azure CNS] Successfully deleted network container: %s. Output: %v.", | ||
| networkContainerID, string(bytes)) | ||
| } else { | ||
| log.Printf("Received error while deleting a Network Container %v %v", err.Error(), string(bytes)) | ||
| log.Printf("Failed to delete Network Container: %s. Error:%v. Output:%v", | ||
| networkContainerID, err.Error(), string(bytes)) | ||
| return err | ||
| } | ||
| return nil | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this function even needed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there way to asset the lock has been acquired already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asset the lock?
Keeping the function separate because it's still a separate functionality