Last week I had a requirement to look at how to allow customers to export VM’s and vApps from our vCloud Director Zones without using the UI. I’ve known about the OVFTool for a while but never really had the need to use it in anger…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 vCloud Air Network Provider.
You can Download and install the tool from here: https://my.vmware.com/group/vmware/details?downloadGroup=OVFTOOL410&productId=491
Upon doing some research I found a bunch of posts relating to importing OVFs into vCloud Director, vCloud Air or vCenter’s but not a lot around the export side of things…after working through the Admin Guide and some examples I was ready to build out a basic export 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
Note: The VM/vApp needs to be offline for the export process to take place.
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 |
# PowerCLI C:\Program Files\VMware\VMware OVF Tool> $vCloud ="vcloud://cloud2893:*****@mycloud.mel.zettagrid.com:443?org=Org_cloud2893&vdc=DC_1120761&vapp=PHOTON-01" PowerCLI C:\Program Files\VMware\VMware OVF Tool> .\ovftool.exe $vcloud c:\test.ovf Opening vCloud source: vcloud://cloud2893@mycloud.mel.zettagrid.com:443/ Waiting for task on server .................................done Opening OVF target: c:\test.ovf Writing OVF package: c:\test.ovf Progress: 69% |
PowerShell Script:
Wanting to take it a step further to make it easier for our customers to download their vApps I put together a quick and nasty PowerShell Script that can be used for all ZettaGrid Zones. The output of the script can be seen below:
It’s a very basic script that acts to break down the required components that make up the vCloud Source Connection String and then saves the OVF to the same folder where the OVFTool is installed.
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 |
# # 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..." 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" write-host "" $password=read-host "Enter in your vCloud Password" write-host "" $vCD_ORG=read-host "Enter in your vCloud Organisation" write-host "" $vDC=read-host "Enter in your vCloud Virtual Datacenter" write-host "" $vApp=read-host "Enter in your vApp" write-host "" # Build the vCloud Connection String $vCloud="vcloud://${username}:${password}@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&vapp=${vApp}" write-host "vCloud Connection String" $vCloud write-host"" # Set the OVFTool EXE and execute it with some arguments $app = '.\ovftool.exe' $arg1 = "$vCloud" $arg2 = 'c:\' & $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 export and download VMs and vApps from any vCloud Director enabled endpoint.
Behind the Scenes:
I thought it would be interesting to see what happens behind the scenes on the vCloud Director Cells when the OVFTool is brought in do it’s magic….When the OVFTool Authenticates against vCloud the following entries are seen in the cell.log of the active vCenter Proxy Cell.
1 2 3 4 5 6 7 8 9 10 11 12 |
2015-07-27 15:02:11,608 | DEBUG | pool-jetty-72 | ResourceEntityServiceImpl | enableDownload found active transfer session: eec039ea-9721-48b1-be0a-34b425a52e5e, returning last successful task: PHOTON-01(com.vmware.vcloud.entity.task:75c8d9c0-3add-4a47-8bee-d83723f1a57b) | requestId=59c3348a-be74-4fd1-996f-adc7dd15fd68 2015-07-27 15:02:11,611 | DEBUG | pool-jetty-72 | ResourceLinksFilterImpl | No operations for entity PHOTON-01(com.vmware.vcloud.entity.task:75c8d9c0-3add-4a47-8bee-d83723f1a57b) | requestId=59c3348a-be74-4fd1-996f-adc7dd15fd68 2015-07-27 15:07:27,898 | DEBUG | pool-jetty-60 | ResourceEntityServiceImpl | enableDownload found active transfer session: eec039ea-9721-48b1-be0a-34b425a52e5e, returning last successful task: PHOTON-01(com.vmware.vcloud.entity.task:75c8d9c0-3add-4a47-8bee-d83723f1a57b) | requestId=09f78c66-5505-4024-b603-881f7f351320 2015-07-27 15:07:27,901 | DEBUG | pool-jetty-60 | ResourceLinksFilterImpl | No operations for entity PHOTON-01(com.vmware.vcloud.entity.task:75c8d9c0-3add-4a47-8bee-d83723f1a57b) | requestId=09f78c66-5505-4024-b603-881f7f351320 2015-07-27 15:31:04,533 | DEBUG | pool-jetty-69 | JobString | Job object - Object : PHOTON-01(com.vmware.vcloud.entity.vapp:3d953319-c712-4347-898e-341c04bbd9e6) operation name: VDC_ENABLE_DOWNLOAD | requestId=fcf63816-d83d-4316-8de9-77873996d64d 2015-07-27 15:31:04,538 | DEBUG | pool-jetty-69 | CJob | Update last job : [PHOTON-01(com.vmware.vcloud.entity.vapp:3d953319-c712-4347-898e-341c04bbd9e6)], status=[1], [null] | requestId=fcf63816-d83d-4316-8de9-77873996d64d 2015-07-27 15:31:04,553 | DEBUG | pool-jetty-69 | BusyObjectServiceImpl | Trying to set entities [PHOTON-01(com.vmware.vcloud.entity.vapp:3d953319-c712-4347-898e-341c04bbd9e6), P-02(com.vmware.vcloud.entity.vm:4c803ea1-85ea-478d-8452-23d0ddc55529)] as busy for task ref VDC_ENABLE_DOWNLOAD(com.vmware.vcloud.entity.task:bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7) | requestId=fcf63816-d83d-4316-8de9-77873996d64d 2015-07-27 15:31:04,651 | DEBUG | backend-activity-pool-2109 | JobString | Job object - Object : PHOTON-01(com.vmware.vcloud.entity.vapp:3d953319-c712-4347-898e-341c04bbd9e6) operation name: VDC_ENABLE_DOWNLOAD | requestId=fcf63816-d83d-4316-8de9-77873996d64d vcd=5cf9a09b-55a9-49f5-aaf8-b1a9fec18e71,task=bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 activity=urn:uuid:bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 2015-07-27 15:31:04,653 | DEBUG | backend-activity-pool-2109 | CJob | Update last job : [PHOTON-01(com.vmware.vcloud.entity.vapp:3d953319-c712-4347-898e-341c04bbd9e6)], status=[1], [null] | requestId=fcf63816-d83d-4316-8de9-77873996d64d vcd=5cf9a09b-55a9-49f5-aaf8-b1a9fec18e71,task=bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 activity=urn:uuid:bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 2015-07-27 15:37:12,624 | DEBUG | backend-activity-pool-2109 | JobString | Job object - Object : PHOTON-01(com.vmware.vcloud.entity.vapp:3d953319-c712-4347-898e-341c04bbd9e6) operation name: VDC_ENABLE_DOWNLOAD | requestId=fcf63816-d83d-4316-8de9-77873996d64d vcd=5cf9a09b-55a9-49f5-aaf8-b1a9fec18e71,task=bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 activity=urn:uuid:bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 2015-07-27 15:37:12,628 | DEBUG | backend-activity-pool-2109 | CJob | No last pending job : [PHOTON-01(com.vmware.vcloud.entity.vapp:3d953319-c712-4347-898e-341c04bbd9e6)], status=[2] | requestId=fcf63816-d83d-4316-8de9-77873996d64d vcd=5cf9a09b-55a9-49f5-aaf8-b1a9fec18e71,task=bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 activity=urn:uuid:bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 2015-07-27 15:37:12,629 | DEBUG | backend-activity-pool-2109 | CJob | Update last job : [PHOTON-01(com.vmware.vcloud.entity.vapp:3d953319-c712-4347-898e-341c04bbd9e6)], status=[2], [7/27/15 3:37 PM] | requestId=fcf63816-d83d-4316-8de9-77873996d64d vcd=5cf9a09b-55a9-49f5-aaf8-b1a9fec18e71,task=bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 activity=urn:uuid:bb9cdc8d-0901-4a45-b92d-cc9b032ff8e7 |
When the Enable Download task is executed the cell begins to copy the vApp to the Cell Transfer directory which is the staging area vCloud Director uses for all VM/vApp related copy/move/import/export functions…During this copy the OVFTool displays the Waiting for Server Task status. If you where able to view the contents of the director created in the transfer location you would see the vmdk growing in size as shown below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@vcd-002 6d3eb949-facc-47cf-8e51-a1466fb587bc]# ls -la total 467760 drwx------ 2 admin admin 8192 Jul 23 16:17 . drwxr-x--- 10 admin admin 32768 Jul 23 16:16 .. -rw------- 1 admin admin 478940520 Jul 23 16:19 vm-be12dcad-a228-4739-b9fc-0200b47b7e6c-disk-0.vmdk [root@vcd-002 6d3eb949-facc-47cf-8e51-a1466fb587bc]# ls -la total 467760 drwx------ 2 admin admin 8192 Jul 23 16:17 . drwxr-x--- 10 admin admin 32768 Jul 23 16:16 .. -rw------- 1 admin admin 478940520 Jul 23 16:19 vm-be12dcad-a228-4739-b9fc-0200b47b7e6c-disk-0.vmdk [root@vcd-002 6d3eb949-facc-47cf-8e51-a1466fb587bc]# ls -la total 480288 drwx------ 2 admin admin 8192 Jul 23 16:17 . drwxr-x--- 10 admin admin 32768 Jul 23 16:16 .. -rw------- 1 admin admin 491766890 Jul 23 16:20 vm-be12dcad-a228-4739-b9fc-0200b47b7e6c-disk-0.vmdk |
If you check into the vCloud Director UI and browse to the vApp you will see that the vApp is Busy with a status of Enabling Download.
Once the copy has finished the OFVTool starts the download and once that is complete (or there is an error) the files in the vCloud Director Transfer area are deleted. In my testing I haven’t witnessed any continuation or pick off where it last failed mechanism.
Feel free to take the script and do with it what you will…it can be pretty easily modified to connect to any vCloud Air Network Partner or vCloud Air its self.
Additional Reading:
http://www.virtuallyghetto.com/tag/ovftool
http://www.vmwarebits.com/content/import-and-export-virtual-machines-command-line-vmwares-ovf-tool