|
| 1 | +Function Get-VSANFSResources { |
| 2 | +<# |
| 3 | + .NOTES |
| 4 | + =========================================================================== |
| 5 | + Created by: William Lam |
| 6 | + Organization: VMware |
| 7 | + Blog: www.virtuallyghetto.com |
| 8 | + Twitter: @lamw |
| 9 | + =========================================================================== |
| 10 | + .DESCRIPTION |
| 11 | + This function demonstrates the use of vSAN Management API to retrieve |
| 12 | + the resources allocated to both the vSAN File Server backend and vSAN File Service VMs |
| 13 | + .PARAMETER Cluster |
| 14 | + The name of a vSAN Cluster |
| 15 | + .EXAMPLE |
| 16 | + Get-VSANFSResources -Cluster OCTO-Cluster |
| 17 | +#> |
| 18 | + param( |
| 19 | + [Parameter(Mandatory=$true)][String]$Cluster |
| 20 | + ) |
| 21 | + |
| 22 | + # Scope query within vSAN/vSphere Cluster |
| 23 | + $clusterView = Get-Cluster -Name $Cluster -ErrorAction SilentlyContinue |
| 24 | + if($clusterView) { |
| 25 | + $clusterMoref = $clusterView.ExtensionData.MoRef |
| 26 | + } else { |
| 27 | + Write-Host -ForegroundColor Red "Unable to find vSAN Cluster $cluster ..." |
| 28 | + break |
| 29 | + } |
| 30 | + |
| 31 | + $vsanConfigSystem = Get-VsanView -Id VsanVcClusterConfigSystem-vsan-cluster-config-system |
| 32 | + $results = $vsanConfigSystem.VsanClusterGetConfig($clusterMoref) |
| 33 | + $results.FileServiceConfig | select Enabled, FileServerMemoryMB, FileServerCPUMhz, FsvmMemoryMB, FsvmCPU |
| 34 | +} |
| 35 | + |
| 36 | +Function Set-VSANFSResources { |
| 37 | +<# |
| 38 | + .NOTES |
| 39 | + =========================================================================== |
| 40 | + Created by: William Lam |
| 41 | + Organization: VMware |
| 42 | + Blog: www.virtuallyghetto.com |
| 43 | + Twitter: @lamw |
| 44 | + =========================================================================== |
| 45 | + .DESCRIPTION |
| 46 | + This function demonstrates the use of vSAN Management API to enable vSAN File Services |
| 47 | + with custom resource (CPU/MEM) settings for both the vSAN File Server backend and vSAN File Service VMs |
| 48 | + .PARAMETER Cluster |
| 49 | + The name of a vSAN Cluster |
| 50 | + .PARAMETER fsReservedCPU |
| 51 | + Reserved CPU (Mhz) for vSAN File Server (default 0) |
| 52 | + .PARAMETER fsReservedMem |
| 53 | + Reserved Memory (MB) for vSAN File Server (default 960) |
| 54 | + .PARAMETER fsVMReservedCPU |
| 55 | + Reserved CPU Cores for vSAN File Services VM (default 2) |
| 56 | + .PARAMETER fsVMReservedMem |
| 57 | + Reserved Memory (MB) for vSAN File Services VM (default 2048) |
| 58 | + .EXAMPLE |
| 59 | + Set-VSANFSResources -Cluster OCTO-Cluster -Network VM51-DPortGroup -fsVMReservedMem 8096 |
| 60 | + .EXAMPLE |
| 61 | + Set-VSANFSResources -Cluster OCTO-Cluster -Network VM51-DPortGroup -fsReservedCPU 100 -fsReservedMem 1024 -fsVMReservedCPU 4 -fsVMReservedMem 10240 |
| 62 | +#> |
| 63 | + param( |
| 64 | + [Parameter(Mandatory=$true)][String]$Cluster, |
| 65 | + [Parameter(Mandatory=$true)][String]$Network, |
| 66 | + [Parameter(Mandatory=$false)][String]$fsReservedCPU, |
| 67 | + [Parameter(Mandatory=$false)][String]$fsReservedMem, |
| 68 | + [Parameter(Mandatory=$false)][String]$fsVMReservedCPU, |
| 69 | + [Parameter(Mandatory=$false)][String]$fsVMReservedMem |
| 70 | + ) |
| 71 | + |
| 72 | + # Scope query within vSAN/vSphere Cluster |
| 73 | + $clusterView = Get-Cluster -Name $Cluster -ErrorAction SilentlyContinue |
| 74 | + if($clusterView) { |
| 75 | + $clusterMoref = $clusterView.ExtensionData.MoRef |
| 76 | + } else { |
| 77 | + Write-Host -ForegroundColor Red "Unable to find vSAN Cluster $cluster ..." |
| 78 | + break |
| 79 | + } |
| 80 | + |
| 81 | + $networkView = Get-VirtualNetwork -Name $Network -ErrorAction SilentlyContinue |
| 82 | + if($networkView) { |
| 83 | + $networkMoref = $networkView.ExtensionData.MoRef |
| 84 | + } else { |
| 85 | + Write-Host -ForegroundColor Red "Unable to find vSphere Network $Network ..." |
| 86 | + break |
| 87 | + } |
| 88 | + |
| 89 | + # https://vdc-download.vmware.com/vmwb-repository/dcr-public/9ab58fbf-b389-4e15-bfd4-a915910be724/7872dcb2-3287-40e1-ba00-71071d0e19ff/vim.vsan.FileServiceConfig.html |
| 90 | + $vsanFSSpec = New-Object VMware.Vsan.Views.VsanFileServiceConfig |
| 91 | + $vsanFSSpec.Enabled = $true |
| 92 | + $vsanFSSpec.Network = $networkMoref |
| 93 | + |
| 94 | + if($fsReservedCPU) { |
| 95 | + $vsanFSSpec.fileServerCPUMhz = $fsReservedCPU |
| 96 | + } |
| 97 | + |
| 98 | + if($fsReservedMem) { |
| 99 | + $vsanFSSpec.fileServerMemoryMB = $fsReservedMem |
| 100 | + } |
| 101 | + |
| 102 | + if($fsVMReservedCPU) { |
| 103 | + $vsanFSSpec.fsvmCPU = $fsVMReservedCPU |
| 104 | + } |
| 105 | + |
| 106 | + if($fsVMReservedMem) { |
| 107 | + $vsanFSSpec.fsvmMemoryMB = $fsVMReservedMem |
| 108 | + } |
| 109 | + |
| 110 | + $spec = New-Object VMware.Vsan.Views.VimVsanReconfigSpec |
| 111 | + $spec.modify = $true |
| 112 | + $spec.FileServiceConfig = $vsanFSSpec |
| 113 | + |
| 114 | + Write-Host -ForegroundColor cyan "Enabling and applying custom resource settings to vSAN File Services ... " |
| 115 | + $vsanConfigSystem = Get-VsanView -Id VsanVcClusterConfigSystem-vsan-cluster-config-system |
| 116 | + $task = $vsanConfigSystem.VsanClusterReconfig($clusterMoref,$spec) |
| 117 | + $task1 = Get-Task -Id ("Task-$($task.value)") |
| 118 | + $task1 | Wait-Task |
| 119 | +} |
0 commit comments