Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cns/configuration/cns_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"UseHTTPS" : false,
"TLSSubjectName" : "",
"TLSCertificatePath" : "",
"TLSEndpoint" : "localhost:10091"
"TLSEndpoint" : "localhost:10091",
"WireserverIP": "168.63.129.16"
}
1 change: 1 addition & 0 deletions cns/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type CNSConfig struct {
TLSSubjectName string
TLSCertificatePath string
TLSEndpoint string
WireserverIP string
}

type TelemetrySettings struct {
Expand Down
20 changes: 19 additions & 1 deletion cns/restserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"net"
"net/http"
"regexp"
"runtime"
"strings"

Expand Down Expand Up @@ -1139,6 +1140,16 @@ func getAuthTokenFromCreateNetworkContainerURL(
return strings.Split(strings.Split(createNetworkContainerURL, "authenticationToken/")[1], "/")[0]
}

var rgx = regexp.MustCompile("^http[s]?://(.*?)/joinedVirtualNetworks.*?$")

func extractHostFromJoinNetworkURL(url string) string {
submatches := rgx.FindStringSubmatch(url)
if len(submatches) != 2 {
return ""
}
return submatches[1]
}

// Publish Network Container by calling nmagent
func (service *HTTPRestService) publishNetworkContainer(w http.ResponseWriter, r *http.Request) {
logger.Printf("[Azure-CNS] PublishNetworkContainer")
Expand Down Expand Up @@ -1199,8 +1210,15 @@ func (service *HTTPRestService) publishNetworkContainer(w http.ResponseWriter, r
// Store ncGetVersionURL needed for calling NMAgent to check if vfp programming is completed for the NC
primaryInterfaceIdentifier := getInterfaceIdFromCreateNetworkContainerURL(req.CreateNetworkContainerURL)
authToken := getAuthTokenFromCreateNetworkContainerURL(req.CreateNetworkContainerURL)

// we attempt to extract the wireserver IP to use from the request, otherwise default to the well-known IP.
hostIP := extractHostFromJoinNetworkURL(req.JoinNetworkURL)
if hostIP == "" {
hostIP = nmagentclient.WireserverIP
}

ncGetVersionURL := fmt.Sprintf(nmagentclient.GetNetworkContainerVersionURLFmt,
nmagentclient.WireserverIP,
hostIP,
primaryInterfaceIdentifier,
req.NetworkContainerID,
authToken)
Expand Down
10 changes: 10 additions & 0 deletions cns/restserver/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ func publishNCViaCNS(t *testing.T,
fmt.Printf("PublishNetworkContainer succeded with response %+v, raw:%+v\n", resp, w.Body)
}

func TestExtractHost(t *testing.T) {
joinURL := "http://127.0.0.1:9001/joinedVirtualNetworks/c9b8e695-2de1-11eb-bf54-000d3af666c8/api-version/1"

host := extractHostFromJoinNetworkURL(joinURL)
expected := "127.0.0.1:9001"
if host != expected {
t.Fatalf("expected host %q, got %q", expected, host)
}
}

func TestUnpublishNCViaCNS(t *testing.T) {
fmt.Println("Test: unpublishNetworkContainer")

Expand Down
4 changes: 4 additions & 0 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ func main() {
configuration.SetCNSConfigDefaults(&cnsconfig)
logger.Printf("[Azure CNS] Read config :%+v", cnsconfig)

if cnsconfig.WireserverIP != "" {
nmagentclient.WireserverIP = cnsconfig.WireserverIP
}

if cnsconfig.ChannelMode == cns.Managed {
config.ChannelMode = cns.Managed
privateEndpoint = cnsconfig.ManagedSettings.PrivateEndpoint
Expand Down