pages

Friday, September 27, 2013

vCAC - how to change the VM network after provisioning

Sometimes we are asked for some special test cases in pilot scenarios. On of my colleagues asked me how we can change a virtual machine network after the virtual machine is provisioned in vCAC. The reason for this was a provisioning environment in which the virtual machine is deployed in a special network and attached to the production afterwards.

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!




3 comments:

  1. Hi,
    you should mention that scripts that are imported into vcac MUST be UTF-8 else they wont work.

    ReplyDelete
  2. 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.
    Regards, Ronald

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete