88 "fmt"
99 "net"
1010 "net/http"
11+ "runtime"
1112 "sync"
1213 "time"
1314
@@ -157,6 +158,7 @@ func (service *HTTPRestService) Start(config *common.ServiceConfig) error {
157158 listener .AddHandler (cns .DetachContainerFromNetwork , service .detachNetworkContainerFromNetwork )
158159 listener .AddHandler (cns .CreateHnsNetworkPath , service .createHnsNetwork )
159160 listener .AddHandler (cns .DeleteHnsNetworkPath , service .deleteHnsNetwork )
161+ listener .AddHandler (cns .NumberOfCPUCoresPath , service .getNumberOfCPUCores )
160162
161163 // handlers for v0.2
162164 listener .AddHandler (cns .V2Prefix + cns .SetEnvironmentPath , service .setEnvironment )
@@ -177,6 +179,7 @@ func (service *HTTPRestService) Start(config *common.ServiceConfig) error {
177179 listener .AddHandler (cns .V2Prefix + cns .DetachContainerFromNetwork , service .detachNetworkContainerFromNetwork )
178180 listener .AddHandler (cns .V2Prefix + cns .CreateHnsNetworkPath , service .createHnsNetwork )
179181 listener .AddHandler (cns .V2Prefix + cns .DeleteHnsNetworkPath , service .deleteHnsNetwork )
182+ listener .AddHandler (cns .V2Prefix + cns .NumberOfCPUCoresPath , service .getNumberOfCPUCores )
180183
181184 log .Printf ("[Azure CNS] Listening." )
182185 return nil
@@ -1573,3 +1576,32 @@ func (service *HTTPRestService) getNetPluginDetails() *networkcontainers.NetPlug
15731576 configPath , _ := service .GetOption (acn .OptNetPluginConfigFile ).(string )
15741577 return networkcontainers .NewNetPluginConfiguration (pluginBinPath , configPath )
15751578}
1579+
1580+ // Retrieves the number of logic processors on a node. It will be primarily
1581+ // used to enforce per VM delegated NIC limit by DNC.
1582+ func (service * HTTPRestService ) getNumberOfCPUCores (w http.ResponseWriter , r * http.Request ) {
1583+ log .Printf ("[Azure CNS] getNumberOfCPUCores" )
1584+ log .Request (service .Name , "getNumberOfCPUCores" , nil )
1585+
1586+ var num = 0
1587+ var returnCode = 0
1588+ var errmsg string
1589+
1590+ switch r .Method {
1591+ case "GET" :
1592+ num = runtime .NumCPU ()
1593+ default :
1594+ errmsg = "[Azure-CNS] getNumberOfCPUCores API expects a GET."
1595+ returnCode = UnsupportedVerb
1596+ }
1597+
1598+ resp := cns.Response {ReturnCode : returnCode , Message : errmsg }
1599+ numOfCPUCoresResp := cns.NumOfCPUCoresResponse {
1600+ Response : resp ,
1601+ NumOfCPUCores : num ,
1602+ }
1603+
1604+ err := service .Listener .Encode (w , & numOfCPUCoresResp )
1605+
1606+ log .Response (service .Name , numOfCPUCoresResp , resp .ReturnCode , ReturnCodeToString (resp .ReturnCode ), err )
1607+ }
0 commit comments