Improve select-datastore with cluster based filtering (#5013)

This commit is contained in:
Maksim Shilov
2022-02-07 10:30:14 +03:00
committed by GitHub
parent c01e7d1ed8
commit 30ffa34849
5 changed files with 21 additions and 12 deletions

View File

@@ -55,7 +55,8 @@ jobs:
arguments: -VMName "$(VirtualMachineName)" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword "$(vcenter-password-v2)"
-VIPassword '$(vcenter-password-v2)' `
-Cluster "$(esxi-cluster-v2)"
- pwsh: |
$SensitiveData = @(
@@ -66,13 +67,14 @@ jobs:
packer build -on-error=abort `
-var="vcenter_server=$(vcenter-server-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="cluster_or_esxi_host=$(esxi-cluster-v2)" `
-var="esxi_datastore=$(buildDatastore)" `
-var="output_folder=$(output-folder)" `
-var="vm_username=$(vm-username)" `
-var="vm_password=$(vm-password)" `
-var="github_api_pat=$(github_api_pat)" `
-var="build_id=$(VirtualMachineName)" `
-var="baseimage_name=${{ parameters.base_image_name }}" `
-var="xcode_install_user=$(xcode-installation-user)" `
@@ -130,7 +132,7 @@ jobs:
-TargetDataStore "${{ parameters.target_datastore }}" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword "$(vcenter-password-v2)"
-VIPassword '$(vcenter-password-v2)' `
-CpuCount "$(cpu-count)" `
-CoresPerSocketCount "$(cores-per-socket-count)" `
-Memory "$(memory)"
@@ -144,4 +146,4 @@ jobs:
arguments: -VMName "$(VirtualMachineName)" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword "$(vcenter-password-v2)"
-VIPassword '$(vcenter-password-v2)'

View File

@@ -36,7 +36,9 @@ param(
[ValidateNotNullOrEmpty()]
[string]$VIPassword,
[string]$TagCategory = "Busy"
[string]$TagCategory = "Busy",
[string]$Cluster
)
# Import helpers module
@@ -47,6 +49,7 @@ function Select-DataStore {
[string]$VMName,
[string]$TagCategory,
[string]$TemplateDatastore = "ds-local-Datastore-*",
[string]$Cluster,
[int]$ThresholdInGb = 400,
[int]$VMCount = 2,
[int]$Retries = 5
@@ -57,8 +60,9 @@ function Select-DataStore {
# 3. Choose a datastore with the minimal VM count < 2
Write-Host "Start Datastore selection process..."
$allDatastores = Get-Datastore -Name $templateDatastore | Where-Object { $_.State -eq "Available" }
$availableDatastores = $allDatastores `
$clusterHosts = Get-Cluster -Name $Cluster | Get-VMHost
$availableClusterDatastores = $clusterHosts | Get-Datastore -Name $TemplateDatastore | Where-Object -Property State -eq "Available"
$availableDatastores = $availableClusterDatastores `
| Where-Object { $_.FreeSpaceGB -ge $thresholdInGb } `
| Where-Object {
$vmOnDatastore = @((Get-ChildItem -Path $_.DatastoreBrowserPath).Name -notmatch "^\.").Count
@@ -101,11 +105,11 @@ function Select-DataStore {
}
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
Connect-VCServer -VIServer $VIServer -VIUserName $VIUserName -VIPassword $VIPassword
# Get a target datastore for current deployment
Select-DataStore -VMName $VMName -TagCategory $TagCategory
Select-DataStore -VMName $VMName -Cluster $Cluster -TagCategory $TagCategory

View File

@@ -31,7 +31,8 @@
"vm_name": "{{user `build_id`}}",
"ssh_username": "{{user `vm_username`}}",
"ssh_password": "{{user `vm_password`}}",
"CPUs": "10",
"CPUs": "5",
"cpu_cores": "5",
"RAM": "24576",
"NestedHV": "true",
"shutdown_timeout": "15m"

View File

@@ -31,7 +31,8 @@
"vm_name": "{{user `build_id`}}",
"ssh_username": "{{user `vm_username`}}",
"ssh_password": "{{user `vm_password`}}",
"CPUs": "10",
"CPUs": "5",
"cpu_cores": "5",
"RAM": "24576",
"NestedHV": "true",
"shutdown_timeout": "15m"

View File

@@ -31,7 +31,8 @@
"vm_name": "{{user `build_id`}}",
"ssh_username": "{{user `vm_username`}}",
"ssh_password": "{{user `vm_password`}}",
"CPUs": "10",
"CPUs": "5",
"cpu_cores": "5",
"RAM": "24576",
"NestedHV": "true",
"shutdown_timeout": "15m"