As per my last post ive been doing a bit more with vCAC and vCO due to job requirements, and getting my head around vCO has been a little challanging There is some great information out there but just not enough to understand how to put particular flows together specially with scripting.
I will go through a test flow I did to get my head around managing VMs based on their properties like changing or adding resources etc. Then plug that into vCAC 6. So here goes me trying to explain this.
The below flow is a flow i created to just play around with VM services, the idea of this flow is to take a virtual machine and either increase or decrease the vCPU allocation taking into account hot add features. This can be expanded to work with many VM related changes but I chose vCPU as its something more likely to be used and had some complexity to it.
2) Extract virtual machine information. This is an out of the box workflow you can search for the workflow or its located under vCenter -> virtual machine management -> others.
Below is the virtual binding which shows the inputs and outputs. For all the outputs I just used “create parameter/attribute in workflow” and accepted the defaults. The output on this flow all I needed was cpu count and could have set all the others to null.
3) First decision, This is a custom decision under generic. The inputs I need is virtual machine, vCPU number requested and the current CPU count of the virtual machine.
The code I use under the scripting tab is:
if (vcpuNum > cpuCount)
4) We will follow the path down if the vCPU request is larger than the current assigned vCPU. The next decision we need to make is, is the VM powered on. This again is using a custom decision object, The only input is the virtual machine with the below code in the scripting tab.
return virtualmachineName.runtime.powerState.value == "poweredOff";
5)If it comes back true and the vm is powered off we go straight into changeVMvCPU object this action is out of the box search for it and drag it onto the schema, the inputs are the virtual machine and the number of vCPUs the customer wants to set, and the output is a VC task which I left default as actionResult
7) Now we jump back up to the is the VM powered on and move onto the false branch meaning that the VM is powered on. So now we look to see if the VM supports hot add. The in parameter is the virtualmachine. The code under the scripting tab is as below:
8) If the result is True we would jump back up to step 5 as we can just add vCPUs while the machine is powered on.
9) If the result is false and hot add vCPU is not supported or enabled we need to power down the virtual machine. For this we use the shutdownVMandForce which is an out of the box action item which will attempt to shutdown the guest OS and if it has not shutdown it will force a power off in 10min by default this number can be changed with the timeout parameter. The inputs are virtual machine, Polling and timeout. as per all action items the script under scripting tab can not be edited and is self generated.
10) once the VM is shutdown we can change the vCPU allocation This is using the same action object as we used previously which is changeVMvCPU. the inputs are virtual machine, vCPU number to change too and the output is a task
13) Now we jump all the way back to the first decision branch and if the vCPU number is smaller than the current allocated vCPU we need to shutdown as we cant hot remove. So we use the ShutdownVMandForce action object again. The inputs are the same as the others mentioned.
15) the rest of the the objects are identical to step 9 and down again.
19) Now we want to add this into vCAC. I will not go through setting up Advanced services. This must be configured before continuing. We go to the Advance Services Tab -> blueprints and hit the green plus to add a new blueprint. Under the workflow tab we want to select the flow we just created.
Going through this helped me understand it a little bit more and get more or an understanding on what can be done with very little scripting.