Infrastructure as Code


Powers Combined: PowerCLI and OVFTool

07 Oct 2011

[caption id="attachment_127" align="alignleft" width="249" caption=""By your powers combined!!!""]a picture[/caption] This post will show how to combine the automation abilities of PowerCLI with OVFTool, but first: a bit of history... Open Virtualization Format (OVF) is designed to be a "universal" packaging system for virtual machines (and vApps, for that matter) across any virtualization platform. While adoption is still happening, it is already VERY useful for importing and exporting across your VMware environments. VMware has an excellent command-line OVF Tool called...uh...OVFTool. Arne has a great post about using OVFTool in your environment. The problem... While OVF is a great standard, there can be issues (encoding, unsupported metadata, OVF version mismatches) when importing and exporting to/from different platforms. We're going to talk specifically about the Hybrid Cloud use case: vSphere to vCloud Director. PowerCLI has a pretty good method for exporting vApps (Export-vApp), but not Virtual Machines. The simple and effective work-around is to simply create a new vApp, move/clone your VM to the vApp, export the vApp using the Export-vApp cmdlet. It works great for vSphere->;vSphere, but again...not for vSphere->;vCloud.
New-VApp test02 -Location cluster01
Move-VM delta -Destination test02
Export-VApp test02 -Destination C:\users\jake\desktop
Uploading the OVF produced by the code above results in the following error: a picture Easy Fix? Use OVFtool. It uploads perfectly to vCloud AND I can directly export the VM without the need for a vApp! "But wait a tick..." you say. "That's a command-line tool, not a PowerCLI cmdlet! I'll have to have to pass login credentials to OVFtool somehow." Exactly. We're going to use our PowerCLI session and a somewhat secret and cool feature in OVFTool to automate the export of our VM. So here's the code: Lines 26-29 are where the magic happens. Line 26: Get our Moref value for the VM. Line 27: Get our PowerCLI session data Line 28: Acquire a "clone ticket" for our session Line 29: Run OVFTool with our session ticket, moref value, and the destination parameter. Four lines of code is all it takes, just like Export-vApp. :D And the best part is uploading to vCloud works: a picture So, in summary: a picture You can combine the forces of PowerCLI and OVFTool to automate exporting of VMs, perfectly encoded for vCloud uploads. Stay tuned for part two, where we will use the upcoming vCloud PowerCLI snapin to fully automate VM migration to the public cloud.
comments powered by Disqus