So at first you have to set the "ExternalWFStubs.MachineProvisioned" property at the virtual machine blueprint.
As an additional input i created a custom property called "VirtualMachine.NewNetwork" which holds the name of the new network. I created a custom property with a dropdown list (Values: VM Network, DVPortGroup) to let the user select the network.
Next step was the creation of a powershell script (ChangeNetwork.ps1):
#Variable detection
$OldNetwork = $Properties["VirtualMachine.Network0.Name"]
$NewNetwork = $Properties["VirtualMachine.NewNetwork"]
$Hostname = $Properties["VirtualMachineName"]
#Check for the variables
$OldNetwork >> C:\test.txt
$NewNetwork >> C:\test.txt
$Hostname >> C:\test.txt
#Calls the powershell actions
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer YourVcenterServer -User YourUser -Password YourPass
Get-VM -Name $Hostname | Get-NetworkAdapter | Where {$_.NetworkName -eq $OldNetwork }|Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false
I uploaded the powershell script using the CloudUtil command line:
CloudUtil File-Import -n ChangeNetwork -f ChangeNetwork.ps1
Now i created a new workflow in the Design Center for the MachineProvisioned stub like Zack described here: Calling Powershell/PowerCLI Scripts from a vCAC workflow.
Please note that you need to initialize the Dictionary array like described in the blog post. After sending the workflow to the vCAC server the stub should call the Powershell script and change the network adapter from "DVPortGroup" to "VM Network".
After the deployment (my template has DVPortGroup as network when deployed)
the network should change with a reconfigure task.
Have fun with this!
Hi,
ReplyDeleteyou should mention that scripts that are imported into vcac MUST be UTF-8 else they wont work.
Hi Christian, a suggestion for your script. Instead of using explicit user/pass combinations you could use the credentials from vCAC. You just have to pass the MgmtContext to the script and then resolve the endpoint and its associated credentials as described here: http://d-fens.ch/2013/11/02/decrypting-passwords-in-vcac-connectioncredentials/. Btw the vCenter itself can certainly be resolved like this, too.
ReplyDeleteRegards, Ronald
This comment has been removed by the author.
ReplyDelete