Ever since the vSphere 5 upgrade, cold booting my home lab (which I generally do because I’m not going to pay to leave it running all the time plus it is noisy and it heats up my office) requires re-connecting my ESXi hosts.
I was tempted to write a Perl script or use PowerCLI but given my focus on vCO and with the new the vSphere 5 plugin, I thought, “I’ll write a workflow!”
I easily found the delivered workflows for “Disconnect host” and “Reconnect host”.
Trying those one at a time on one of my ESXi hosts and they worked perfectly. Great. These are my first building blocks.
Next I thought, “Ok, now I will sequence these two flows.” No biggie. I created a new workflow called “Disconnect Reconnect ESX Host”. In the schema, I dragged a workflow item, select “Disconnect host” and repeated for “Reconnect host”. Add the “End Workflow” item then link together.
Next I clicked “Validate” and took the quick fix option to create an input attribute for “ESX host” which both embedded workflows can now share.
I tried the flow on one of my ESXi hosts. It worked great. Cool.
So then I said, “Now I need to loop through all my ESX hosts in my lab cluster.” Hmm, I remember Burke Azbill has shown me how to do this multiple times. J And after a quick search I found it (again): http://www.vcoteam.info/learn-vco/creating-workflow-loops.html
“Well, maybe I can just use what is there in vCO and not write something. (I am so lazy.) Hey, what about that Batch thing. Yeah, baby.”
Since I had just added a new workflow that takes a single ESX host as input which qualifies to run from the batch workflow, I ran the “Fill batch configuration element”. Now I will be able to reference my “Disconnect Reconnect ESX host” workflow.
Now I want to verify that I can run my new workflow from the “Run a workflow on a selection of objects”. I chose ESX host as the object type, selected the Action “GetallHostSystemsofCluster”, using my cluster for the input and then chose my “Disconnect Reconnect ESX Host” workflow.
Outstanding, it cycled through my ESXi hosts disconnecting and then reconnecting each one very quickly.
Lines of code written: ZERO.
But you know I am really, really lazy. How can I run this batch workflow without having to go through and configure all the inputs each time? It was time for another workflow. I remember Christophe Decanini telling me this could be done.
Ok time for one more workflow to setup and call the batch workflow the way I want for this job. I called it “Disconnect Reconnect All ESX hosts of Cluster”. Add one workflow item which is the “Run a workflow on a selection of objects”, add the “End Workflow” item and link it together.
Next I used a trick that Christophe Decanini taught me. “Synchronize presentation” shows when you right-click on the embedded workflow.
This adds all the attributes of the embedded workflow as inputs to the current workflow. While this is pretty cool, remember that I want to run this without any inputs at all. Ok, there is a quick fix for this. Move all the inputs as attributes. Click on the top input, then Shift-Click on the bottom input. When all the inputs are selected, right-click and choose “Move as attribute”.
Now the visual binding looks like this:
This is a complex workflow but I only need a few of the parameters.
Now all that is left is to set the defaults that I want for my lab to run this specific job. This was actually pretty easy by looking back at the successful run of the batch flow previously and observing the variables that were actually used and their values.
The objectType is a string and the value needs to be “Host”. Not exactly intuitive but there it was in the variables from my previous run. I used the same Action “GetallHostSystemsofCluster” as before and selected my cluster for the input to the Action and finally chose my “Disconnect Reconnect ESX Host” workflow.
This is good enough for me but if I am going to share this with others, I don’t want the workflow referring to the cluster in my lab. So the one last improvement is to use a Configuration instead to reference the cluster to use. This way you can set the Configuration to reference your cluster. Create a new folder and element for the Configuration.
Then edit the Configuration and add an element setting the Type to VC:ClusterComputeResource. I called it “MyCluster” and set the default value to point to “Cluster1” in my lab. Yes, this is quite the outstanding name, don’t you think?
Finally, I went back to the workflow and updated the “cluster” attribute default value to reference the configuration element. Click the little symbol in the Configuration column.
Now pick the “MyCluster” Configuration element.
Finally, I created of Package of my work and saved it out for safe keeping.
Central Region US Principal Systems Engineer
Solution Specialist vCloud/Chargeback
Bill has been at VMware a relatively long time (8+ years) and has worked with various automation tools over 25+ years in IT.