Table of Content
In Part1 we start with the SQL DB Plugin and create the required database for our need.
In Part2 we start with the development of our Workflow. We will start with a few elements.
In Part3 we finish the collection of the VM information.
In Part4 we insert our data into the database and test our created workflow
In Part5 we create our webview to get a look on our Data in the SQL Database
In Part6 we will make our Workflow smarter to update the DB with actual VM information
In Part7 problems with vAPP located virtual machines are fixed
Part3
Here we go with the Part3 of our LittleCMDB……
To get forward with out CMDB with need more Elements. We insert the following elements and workflows into the Schema.
-
A scripting element
-
a decision
-
the Workflow element “Extract virtual machine information”
-
a second scripting element
-
a third scripting element
-
a second decision
We can place the elements on the left side of our Schema.
After placement it have to look like this screen shot
Image may be NSFW.
Clik here to view.
Next we have to insert values in the different elements. Lets start with the first Scriptable task.
We set the name of the element t o”Countdown VMs” and insert a good description (we want to countdown the “AllVMs” Array…). Next we need the in and output’s for the element. Following variables are required:
Local Parameter | Variable Name | Module | Direction | Type |
NumberVMs | NumberVMs | Countdown Vms | in | Number |
allVMs | allVMs | Countdown Vms | in | Array/VC:VirtualMachine |
SQLVID | SQLVID | Countdown Vms | in | String |
NumberVMs | NumberVMs | Countdown Vms | out | Number |
VmtoGet | VmtoGet | Countdown Vms | out | VC:VirtualMachine |
SkipVM | SkipVM | Countdown Vms | out | Boolean |
VMName | VMName | Countdown Vms | out | String |
V_ID | V_ID | Countdown Vms | out | String |
After we have created the values we start with our scripting. In our Scripting, we have to check different states of the connected virtual machines. Some states could lead to errors in our scripting, so we have to avoid them and skip the VM. In the Scripting Tab we have to insert this commands.
// set Variable SkipVM to false SkipVM == false; // We take the last VM in our Array VmtoGet = allVMs.pop(); // some virtual machines are in the API but not connected. We must exclude them, otherwise we become errors if (VmtoGet.summary.runtime.connectionState == VcVirtualMachineConnectionState.orphaned) { SkipVM = true; System.debug("OrphanedVM: " + VmtoGet); } if (VmtoGet.summary.config.template == true) { SkipVM = true; System.debug("Template: " + VmtoGet); } if (VmtoGet.summary.runtime.connectionState == VcVirtualMachineConnectionState.disconnected) { SkipVM = true; System.debug("VM Disconnected: " + VmtoGet); } if (VmtoGet.summary.runtime.connectionState == VcVirtualMachineConnectionState.inaccessible) { SkipVM = true; System.debug("VM Inaccessible: " + VmtoGet); } // Get the virtual machine name VMName = VmtoGet.summary.config.name; // create a unique UUID for the database (It is also possible to do so in the SQL DB....here I use the JavaScript ) V_ID = System.nextUUID(); // decrease the Variable NumberVMs NumberVMs = NumberVMs -1;
Next we go to the decision. Here we have to insert a speaking name and a description. I use “SkipVM” as name. After that, we have to fill in the Decision condition.
Image may be NSFW.
Clik here to view.
For that, we click on “Not Set (NULL)” and choose the Skip VM variable
Image may be NSFW.
Clik here to view.
Then we have to set the parameter to “is false”
Image may be NSFW.
Clik here to view.
Then we are already finished with this module.
Now we have to deal with the “Extract virtual machine Information” Workflow. This workflow has one Input and a lot of Output variables.
Local Parameter | Variable Name | Module | Direction | Type |
vm | VmtoGet | Extract virtual Machine | in | VC:VirtualMachine |
folderName | folderName | Extract virtual Machine | out | String |
folderID | folderID | Extract virtual Machine | out | String |
runningHostName | runningHostName | Extract virtual Machine | out | String |
runningHostID | runningHostID | Extract virtual Machine | out | String |
resourcePoolName | resourcePoolName | Extract virtual Machine | out | String |
rescourcePoolID | rescourcePoolID | Extract virtual Machine | out | String |
clusterName | clusterName | Extract virtual Machine | out | String |
clusterID | clusterID | Extract virtual Machine | out | String |
computeResourceId | computeResourceId | Extract virtual Machine | out | String |
datastoreName | datastoreName | Extract virtual Machine | out | Array/string |
datastoreId | datastoreId | Extract virtual Machine | out | Array/string |
diskSize | diskSize | Extract virtual Machine | out | Array/number |
cpuCount | cpuCount | Extract virtual Machine | out | number |
memoryMB | memoryMB | Extract virtual Machine | out | number |
ipAddresses | ipAddresses | Extract virtual Machine | out | Array/string |
networks | networks | Extract virtual Machine | out | Array/string |
folder | folder | Extract virtual Machine | out | VC:VmFolder |
host | host | Extract virtual Machine | out | VC:HostSystem |
resourcePool | resourcePool | Extract virtual Machine | out | VC:ResourcePool |
cluster | cluster | Extract virtual Machine | out | VC:ClusterComputeResource |
computeResource | computeResource | Extract virtual Machine | out | VC:ComputeResource |
datastores | datastores | Extract virtual Machine | out | Array/VC:Datastore |
The output Variables must all be attributes….when your are finished your “Visual Bindings” have a whole bunch of connections…
Image may be NSFW.
Clik here to view.
That’s all for the module. Know we have to deal with the second scripting element. When you have a deeper look at the “Extract virtual machine Information” module, you will see that some information about virtual machines are missing. One of these information is the virtual machine UUID. This UUID is always unique for a VM. The name of the VM could be changed but the UUID with not be changed. So to be able to identify a VM we need this UUID. In this scripting element, we want extract this information.
First we give a name and a description for the module. I use the name “GetVMUUID”. Then we need one Input parameter and a output parameter.
Local Parameter | Variable Name | Module | Direction | Type |
VmtoGet | VmtoGet | GetVMUUID | in | VC:VirtualMachine |
VMUUID | VMUUID | GetVMUUID | out | String |
In the scripting tab we insert the following:
VMUUID = VmtoGet.summary.config.uuid;
With this, we get the UUID of the virtual Machine.
Now it is time to configure the third scriptable task. In this module, we will check if the VM is already in our DB. For that, we do some custom SQL scripting. We will not use a “predefined” SQL Statement, which we created earlier because we only need two columns for our decision.
First, lets name the module and insert a description. I name the module “GetVMfromDB”
Let’s see what Input and Output parameter we need:
Local Parameter | Variable Name | Module | Direction | Type |
isUnique | isUnique | GetVMfromDB | in | Boolean (true) |
VMUUID | VMUUID | GetVMfromDB | in | String |
V_ID | V_ID | GetVMfromDB | in | String |
VMInfo_Table | VMInfo | GetVMfromDB | in | SQL:Table |
VMInfoRead_Result | VMInfoReadResult | GetVMfromDB | in | SQL:ActiveRecord |
VMName | VMName | GetVMfromDB | in | String |
VminDB | VminDB | GetVMfromDB | out | Boolean |
The VMInfo_Table must be chosen. You can pick the right Table during the configuration of the Variable
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
The VMInfoRead_result is reading data out of the database and to work with this data.
Image may be NSFW.
Clik here to view.
After we have created all variables, we can start with the Scripting.
The script we need has to read the VM information out of the db (if the VM exist in the database). If the VM exist it generates a log entry and sets the Variables “VMinDB” to true. Otherwise to false. We use the Variable “VMinDB” for the control of our Workflow.
// We check the DB for the VM. The check is based on VMName and UUID var columns = { UUID : VMUUID, VMName : VMName, }; VMInfoRead_result = VMInfo_Table.readRecords(columns); // Some local variables here. We have to split the DB Information var SplitArraytoString = VMInfoRead_result.toString(); var UUIDString = SplitArraytoString.search(VMUUID); var VMNameString = SplitArraytoString.search(VMName); if ((UUIDString >= 0) && (VMNameString >=0)) { VMinDB = true; System.log("VM: " + VMName + " already in DB.") } else { VMinDB = false; System.log("VM: " + VMName + " not in DB.") };
At last we have to deal with the next Decision. I use the Name “VM in DB”for that decision. Here we check if the VM is already in the DB.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
After we have chosen the Variable, we set the Boolean Value to “false”
Image may be NSFW.
Clik here to view.
After we have finished all the Elements, we are starting to connect these. We start with the “Countdown VMs”. We need a connection from “NumberofVMs” to there. And from “Countdown VMs” we will make a connection to “SkipVM”
Image may be NSFW.
Clik here to view.
Next we need a connection from “SkipVM” to “Extract virtual machine Information” and a “Error Connection to “NumberofVMs”.
Image may be NSFW.
Clik here to view.
All Other Elements will be connected to the following element.
Image may be NSFW.
Clik here to view.
From “VM in DB” we connect the error connection to “NumberofVMs”. When the VM is already in our Database, we go further with the next virtual machine.
Image may be NSFW.
Clik here to view.
At least for this part, we create a End under “NumberofVMs”. This End will be reached, If the number of VMs is “0”.
That’s all for Part3. In Part4 we will start to insert the Data into the SQL Server, so stay tuned Image may be NSFW.
Clik here to view.