mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-20 06:29:50 +00:00
[macOS] Improve select-datastore script rev2 (#2772)
* select last one * Fix comment * Change logic * change name * fix comment
This commit is contained in:
@@ -58,15 +58,15 @@ function Select-DataStore {
|
|||||||
|
|
||||||
Write-Host "Start Datastore selection process..."
|
Write-Host "Start Datastore selection process..."
|
||||||
$allDatastores = Get-Datastore -Name $templateDatastore | Where-Object { $_.State -eq "Available" }
|
$allDatastores = Get-Datastore -Name $templateDatastore | Where-Object { $_.State -eq "Available" }
|
||||||
$buildDatastore = $allDatastores `
|
$availableDatastores = $allDatastores `
|
||||||
| Where-Object { $_.FreeSpaceGB -ge $thresholdInGb } `
|
| Where-Object { $_.FreeSpaceGB -ge $thresholdInGb } `
|
||||||
| Where-Object {
|
| Where-Object {
|
||||||
$vmOnDatastore = @((Get-ChildItem -Path $_.DatastoreBrowserPath).Name -notmatch "^\.").Count
|
$vmOnDatastore = @((Get-ChildItem -Path $_.DatastoreBrowserPath).Name -notmatch "^\.").Count
|
||||||
$vmOnDatastore -lt $vmCount } `
|
$vmOnDatastore -lt $vmCount } `
|
||||||
| Group-Object -Property { $vmOnDatastore } `
|
| Group-Object -Property { $vmOnDatastore }
|
||||||
| Select-Object -First 1 -ExpandProperty Group `
|
|
||||||
| Get-Random `
|
$datastore = $availableDatastores | Select-Object @{n="VmCount";e={$_.Name}},@{n="DatastoreName";e={$_.Group | Get-Random}} -First 1
|
||||||
| Select-Object -ExpandProperty Name
|
$buildDatastore = $datastore.DatastoreName
|
||||||
|
|
||||||
$tag = Get-Tag -Category $TagCategory -Name $VMName -ErrorAction Ignore
|
$tag = Get-Tag -Category $TagCategory -Name $VMName -ErrorAction Ignore
|
||||||
if (-not $tag)
|
if (-not $tag)
|
||||||
@@ -78,8 +78,9 @@ function Select-DataStore {
|
|||||||
|
|
||||||
# Wait for 60 seconds to check if any other tags are assigned to the same datastore
|
# Wait for 60 seconds to check if any other tags are assigned to the same datastore
|
||||||
Start-Sleep -Seconds 60
|
Start-Sleep -Seconds 60
|
||||||
# Take the last tag (Last in, first out), all the others will go to the next round
|
# If there are no datastores with 0 VMs, take a datastore with 1 VM (index 1 if datastore has 0 VMs and 2 if 1 VM)
|
||||||
$tagAssignments = (Get-TagAssignment -Entity $buildDatastore).Tag.Name | Select-Object -Last 1
|
$index = 1 + [int]$datastore.VmCount
|
||||||
|
$tagAssignments = (Get-TagAssignment -Entity $buildDatastore).Tag.Name | Select-Object -First $index
|
||||||
$isAllow = $tagAssignments -contains $VMName
|
$isAllow = $tagAssignments -contains $VMName
|
||||||
|
|
||||||
if ($isAllow)
|
if ($isAllow)
|
||||||
|
|||||||
Reference in New Issue
Block a user