1+ param (
2+ [string ]$SubscriptionId ,
3+ [string ]$Location ,
4+ [string ]$ModelsParameter
5+ )
6+
7+ # Verify all required parameters are provided
8+ $MissingParams = @ ()
9+
10+ if (-not $SubscriptionId ) {
11+ $MissingParams += " subscription"
12+ }
13+
14+ if (-not $Location ) {
15+ $MissingParams += " location"
16+ }
17+
18+ if (-not $ModelsParameter ) {
19+ $MissingParams += " models-parameter"
20+ }
21+
22+ if ($MissingParams.Count -gt 0 ) {
23+ Write-Error " ❌ ERROR: Missing required parameters: $ ( $MissingParams -join ' , ' ) "
24+ Write-Host " Usage: .\validate_model_deployment_quotas.ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
25+ exit 1
26+ }
27+
28+ $JsonContent = Get-Content - Path " ./infra/main.parameters.json" - Raw | ConvertFrom-Json
29+
30+ if (-not $JsonContent ) {
31+ Write-Error " ❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
32+ exit 1
33+ }
34+
35+ $aiModelDeployments = $JsonContent.parameters .$ModelsParameter.value
36+
37+ if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable ])) {
38+ Write-Error " ❌ ERROR: The specified property $ModelsParameter does not exist or is not an array."
39+ exit 1
40+ }
41+
42+ # Set the Azure subscription
43+ az account set -- subscription $SubscriptionId
44+ Write-Host " 🎯 Active Subscription: $ ( az account show -- query ' [name, id]' -- output tsv) "
45+
46+ $QuotaAvailable = $true
47+
48+ # Iterate over each deployment in the aiModelDeployments array
49+ foreach ($deployment in $aiModelDeployments ) {
50+ $name = $deployment.name
51+ $model = $deployment.model.name
52+ $type = $deployment.sku.name
53+ $capacity = $deployment.sku.capacity
54+
55+ # Call the validate_model_quota.ps1 script
56+ Write-Host " 🔍 Validating model deployment: $name ..."
57+ & .\scripts\validate_model_quota.ps1 - Location $Location - Model $model - Capacity $capacity - DeploymentType $type
58+
59+ # Check if the script failed
60+ if ($LASTEXITCODE -ne 0 ) {
61+ Write-Error " ❌ ERROR: Quota validation failed for model deployment: $name "
62+ $QuotaAvailable = $false
63+ }
64+ }
65+
66+ if (-not $QuotaAvailable ) {
67+ Write-Error " ❌ ERROR: One or more model deployments failed validation."
68+ exit 1
69+ } else {
70+ Write-Host " ✅ All model deployments passed quota validation successfully."
71+ exit 0
72+ }
0 commit comments