Skip to content
Merged
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
38 changes: 19 additions & 19 deletions cns/cnsclient/cnsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"

"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/log"
)

// CNSClient specifies a client to connect to Ipam Plugin.
Expand Down Expand Up @@ -55,42 +55,42 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte)

httpc := &http.Client{}
url := cnsClient.connectionURL + cns.GetNetworkContainerByOrchestratorContext
logger.Printf("GetNetworkConfiguration url %v", url)
log.Printf("GetNetworkConfiguration url %v", url)

payload := &cns.GetNetworkContainerRequest{
OrchestratorContext: orchestratorContext,
}

err := json.NewEncoder(&body).Encode(payload)
if err != nil {
logger.Errorf("encoding json failed with %v", err)
log.Errorf("encoding json failed with %v", err)
return nil, err
}

res, err := httpc.Post(url, "application/json", &body)
if err != nil {
logger.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return nil, err
}

defer res.Body.Close()

if res.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("[Azure CNSClient] GetNetworkConfiguration invalid http status code: %v", res.StatusCode)
logger.Errorf(errMsg)
log.Errorf(errMsg)
return nil, fmt.Errorf(errMsg)
}

var resp cns.GetNetworkContainerResponse

err = json.NewDecoder(res.Body).Decode(&resp)
if err != nil {
logger.Errorf("[Azure CNSClient] Error received while parsing GetNetworkConfiguration response resp:%v err:%v", res.Body, err.Error())
log.Errorf("[Azure CNSClient] Error received while parsing GetNetworkConfiguration response resp:%v err:%v", res.Body, err.Error())
return nil, err
}

if resp.Response.ReturnCode != 0 {
logger.Errorf("[Azure CNSClient] GetNetworkConfiguration received error response :%v", resp.Response.Message)
log.Errorf("[Azure CNSClient] GetNetworkConfiguration received error response :%v", resp.Response.Message)
return nil, fmt.Errorf(resp.Response.Message)
}

Expand All @@ -107,20 +107,20 @@ func (cnsClient *CNSClient) CreateHostNCApipaEndpoint(

httpc := &http.Client{}
url := cnsClient.connectionURL + cns.CreateHostNCApipaEndpointPath
logger.Printf("CreateHostNCApipaEndpoint url: %v for NC: %s", url, networkContainerID)
log.Printf("CreateHostNCApipaEndpoint url: %v for NC: %s", url, networkContainerID)

payload := &cns.CreateHostNCApipaEndpointRequest{
NetworkContainerID: networkContainerID,
}

if err = json.NewEncoder(&body).Encode(payload); err != nil {
logger.Errorf("encoding json failed with %v", err)
log.Errorf("encoding json failed with %v", err)
return "", err
}

res, err := httpc.Post(url, "application/json", &body)
if err != nil {
logger.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return "", err
}

Expand All @@ -129,20 +129,20 @@ func (cnsClient *CNSClient) CreateHostNCApipaEndpoint(
if res.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("[Azure CNSClient] CreateHostNCApipaEndpoint: Invalid http status code: %v",
res.StatusCode)
logger.Errorf(errMsg)
log.Errorf(errMsg)
return "", fmt.Errorf(errMsg)
}

var resp cns.CreateHostNCApipaEndpointResponse

if err = json.NewDecoder(res.Body).Decode(&resp); err != nil {
logger.Errorf("[Azure CNSClient] Error parsing CreateHostNCApipaEndpoint response resp: %v err: %v",
log.Errorf("[Azure CNSClient] Error parsing CreateHostNCApipaEndpoint response resp: %v err: %v",
res.Body, err.Error())
return "", err
}

if resp.Response.ReturnCode != 0 {
logger.Errorf("[Azure CNSClient] CreateHostNCApipaEndpoint received error response :%v", resp.Response.Message)
log.Errorf("[Azure CNSClient] CreateHostNCApipaEndpoint received error response :%v", resp.Response.Message)
return "", fmt.Errorf(resp.Response.Message)
}

Expand All @@ -155,21 +155,21 @@ func (cnsClient *CNSClient) DeleteHostNCApipaEndpoint(networkContainerID string)

httpc := &http.Client{}
url := cnsClient.connectionURL + cns.DeleteHostNCApipaEndpointPath
logger.Printf("DeleteHostNCApipaEndpoint url: %v for NC: %s", url, networkContainerID)
log.Printf("DeleteHostNCApipaEndpoint url: %v for NC: %s", url, networkContainerID)

payload := &cns.DeleteHostNCApipaEndpointRequest{
NetworkContainerID: networkContainerID,
}

err := json.NewEncoder(&body).Encode(payload)
if err != nil {
logger.Errorf("encoding json failed with %v", err)
log.Errorf("encoding json failed with %v", err)
return err
}

res, err := httpc.Post(url, "application/json", &body)
if err != nil {
logger.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return err
}

Expand All @@ -178,21 +178,21 @@ func (cnsClient *CNSClient) DeleteHostNCApipaEndpoint(networkContainerID string)
if res.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("[Azure CNSClient] DeleteHostNCApipaEndpoint: Invalid http status code: %v",
res.StatusCode)
logger.Errorf(errMsg)
log.Errorf(errMsg)
return fmt.Errorf(errMsg)
}

var resp cns.DeleteHostNCApipaEndpointResponse

err = json.NewDecoder(res.Body).Decode(&resp)
if err != nil {
logger.Errorf("[Azure CNSClient] Error parsing DeleteHostNCApipaEndpoint response resp: %v err: %v",
log.Errorf("[Azure CNSClient] Error parsing DeleteHostNCApipaEndpoint response resp: %v err: %v",
res.Body, err.Error())
return err
}

if resp.Response.ReturnCode != 0 {
logger.Errorf("[Azure CNSClient] DeleteHostNCApipaEndpoint received error response :%v", resp.Response.Message)
log.Errorf("[Azure CNSClient] DeleteHostNCApipaEndpoint received error response :%v", resp.Response.Message)
return fmt.Errorf(resp.Response.Message)
}

Expand Down