Deploying the vCloud Director OVAs from the Command Line
I've recently had the opportunity to do some work with a vCloud Director deployment, which has been a lot of fun! We've been working on a lab environment at the moment, and we want the ability to quickly redeploy the lab now and we want to be able to reliably deploy a similar configuration into production later. So, to that end, I spent a bit of time figuring out how to deploy the VCD Appliance via the CLI, and I'm ready to share my results!
I started by spending some quality time with the Deploying vCloud Director with the OVF Tool Guide to get an idea about what options I was going to need. There's a lot of options in there, and there's a moderate amount of variety to their syntax! After looking over the various options, it looks like we can basically break down the option syntax into 3 parts: a Paramter, a Name, and a Value. Various options use these parts in different combinations. Let's look at these lines from their example:
--allowAllExtraConfig
--diskMode=thin --prop:"vami.ip0.VMware_vCloud_Director"="10.0.0.142" --prop:"vami.ip1.VMware_vCloud_Director"="172.18.41.24"
The options all start with a "--" and then a parameter value, so these would be a --allowAllExtraConfig option, a --diskmode option, and two --prop options. The --alowAllExtraConfig option is a simple switch, in that it's either there or it's not and it needs no extra settings. The --diskmode option just needs a value (after an = sign), but the --prop options have a bit more going on! They specify a named setting and then its value, and we can pass a whole bunch of --prop settings via ovftool.
So, that brings us back to breaking these options down into three parts. The Parameter is the bit that immediately follows the -- up to either the : or the =. If there's a :, then this option has a Name as well, which goes up to the =. The Value is anything that follows the =. So, that first line only has a Parameter. The second line has a Parameter and a Value. The third and fourth lines have all three, Parameter, Name, and Value.
As you can see in the guide, there are a ton of settings that can be specified for a VCD Appliance deployment. To make this easier to manage, I set myself up with a quick CSV to store the settings for each VCD instance. You probably see where I'm going with this, but my CSV has three columns: Param, Name, and Value. I then populated each column appropriately for each setting that I need to specify.
Once I had my CSV, I needed a way to parse it into an ovftool deployment command. Naturally, I fell back on PowerShell as a quick and easy way to do that! So, I put together this simple script to generate the ovftool command for me, based on the options specified in the CSV:
The bulk of that script just parses the CSV and is moderately self-explanation, but the last line has some important stuff that I want to cover. When using OVFTool to deploy systems, the destination syntax was a bit confusing to me. The long and short of it is that, if your destination is an ESXi host in a cluster, you'll need to format it as you see in the $destination variable above. It's not overly complicated, but you just need to remember that you're referring to the inventory objects in a API-like fashion rather than a GUI-like fashion.
When all that's done, you can take a look at your $ovfString to find see all of the parameters that it takes to deploy the configured VCD appliance! Once you're happy with the way the string looks, you can execute it with:
Invoke-expression $ovfString
I started by spending some quality time with the Deploying vCloud Director with the OVF Tool Guide to get an idea about what options I was going to need. There's a lot of options in there, and there's a moderate amount of variety to their syntax! After looking over the various options, it looks like we can basically break down the option syntax into 3 parts: a Paramter, a Name, and a Value. Various options use these parts in different combinations. Let's look at these lines from their example:
--allowAllExtraConfig
--diskMode=thin --prop:"vami.ip0.VMware_vCloud_Director"="10.0.0.142" --prop:"vami.ip1.VMware_vCloud_Director"="172.18.41.24"
The options all start with a "--" and then a parameter value, so these would be a --allowAllExtraConfig option, a --diskmode option, and two --prop options. The --alowAllExtraConfig option is a simple switch, in that it's either there or it's not and it needs no extra settings. The --diskmode option just needs a value (after an = sign), but the --prop options have a bit more going on! They specify a named setting and then its value, and we can pass a whole bunch of --prop settings via ovftool.
So, that brings us back to breaking these options down into three parts. The Parameter is the bit that immediately follows the -- up to either the : or the =. If there's a :, then this option has a Name as well, which goes up to the =. The Value is anything that follows the =. So, that first line only has a Parameter. The second line has a Parameter and a Value. The third and fourth lines have all three, Parameter, Name, and Value.
As you can see in the guide, there are a ton of settings that can be specified for a VCD Appliance deployment. To make this easier to manage, I set myself up with a quick CSV to store the settings for each VCD instance. You probably see where I'm going with this, but my CSV has three columns: Param, Name, and Value. I then populated each column appropriately for each setting that I need to specify.
Once I had my CSV, I needed a way to parse it into an ovftool deployment command. Naturally, I fell back on PowerShell as a quick and easy way to do that! So, I put together this simple script to generate the ovftool command for me, based on the options specified in the CSV:
$answers =
import-csv C:\Temp\Answers.csv
$ovaPath = "E:\vmware\VMware_vCloud_Director-10.0.0.4649-15450333_OVF10.ova"
$username = "administrator@vsphere.local"
$password = [uri]::EscapeDataString("my password") #URL encode any special characters
$destination = "<myVCenterServer>/<myDatacenterName>/host/<myCluster>\<myESXiHost>"
$ovfString =
"ovftool"
foreach ($answer in
$answers){
$thisParam
= " --" + $answer.param
if
($answer.name){
$thisParam
+= ":""" + $answer.name + """"
}
if
($answer.value){
$thisParam
+= "=""" + $answer.value + """"
}
$ovfString
+= $thisParam
}
$ovfString += " $ovaPath vi://$username:$password@$destination"
The bulk of that script just parses the CSV and is moderately self-explanation, but the last line has some important stuff that I want to cover. When using OVFTool to deploy systems, the destination syntax was a bit confusing to me. The long and short of it is that, if your destination is an ESXi host in a cluster, you'll need to format it as you see in the $destination variable above. It's not overly complicated, but you just need to remember that you're referring to the inventory objects in a API-like fashion rather than a GUI-like fashion.
When all that's done, you can take a look at your $ovfString to find see all of the parameters that it takes to deploy the configured VCD appliance! Once you're happy with the way the string looks, you can execute it with:
Invoke-expression $ovfString
Comments
Post a Comment
Sorry guys, I've been getting a lot of spam recently, so I've had to turn on comment moderation. I'll do my best to moderate them swiftly after they're submitted,