LittleCMDB (An Orchestrator and WaveMaker project) – Part 4

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


Part4

In Part4 of this LittleCMDB series we will finished the first Version of our vCO Workflow and make a run….

Our “get Information” part of the Workflow is ready, know it is time to put the data into the SQL Database.

For that, we start with the placement of our SQL-Statement Workflow we created earlier. For that, we place the workflows

  • “Create active record for ‘VM_Info’”

  • “Create active record for ‘VM_Host’”

    and two Scriptable Tasks in our schema.

In my Order the workflow on the right site of the “VM in DB” is the VM_Info, followed from VM_Host and then the two scriptable Task

First, we will configure the VM_Info Workflow.

The only thing we have to do is to match the attributes which we have with the needed input parameter of the workflow.

Here is the matching table for the Workflow:

Local Parameter Variable Name Module Direction Type
isUnique isUnique Create Active Record VM_Info in Boolean (true)
VMUUID VMUUID Create Active Record VM_Info in String
VMID V_ID Create Active Record VM_Info in String
CPUConfig cpuCount Create Active Record VM_Info in number
MemConfig MemoryMB Create Active Record VM_Info in number
result VMInfo_result Create Active Record VM_Info out SQL:ActiveRecord

Some extra notes here: Sometimes, the creation of the SQL statements workflows uses wrong “Types” for example string then number. You can change this types in the Workflow. After that, you have to reinsert the Workflow.

When you are ready your binding must look like this:

When we are ready we go further with the next Workflow “Create Active record ‘VM_Host’.

Here we need the following bindings:

Local Parameter Variable Name Module Direction Type
isUnique isUnique Create Active Record VM_Host in Boolean (true)
VMUUID VMUUID Create Active Record VM_Host in String
Cluster clusterName Create Active Record VM_Host in String
Host runningHostName Create Active Record VM_Host in String
ResourcePool ResourcePoolName Create Active Record VM_Host in String
Folder folderName Create Active Record VM_Host in String
VMID V_ID Create Active Record VM_Host in String
result VMHost_result Create Active Record VM_Host out SQL:ActiveRecord

Now we are on the first Scriptable Task element. We will use this for the VM_network SQL operation. You may ask yourself why will we don’t use the Workflow Element? That’s a good question and here is the answer.

In the Network and Datastore Element we need some scripting to catch errors from gathering the VM data. Also there is a need for changing the Array/string Elements into String Elements for the storing in the database.

So, let’s start with the first Scripting Element. I call it “SQL_VM_Network”. Know let’s insert the needed in- and outputs

Local Parameter Variable Name Module Direction Type
V_ID V_ID SQL_VM_Network in String
isUnique isUnique SQL_VM_Network in Boolean (true)
VMUUID VMUUID SQL_VM_Network in String
networks networks SQL_VM_Network in Array/string
ipAddresses ipAddresses SQL_VM_Network in Array/string
VMNetwork_table VMNetwork_table SQL_VM_Network in SQL:Table
ipAddressesToString ipAddressesToString SQL_VM_Network in String
NetworksToString NetworksToString SQL_VM_Network in String
VMNetwork_result VMNetwork_result SQL_VM_Network out SQL:ActiveRecord

Here is the Script for the Element

// Catch empty Network and IpAdresses and set a placeholder text

if (ipAddresses == null){

IpAddressToString = "No IP adress found"

} else {

IpAddressToString = ipAddresses.toString()

};

if (networks== null){

NetworksToString = "No networks found"

} else {

NetworksToString =networks.toString()

};

// The SQL Operation to store the information into the Db

var columns = {

VMID : V_ID,

VMUUID : VMUUID,

Network : NetworksToString,

IPAddress : IpAddressToString

};

VMNetwork_result = VMNetwork_table.createRecord(columns, isUnique);

System.log("Database table record created successfully");

Know we have to configure the second scriptable Task. This one is for the Datastore config. I call it “SQL_VM_Datastore”.

Here are the required variables

Local Parameter Variable Name Module Direction Type
V_ID V_ID SQL_VM_Datastore in String
isUnique isUnique SQL_VM_Datastore in Boolean (true)
VMUUID VMUUID SQL_VM_Datastore in String
diskSize diskSize SQL_VM_Datastore in Array/string
datastoreName datastoreName SQL_VM_Datastore in Array/string
VMDatastore_table VMNetwork_table SQL_VM_Datastore in SQL:Table
DiskSizeToString DiskSizeToString SQL_VM_Datastore in String
DatastoreNamesToString DatastoreNamesToString SQL_VM_Datastore in String
VMDatastore_result VMNetwork_result SQL_VM_Datastore out SQL:ActiveRecord

Here is the script for the Element:

// Catch empty disksizes and datastoreName and replace with a string

if (diskSizes == null){

DiskSizeToString = "Could not read Disk Size"

} else {

DiskSizeToString = diskSizes.toString();

};

if (datastoresName == null){

DatastoreNamesToString = "Could not read Datastore Name"

} else {

DatastoreNamesToString = datastoresName.toString();

};

// The SQL Operation to store the information into the Db

var columns = {

VMID : V_ID,

VMUUID : VMUUID,

DiskSize : DiskSizeToString,

Datastore : DatastoreNamesToString

};

VMDatastore_result = VMDatastore_table.createRecord(columns, isUnique);

System.log("Database table record created successfully");

Know we have to connect our elements. First, we need a Connection from our “VM in DB” Element to the “Create active record for ‘VM_Info’”. From there we go up and connect the “Create active record for ‘VM_Host’” with the “SQL_VM_Network” and then with the “SQL_VM_Datastore”. From the “SQL_VM_Datastore” we build the connection to “NumberofVMs”.

When you have build the connections, your Schema must look like this:

Before we close our Workflow we validate it

When you made everything right, our workflow must show now errors.

Know it is time to make a first run. Save and close the Workflow and start the Workflow with a right click and the option “Start Workflow…”

If you start your Workflow after the first run a second time, only new virtual machines will be cached. Existing machines are ignored.

That’ was all for Part4. In Part5 we are going to create a Website with WaveMaker and get a look on our data so stay tuned 😉

De Vcoportal Part4
De Vcoportal Part4
de.vcoportal_Part4.package
120.9 KiB
Details...