Skip to content

Commit 5dd0bea

Browse files
committed
initial changes to expose getnclist API in cns client
1 parent f9ea169 commit 5dd0bea

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

cns/NetworkContainerContract.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
NumberOfCPUCores = NumberOfCPUCoresPath
4141
NMAgentSupportedAPIs = NmAgentSupportedApisPath
4242
EndpointAPI = EndpointPath
43+
GetNCList = "/nclist"
4344
)
4445

4546
// NetworkContainer Prefixes

cns/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ type NmAgentSupportedApisResponse struct {
353353
SupportedApis []string
354354
}
355355

356+
type NCListResponse struct {
357+
Response Response `json:"response"`
358+
NCList []string `json:"ncList"`
359+
}
360+
356361
type HomeAzResponse struct {
357362
IsSupported bool `json:"isSupported"`
358363
HomeAz uint `json:"homeAz"`

cns/restserver/api.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,3 +1300,39 @@ func (service *HTTPRestService) getVMUniqueID(w http.ResponseWriter, r *http.Req
13001300
})
13011301
}
13021302
}
1303+
1304+
// This function is used to query all NCs on a node from NMAgent
1305+
func (service *HTTPRestService) nmAgentNCListHandler(w http.ResponseWriter, r *http.Request) {
1306+
logger.Request(service.Name, "nmAgentNCListHandler", nil)
1307+
var (
1308+
returnCode types.ResponseCode
1309+
returnMessage string
1310+
networkContainerList []string
1311+
)
1312+
1313+
ctx := r.Context()
1314+
switch r.Method {
1315+
case http.MethodGet:
1316+
ncVersionList, ncVersionerr := service.nma.GetNCVersionList(ctx)
1317+
if ncVersionerr != nil {
1318+
returnCode = types.NmAgentNCVersionListError
1319+
returnMessage = fmt.Sprintf("[Azure-CNS] %s", ncVersionerr.Error())
1320+
}
1321+
1322+
for _, container := range ncVersionList.Containers {
1323+
networkContainerList = append(networkContainerList, container.NetworkContainerID)
1324+
}
1325+
1326+
default:
1327+
returnMessage = "[Azure-CNS] NmAgentNCList API expects a GET method."
1328+
}
1329+
1330+
resp := cns.Response{ReturnCode: returnCode, Message: returnMessage}
1331+
NCListResponse := &cns.NCListResponse{
1332+
Response: resp,
1333+
NCList: networkContainerList,
1334+
}
1335+
1336+
serviceErr := common.Encode(w, &NCListResponse)
1337+
logger.Response(service.Name, NCListResponse, resp.ReturnCode, serviceErr)
1338+
}

cns/restserver/restserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func (service *HTTPRestService) Init(config *common.ServiceConfig) error {
292292
listener.AddHandler(cns.NetworkContainersURLPath, service.getOrRefreshNetworkContainers)
293293
listener.AddHandler(cns.GetHomeAz, service.getHomeAz)
294294
listener.AddHandler(cns.EndpointPath, service.EndpointHandlerAPI)
295+
listener.AddHandler(cns.GetNCList, service.nmAgentNCListHandler)
295296
// This API is only needed for Direct channel mode with Swift v2.
296297
if config.ChannelMode == cns.Direct {
297298
listener.AddHandler(cns.GetVMUniqueID, service.getVMUniqueID)
@@ -318,6 +319,7 @@ func (service *HTTPRestService) Init(config *common.ServiceConfig) error {
318319
listener.AddHandler(cns.V2Prefix+cns.NmAgentSupportedApisPath, service.nmAgentSupportedApisHandler)
319320
listener.AddHandler(cns.V2Prefix+cns.GetHomeAz, service.getHomeAz)
320321
listener.AddHandler(cns.V2Prefix+cns.EndpointPath, service.EndpointHandlerAPI)
322+
listener.AddHandler(cns.V2Prefix+cns.GetNCList, service.nmAgentNCListHandler)
321323
// This API is only needed for Direct channel mode with Swift v2.
322324
if config.ChannelMode == cns.Direct {
323325
listener.AddHandler(cns.V2Prefix+cns.GetVMUniqueID, service.getVMUniqueID)

cns/types/codes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
FailedToAllocateBackendConfig ResponseCode = 44
4747
ConnectionError ResponseCode = 45
4848
UnexpectedError ResponseCode = 99
49+
NmAgentNCVersionListError ResponseCode = 100
4950
)
5051

5152
// nolint:gocyclo

nmagent/responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type NCVersion struct {
3737
Version string `json:"version"` // the current network container version
3838
}
3939

40-
// NetworkContainerListResponse is a collection of network container IDs mapped
40+
// NCVersionList is a collection of network container IDs mapped
4141
// to their current versions.
4242
type NCVersionList struct {
4343
Containers []NCVersion `json:"networkContainers"`

0 commit comments

Comments
 (0)