Earlier this year I put together a quick and nasty PowerShell Script that exports a vApp from vCloud Director using the OVFTool …for those that don’t know the OVFTool is a command line tool that has a powerful set of functions to import/export VMs and vApps from vCenter, ESXi and vCloud Director weather it be from a vCloud Air or a vCloud Air Network Provider.
You can Download and install the tool from here:
This week I needed to upload an Virtual Machine that was in OVA format and for those that have worked with vCloud Director you would know that the OVA format is not supported using the upload functionality in the current web interface. With that I thought it was a good time to round out the export using OVTTool post with an import using OVFTool post. Again, doing some research I found a bunch of posts relating to importing OVAs into vCloud Director and after working through the Admin Guide and some examples I was ready to build out a basic import command and start work on the PowerShell Script. On Windows you can run the tool from CMD but I would suggest using PowerShell/CLI as in the example below I go through building a variable.
What Info is Required:
- vCloud URL
- vCloud Username and Password
- Org Name
- vDC Name
- vApp Name
- Catalog Name
- Path to OVA
Command Line Example:
Below is a basic example of how to construct the vCloud String and use it as a variable to execute the tool.
1 2 3 4 5 6 7 8 9 |
# PowerCLI C:\Program Files\VMware\VMware OVF Tool> $vCloud ="vcloud://cloud2893:*******@mycloud.mel.zettagrid.com:443?org=Org_cloud2893&vdc=DC_1120761&vapp=TurnKey&catalog=Veeam PowerCLI C:\Program Files\VMware\VMware OVF Tool> .\ovftool C:\Users\anthony.spiteri\Downloads\turnkey.ova $vCloud Opening OVA source: C:\Users\anthony.spiteri\Downloads\turnkey.ova The manifest validates Opening vCloud target: vcloud://cloud2893@mycloud.mel.zettagrid.com:443/ Deploying to vCloud vApp: vcloud://cloud2893@mycloud.mel.zettagrid.com:443/ Transfer Completed Completed successfully |
PowerShell Script:
Again, I’ve taken it a step further to make it easier for people to import OVAs into vCloud Director and put together another, slightly improved PowerShell Script that I have coded in to work with my old companies vCloud Zones…though this can be easily modified to use any vCloud Air Network vCD endpoint.
The output of the script can be seen below:
It’s a very basic script that gathers all the required components that make up the vCloud Source Connection String and then exports the OVA into the vCD vApp. I’ve even done a little more PowerShell improvements around password security and added a little colour.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# # Adding the PowerCLI Modules Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue # Clear the Screen and Make a Menu clear write-host "" write-host " PLEASE ENTER IN THE ZETTAGRID ZONE..." -ForegroundColor Green write-host "" write-host " 1. PERTH ZONE" write-host " 2. SYDNEY ZONE" write-host " 3. MELBOURNE ZONE" write-host "" $answer = read-host "Please Make a Selection" # Set the Zone from the Menu Option Selected otherwise Exit - No Fancy While Loop if ($answer -eq 1) { $zone='mycloud.per.zettagrid.com' } elseif ($answer -eq 2) { $zone='mycloud.syd.zettagrid.com' } elseif ($answer -eq 3) { $zone='mycloud.mel.zettagrid.com' } else { write-host "You choose....poorly" exit } # Get the arguments needed for the OVFTOol to Connect and Download the vApp write-host "" $username=read-host "Enter in your vCloud Username" $password=read-host "Enter in your vCloud Password" -AsSecureString $vCD_ORG=read-host "Enter in your vCloud Organisation" $vDC=read-host "Enter in your vCloud Virtual Datacenter" $vApp=read-host "Enter in your vApp" $catalog=read-host "Enter in your vCD Catalog" Write-Host -NoNewline -ForegroundColor Red "Enter In the Full OVA Path" $OVA=read-host " :" write-host "" #Convert Secure Password $password_converted = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) # Build the vCloud Connection String $vCloud="vcloud://${username}:${password_converted}@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&vapp=${vApp}&catalog=${catalog}" #Build the vCloud Connection String to Hide Password $vCloud2="vcloud://${username}:*******@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&vapp=${vApp}&catalog=${catalog}" write-host "vCloud Connection String" $vCloud2 -ForegroundColor Yellow write-host"" # Set the OVFTool EXE and execute it with some arguments $app = '.\ovftool.exe' $arg1 = "$OVA" $arg2 = "$vCloud" & $app $arg1 $arg2 write-host "" read-host "Hit Enter to Exit" |
Save the code snippet as a .ps1 into the OFVTool Windows Folder and execute the script from the same location. If there are any errors with the inputs provided the OVFTool will fail with an error, but apart from that it’s a very simple straight forward way to import OVAs into any vCloud Director enabled endpoint.
Additional Reading:
http://www.virtuallyghetto.com/tag/ovftool
http://www.vmwarebits.com/content/import-and-export-virtual-machines-command-line-vmwares-ovf-tool