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
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.
For that, we click on “Not Set (NULL)” and choose the Skip VM variable
Then we have to set the parameter to “is false”
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…
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
The VMInfoRead_result is reading data out of the database and to work with this data.
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.
After we have chosen the Variable, we set the Boolean Value to “false”
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”
Next we need a connection from “SkipVM” to “Extract virtual machine Information” and a “Error Connection to “NumberofVMs”.
All Other Elements will be connected to the following element.
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.
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 😉
nice job congrats
Thanks!
Hi Christian,
I had a crack at creating the littleCMDB in VCO, got everything up until getVMFromDB – for the life of me, I don’t know why I get a java.lang.NullPointerException @ getVMFromDB (item7) #7 (i.e. can’t use null in a case where an object is required.)
I’ve checked the attributes, database and put in my own debugging to try to figure it out.
Let me know if you have a solution. Again, I appreciate any help.
Cheers,
Dylan
Hi Dylan, as you saw on Christian’s outoresponder, he’s on holiday. But I will set a reminder so he hopefully can help soon…
Cheers,
Joerg
Hi Dylan,
just check my „exported“ workflow…..and found an error in it. There is a typo in the module “VM in DB”. Here is the Part with typo:
“
if ((UUIDString >= 0) && (VMNameString >=0))
{
VMiDB = true;
System.log(“VM: ” + VMName + ” already in DB.”)
}
else
{
VMiDB = false;
System.log(“VM: ” + VMName + ” not in DB.”)
};”
The module VMiDB must be named VMinDB. Then everything should work as expected.
if ((UUIDString >= 0) && (VMNameString >=0))
{
VMinDB = true;
System.log(“VM: ” + VMName + ” already in DB.”)
}
else
{
VMinDB = false;
System.log(“VM: ” + VMName + ” not in DB.”)
};
Give it a try and come back if you have additional questions!
Cheers, Christian
Hi Christian,
Sorry to bother during your holidays. It wasn’t unfortunately a problem with incorrectly variable name like you suggest (VMinDB is variable I used as well, as I copied your documentation, rather than using the .package)
I get the error: java.lang.NullPointerException (Workflow:GetVMConfig / getVMFromDB (item7)#7)
So I decided to have another crack before writing back.
var columns = {
UUID : VMUUID,
VMName : VMName
};
VMInfoRead_result = VMInfo_Table.readRecords(columns);
I think it has to do with ‘columns’ being null, returns [object Object] which could mean I think its doesn’t take the write type. (because it is returning null for me.)
So, I made ‘columns’ an array.
var columns = [VMUUID, VMName];
VMInfoRead_result = VMInfo_Table.readRecords(columns);
And that seems to work.
I am upto the custom SQL: ActiveRecord (SQL_VM_Network and SQL_VM_Datastore)
I let you know how that goes…
But for now, like Joerg mentioned – I think you should enjoy your holiday 🙂 (Instead of being pestered by Javascript noobs :P)
Thanks again for your help. It is very much appreciated.
Cheers,
Dylan
Ich bin bis 17.09.2012 abwesend.
Sehr geehrte Damen und Herren,
Vielen Dank für Ihre E-Mail. Zur Zeit befinde ich mich nicht im Büro. Ankommende E-Mails werden während meiner Abwesenheit nicht weitergeleitet, aber sofort nach meiner Rückkehr beantwortet.
In dringenden Fällen können Sie gerne meinen Kollegen Christoph Leygraf ( Tel. +49 15118025121; christoph.leygraf@sva.de) oder Andreas Ehrenreiter ( Tel. +49 15111359466; andreas.ehrenreiter@sva.de) kontaktieren.
Dear Ladies and Gentlemen,
Thank you for your message.I am out of the office.
Your e-mail will not be forwarded, I will answer it as soon as I am back. For urgent matters please contact my colleagues Christoph Leygraf ( Tel. +49 15118025121; christoph.leygraf@sva.de) or Andreas Ehrenreiter ( Tel. +49 15111359466; andreas.ehrenreiter@sva.de).
Mit freundlichen Grüßen – Best regards
Christian Strijbos
Senior IT-Architekt
SVA System Vertrieb Alexander GmbH
Borsigstrasse 14
65205 Wiesbaden, Germany
Mobile: +49 151 18025123
Phone: +49 6122 / 536-0
Fax.: +49 6122 / 536-399
E-Mail: christian.strijbos@sva.de
http://www.sva.de
Geschäftsführung: Felix Alexander, Philipp Alexander, Sven Eichelbaum Sitz der Gesellschaft: Wiesbaden
Registergericht: Amtsgericht Wiesbaden, HRB 10315
Hinweis: Dies ist eine automatische Antwort auf Ihre Nachricht “[vcoportal] Re: LittleCMDB (An Orchestrator and WaveMaker project) – Part 3” gesendet am 10.09.2012 03:32:08.
Diese ist die einzige Benachrichtigung, die Sie empfangen werden, während diese Person abwesend ist.