We have 30-60 VMs running on a cluster, where the Interfaces/Portgroups need to be reconfigured frequently, as scenarios change.
I tried several solutions, of which none was very satisfying.
My first attempt was in ansible, since we deploy everything else with it too. Using the vmware_guest module it takes about 10-15 minutes to reconfigure every interface. Even after some optimizations with a loop and async, the time needed is in the same area. Ansible seems to be opening one connection per task, and this is pretty slow.
My second attempt was to use the VMware PowerCLI. I didn't find a good solution to set all interfaces at the same time for each host. So in the end it was even slower than with ansible.
Does anyone have experiences with this?
Welcome to the Community,
I've moved your question from VMware vCenter™ to VMware PowerCLI.
If you are looking for a PowerCLI solution, your first try should be to google for PowerCLI LucD, and your question.
André
What exactly are you trying to change?
The portgroups to which the vNICs of the VMs are connected?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have a configuration file something like this
[
{"vm_name": "test-tacrouter-1", "interfaces": ["VM Network", "EmuVlan2910", "EmuVlan2010", "EmuVlan2", "EmuVlan2", "EmuVlan2"]},
{"vm_name": "test-tacrouter-2", "interfaces": ["VM Network", "EmuVlan2911", "EmuVlan2011", "EmuVlan2", "EmuVlan2", "EmuVlan2"]},
...
]
But this is however not set in stone.
Yes, the portgroups to which the vNICs of the VMs are connected have to be changed.
Each VM has 6 Network Adapters, where each portgroup has to be changed.
I have tried something along this
Get-VM VM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName xxx
But this obviously sets every interface to the same portgroup.
Your configuration file is a JSON files I assume?
How do I read that file?
I see the VM displayname and then a number of interfaces. Are those the vNIC attached to the VM on that line?
And how shall we determine what the new portgroup shall be?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, it's a json configuration file for now because I thought this would simplify it. Originally we had a yml file.
Yes, this is the order of the Network Intrerfaces. This is the order as seen in vSphere. And also the order of Get-NetworkAdapter.
If you are interested in how I did the "slow approach" here it is:
$interface_mapping = Get-Content -Raw -Path "esxi_interface_mapping.json" | ConvertFrom-Json
Connect-VIServer -menu
$interface_mapping | ForEach-Object {
$vm_name = $_.vm_name
$interfaces = $_.interfaces
Write-Host -Fore:Yellow "Processing " $vm_name
$network_adapters = Get-VM $vm_name | Get-NetworkAdapter
for ($i=0; $i -lt $network_adapters.length; $i++) {
Set-NetworkAdapter $network_adapters[$i] -NetworkName $interfaces[$i] -Confirm:$false | out-null
}
}
EDIT: The file you see, is the new portgroup configuration.
That looks like the normal way to do this.
If this is abnormally slow, there must be something else going on.
How many VMs are you targetting?
How long does it take to change the portgroup(s) on 1 VM?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference