Skip to content

Commit 6ec4cc1

Browse files
committed
added function to get number of CPUs from template
1 parent a07e78c commit 6ec4cc1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/AzManagers.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,33 @@ function quotacheck(manager, subscriptionid, template, δn, nretry, verbose)
21622162
ncores_available - (ncores_per_machine * δn), ncores_spot_available - (ncores_per_machine * δn)
21632163
end
21642164

2165+
function get_CPU(template)
2166+
isfile(templates_filename_vm()) || error("scale-set template file does not exist. See `AzManagers.save_template_scaleset`")
2167+
2168+
templates_scaleset = JSON.parse(read(templates_filename_vm(), String))
2169+
haskey(templates_scaleset, template) || error("scale-set template file does not contain a template with name: $template. See `AzManagers.save_template_scaleset`")
2170+
template = templates_scaleset[template]
2171+
2172+
ssid = template["subscriptionid"]
2173+
region = template["value"]["location"]
2174+
sku_name = template["value"]["properties"]["hardwareProfile"]["vmSize"]
2175+
2176+
_r = HTTP.request("GET",
2177+
"https://management.azure.com/subscriptions/$ssid/providers/Microsoft.Compute/skus?api-version=2022-11-01",
2178+
["Authorization" => "Bearer $(token(AzSession(;lazy=true)))"])
2179+
r = JSON.parse(String(_r.body))
2180+
2181+
2182+
filtered_skus = filter(sku -> sku["name"] == sku_name && haskey(sku, "capabilities") && any(location -> location == region, sku["locations"]), r["value"])
2183+
2184+
vCPU_details = [(cap["value"], any(cap -> cap["name"] == "HyperThreadingEnabled" && cap["value"] == "true", sku["capabilities"])) for sku in filtered_skus for cap in sku["capabilities"] if cap["name"] == "vCPUs"]
2185+
hyperthreading = vCPU_details[1][2]
2186+
vCPU = vCPU_details[1][1]
2187+
2188+
# Number of physical cores
2189+
pCPU = hyperthreading ? div(parse(Int,vCPU),2) : parse(Int,vCPU)
2190+
end
2191+
21652192
function getnextlinks!(manager::AzManager, _r, value, nextlink, nretry, verbose)
21662193
while nextlink != ""
21672194
_r = @retry nretry azrequest(

0 commit comments

Comments
 (0)