mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-16 06:46:48 +00:00
Improve select-datastore with cluster based filtering (#5013)
This commit is contained in:
@@ -55,7 +55,8 @@ jobs:
|
|||||||
arguments: -VMName "$(VirtualMachineName)" `
|
arguments: -VMName "$(VirtualMachineName)" `
|
||||||
-VIServer "$(vcenter-server-v2)" `
|
-VIServer "$(vcenter-server-v2)" `
|
||||||
-VIUserName "$(vcenter-username-v2)" `
|
-VIUserName "$(vcenter-username-v2)" `
|
||||||
-VIPassword "$(vcenter-password-v2)"
|
-VIPassword '$(vcenter-password-v2)' `
|
||||||
|
-Cluster "$(esxi-cluster-v2)"
|
||||||
|
|
||||||
- pwsh: |
|
- pwsh: |
|
||||||
$SensitiveData = @(
|
$SensitiveData = @(
|
||||||
@@ -66,13 +67,14 @@ jobs:
|
|||||||
packer build -on-error=abort `
|
packer build -on-error=abort `
|
||||||
-var="vcenter_server=$(vcenter-server-v2)" `
|
-var="vcenter_server=$(vcenter-server-v2)" `
|
||||||
-var="vcenter_username=$(vcenter-username-v2)" `
|
-var="vcenter_username=$(vcenter-username-v2)" `
|
||||||
-var="vcenter_password=$(vcenter-password-v2)" `
|
-var='vcenter_password=$(vcenter-password-v2)' `
|
||||||
-var="vcenter_datacenter=$(vcenter-datacenter-v2)" `
|
-var="vcenter_datacenter=$(vcenter-datacenter-v2)" `
|
||||||
-var="cluster_or_esxi_host=$(esxi-cluster-v2)" `
|
-var="cluster_or_esxi_host=$(esxi-cluster-v2)" `
|
||||||
-var="esxi_datastore=$(buildDatastore)" `
|
-var="esxi_datastore=$(buildDatastore)" `
|
||||||
-var="output_folder=$(output-folder)" `
|
-var="output_folder=$(output-folder)" `
|
||||||
-var="vm_username=$(vm-username)" `
|
-var="vm_username=$(vm-username)" `
|
||||||
-var="vm_password=$(vm-password)" `
|
-var="vm_password=$(vm-password)" `
|
||||||
|
-var="github_api_pat=$(github_api_pat)" `
|
||||||
-var="build_id=$(VirtualMachineName)" `
|
-var="build_id=$(VirtualMachineName)" `
|
||||||
-var="baseimage_name=${{ parameters.base_image_name }}" `
|
-var="baseimage_name=${{ parameters.base_image_name }}" `
|
||||||
-var="xcode_install_user=$(xcode-installation-user)" `
|
-var="xcode_install_user=$(xcode-installation-user)" `
|
||||||
@@ -130,7 +132,7 @@ jobs:
|
|||||||
-TargetDataStore "${{ parameters.target_datastore }}" `
|
-TargetDataStore "${{ parameters.target_datastore }}" `
|
||||||
-VIServer "$(vcenter-server-v2)" `
|
-VIServer "$(vcenter-server-v2)" `
|
||||||
-VIUserName "$(vcenter-username-v2)" `
|
-VIUserName "$(vcenter-username-v2)" `
|
||||||
-VIPassword "$(vcenter-password-v2)"
|
-VIPassword '$(vcenter-password-v2)' `
|
||||||
-CpuCount "$(cpu-count)" `
|
-CpuCount "$(cpu-count)" `
|
||||||
-CoresPerSocketCount "$(cores-per-socket-count)" `
|
-CoresPerSocketCount "$(cores-per-socket-count)" `
|
||||||
-Memory "$(memory)"
|
-Memory "$(memory)"
|
||||||
@@ -144,4 +146,4 @@ jobs:
|
|||||||
arguments: -VMName "$(VirtualMachineName)" `
|
arguments: -VMName "$(VirtualMachineName)" `
|
||||||
-VIServer "$(vcenter-server-v2)" `
|
-VIServer "$(vcenter-server-v2)" `
|
||||||
-VIUserName "$(vcenter-username-v2)" `
|
-VIUserName "$(vcenter-username-v2)" `
|
||||||
-VIPassword "$(vcenter-password-v2)"
|
-VIPassword '$(vcenter-password-v2)'
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ param(
|
|||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$VIPassword,
|
[string]$VIPassword,
|
||||||
|
|
||||||
[string]$TagCategory = "Busy"
|
[string]$TagCategory = "Busy",
|
||||||
|
|
||||||
|
[string]$Cluster
|
||||||
)
|
)
|
||||||
|
|
||||||
# Import helpers module
|
# Import helpers module
|
||||||
@@ -47,6 +49,7 @@ function Select-DataStore {
|
|||||||
[string]$VMName,
|
[string]$VMName,
|
||||||
[string]$TagCategory,
|
[string]$TagCategory,
|
||||||
[string]$TemplateDatastore = "ds-local-Datastore-*",
|
[string]$TemplateDatastore = "ds-local-Datastore-*",
|
||||||
|
[string]$Cluster,
|
||||||
[int]$ThresholdInGb = 400,
|
[int]$ThresholdInGb = 400,
|
||||||
[int]$VMCount = 2,
|
[int]$VMCount = 2,
|
||||||
[int]$Retries = 5
|
[int]$Retries = 5
|
||||||
@@ -57,8 +60,9 @@ function Select-DataStore {
|
|||||||
# 3. Choose a datastore with the minimal VM count < 2
|
# 3. Choose a datastore with the minimal VM count < 2
|
||||||
|
|
||||||
Write-Host "Start Datastore selection process..."
|
Write-Host "Start Datastore selection process..."
|
||||||
$allDatastores = Get-Datastore -Name $templateDatastore | Where-Object { $_.State -eq "Available" }
|
$clusterHosts = Get-Cluster -Name $Cluster | Get-VMHost
|
||||||
$availableDatastores = $allDatastores `
|
$availableClusterDatastores = $clusterHosts | Get-Datastore -Name $TemplateDatastore | Where-Object -Property State -eq "Available"
|
||||||
|
$availableDatastores = $availableClusterDatastores `
|
||||||
| 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
|
||||||
@@ -101,11 +105,11 @@ function Select-DataStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Datastore select failed, $retries left"
|
Write-Host "Datastore select failed, $retries left"
|
||||||
Select-DataStore -VMName $VMName -TagCategory $TagCategory -Retries $retries
|
Select-DataStore -VMName $VMName -Cluster $Cluster -TagCategory $TagCategory -Retries $retries
|
||||||
}
|
}
|
||||||
|
|
||||||
# Connection to a vCenter Server system
|
# Connection to a vCenter Server system
|
||||||
Connect-VCServer -VIServer $VIServer -VIUserName $VIUserName -VIPassword $VIPassword
|
Connect-VCServer -VIServer $VIServer -VIUserName $VIUserName -VIPassword $VIPassword
|
||||||
|
|
||||||
# Get a target datastore for current deployment
|
# Get a target datastore for current deployment
|
||||||
Select-DataStore -VMName $VMName -TagCategory $TagCategory
|
Select-DataStore -VMName $VMName -Cluster $Cluster -TagCategory $TagCategory
|
||||||
|
|||||||
@@ -31,7 +31,8 @@
|
|||||||
"vm_name": "{{user `build_id`}}",
|
"vm_name": "{{user `build_id`}}",
|
||||||
"ssh_username": "{{user `vm_username`}}",
|
"ssh_username": "{{user `vm_username`}}",
|
||||||
"ssh_password": "{{user `vm_password`}}",
|
"ssh_password": "{{user `vm_password`}}",
|
||||||
"CPUs": "10",
|
"CPUs": "5",
|
||||||
|
"cpu_cores": "5",
|
||||||
"RAM": "24576",
|
"RAM": "24576",
|
||||||
"NestedHV": "true",
|
"NestedHV": "true",
|
||||||
"shutdown_timeout": "15m"
|
"shutdown_timeout": "15m"
|
||||||
|
|||||||
@@ -31,7 +31,8 @@
|
|||||||
"vm_name": "{{user `build_id`}}",
|
"vm_name": "{{user `build_id`}}",
|
||||||
"ssh_username": "{{user `vm_username`}}",
|
"ssh_username": "{{user `vm_username`}}",
|
||||||
"ssh_password": "{{user `vm_password`}}",
|
"ssh_password": "{{user `vm_password`}}",
|
||||||
"CPUs": "10",
|
"CPUs": "5",
|
||||||
|
"cpu_cores": "5",
|
||||||
"RAM": "24576",
|
"RAM": "24576",
|
||||||
"NestedHV": "true",
|
"NestedHV": "true",
|
||||||
"shutdown_timeout": "15m"
|
"shutdown_timeout": "15m"
|
||||||
|
|||||||
@@ -31,7 +31,8 @@
|
|||||||
"vm_name": "{{user `build_id`}}",
|
"vm_name": "{{user `build_id`}}",
|
||||||
"ssh_username": "{{user `vm_username`}}",
|
"ssh_username": "{{user `vm_username`}}",
|
||||||
"ssh_password": "{{user `vm_password`}}",
|
"ssh_password": "{{user `vm_password`}}",
|
||||||
"CPUs": "10",
|
"CPUs": "5",
|
||||||
|
"cpu_cores": "5",
|
||||||
"RAM": "24576",
|
"RAM": "24576",
|
||||||
"NestedHV": "true",
|
"NestedHV": "true",
|
||||||
"shutdown_timeout": "15m"
|
"shutdown_timeout": "15m"
|
||||||
|
|||||||
Reference in New Issue
Block a user