vCO Use-Cases

0

Generate VMs based on actual load in a Resource Pool

During the last VMworld in Barcelona I was in a session (INF-VSP2033 – Auto Scaling and Cloud Bursting in the Hybrid IaaS Cloud) from Christophe Decanini and Chris Knowles who showed a solution with two sites located in Europe and the USA with vSphere and vCO environments on both sites. The sites were connected with F5 Loadbalancer and the load could be migrated from one Country to the other Country……sincerely the session is not online in the VMworld online session folder so you cannot see what the showed…..

To give you a hint what is possible with the vCO, I created my “own” solution based on the load in a given resource pool, see following video:

Some background notes what I did with my Workflow:

  • I monitor a resource pool for the load in the RP. It is also possible to do so in a folder
  • I can define a minimum amount of VMs with must be run in the RP. A deletion below this minimum point is not possible from the Workflow
  • I can define a maximum amount of running virtual machines in the RP. The workflow cannot provision VMs above the maximum amount.
  • My virtual machines witch were provisioned are all Linux based (I use a CentOS). The data for the machines (for example a Website) must be located outside the VMs. I connect them via NFS or iSCSI. The machines are an ideal example for vApps
  • The load is captured over a time interval of 5 minutes. Short peaks will not result in any action (create new VMs or delete existing VMs)

So have fun with the Video and get a look what is possible with the vCO. If you have questions feel free to ask ([email protected]).

Load based generation of virtual machines from Christian Strijbos on Vimeo.

0

Backup vCloud Director vApps automatically, driven by vCO

This video shows another example how powerful vCenter Orchestrator really is:

Auto-Create a new Backup Job, whenever a new vApp is deployed in vCloud Director

vCloud Director Backup driven by vCenter Orchestrator from Joerg Lew on Vimeo.

For that I used the AMQP-Plugin, so that the “Create VM“-Event in vCD triggers the Generate Backup Job-Workflow. This workflow calls out to a Powershell-Script to create a new Backup Job using the vendor’s snapin. I used Veeam Backup&Recovery, because they provide a lot of helpful Cmdlets to automate their backup solution.

What to learn?

  • For vCloud Administrators: vCO allows you to integrate vCD with the rest of your IT-world
  • For Backup Vendors: Provide a Plugin for vCO (or at least a basic API), and your customer can integrate your backup product with the rest of their IT-world.
    (Then you don’t even have to develop the integration for vCloud Director from scratch 😉 )
  • For every VMware User: Even without vCloud Director you can use vCO for a lot of cool stuff to integrate your IT-world (what about to create a new Backup Job whenever anybody deploys a Template in vCenter…?)
  • For all: Be creative! Everything is possible with vCO!

References (in case I kicked your mind :mrgreen:)

0

vCO, SNMP Traps and vCOPS

Today I had the request, to generate a vCOPS Demo with an vCO integration. For that, I had a first look on Jörg’s post about is “Self-Healing datacenter” which can be found here: http://www.vcoportal.de/2012/05/integrate-vcops-and-vco/

For me, that was a good starting point but I want to integrate the SNMP Trap with an existing workflow. The creation of a Workflow to deal with snmp traps is not a big problem. The bigger problem is the “automatic” processing via Policy’s because there is no documentation (or I didn’t find it) . So I started to talk with Jörg and made some research in the web.  There I found this excellent post from William Lam about “Automatically Securing Virtual Machines Using vCenter Orchestrator”  http://blogs.vmware.com/vsphere/2012/07/automatically-securing-virtual-machines-using-vcenter-orchestrator.html

This post from William (and his package) has everything inside we need.

First we have to create the preconditions like the SNMP installation in the vCO and the configuration in the vCOPS and the vCO. Jörg has this already documented here: http://www.vcoportal.de/2012/05/integrate-vcops-and-vco/ so I will not repeat this steps here.

Let’s start with the Workflow development. First, we have to create a new workflow. I will call it “Execute Host Maintenance after trap” and I insert the following description “Waits to receive an SNMP trap from a vCenter Server instance, then set the host in maintenance mode or exist the maintenance mode “

After we created the Workflow, we go to the “Schema” tab

Here we insert some Elements. We need:

  • One Scriptable Task
  • One Decsion
  • The Workflow Enter Maintenance Mode
  • The Workflow Exit Maintenance Mode
  • And a Workflow End.

When you are ready your order should look like mine.

Now, let’s start with the Scriptable Task. I name it “Retrieve Host”. We want to extract the information out of the SNMP Message, for that we need some variables and SNMP Trap information. Let’s start with the SNMP Trap Information. The SNMP Messages comes with OID Numbers. Each OID Number has a different meaning and stands for a other component or message. The values of this OID Number can be found in the SNMP MIB Files which can be downloaded from the VMware Website. Every trap data has more than one OID Number

=============

oid: 1.3.6.1.2.1.1.3.0

type: Number

snmp type: Timeticks

value: 1743301911

Element 2:

=============

oid: 1.3.6.1.6.3.1.1.4.1.0

type: String

snmp type: OID

value: 1.3.6.1.4.1.19004.0.25

Element 3:

=============

oid: 1.3.6.1.4.1.19004.2.1

type: String

snmp type: Octet String

value: localhost

Element 4:

=============

oid: 1.3.6.1.4.1.19004.2.2

type: String

snmp type: Octet String

value: 10.10.120.183

Element 5:

=============

oid: 1.3.6.1.4.1.19004.2.3

type: String

snmp type: Octet String

value: Resource

Element 6:

=============

oid: 1.3.6.1.4.1.19004.2.4

type: String

snmp type: Octet String

value: 1346068003943

Element 7:

=============

oid: 1.3.6.1.4.1.19004.2.5

type: String

snmp type: Octet String

value: Critical

Element 8:

=============

oid: 1.3.6.1.4.1.19004.2.6

type: String

snmp type: Octet String

value: New alert by id 36 is generated at Mon Aug 27 11:46:43 UTC 2012; Root Cause : (2 SYMPTOMS)

1. MESSAGE EVENT    (1 OF 3)

33% - FAULT -

33% - CHANGE EVENT -

Element 9:

=============

oid: 1.3.6.1.4.1.19004.2.7

type: String

snmp type: Octet String

value: https://10.10.120.166/vcops-vsphere/?alert=36

Element 10:

=============

oid: 1.3.6.1.4.1.19004.2.8

type: Number

snmp type: Integer

value: 36

Element 11:

=============

oid: 1.3.6.1.4.1.19004.2.9

type: String

snmp type: Octet String

value: Verbindungsstatus der physischen Netzwerkkarte vmnic1 ist nicht bereit.

Element 12:

=============

oid: 1.3.6.1.4.1.19004.2.10

type: String

snmp type: Octet String

value: Health

Element 13:

=============

oid: 1.3.6.1.4.1.19004.2.11

type: String

snmp type: Octet String

value: Faults

For us, we want to search for the OID Number of the hostname and the error Message.

With this background information, we can create our needed In- and Outputs for our Workflow.

Local Parameter Variable Name Module Direction Type Value
trapData trapData Retrieve Host in Array/Properties
HostOID HostOID Retrieve Host in String 1.3.6.1.4.1.19004.2.2
MessageOID MessageOID Retrieve Host in String 1.3.6.1.4.1.19004.2.6
Host Host Retrieve Host out VC:HostSystem
SNMPMessage SNMPMessage Retrieve Host out String
NewAlert NewAlert Retrieve Host out Boolean

One important thing here: The trapData must be defined as Input Parameter not as attribute!

After we have created our variables, we can start with our scripting. I made a lot comments in the script, so everybody should understand what there happens….


// We extract the host name out of the SNMP TrapData
var HostName;
for (var x = 0; x < trapData.length; x++) {
var prop = trapData[x];
if (prop.get("oid") == HostOID) {
HostName = prop.get("value");
break;
}
}

// We compare the extracted Hostname with the Hosts registred in the vCenter Server.
// when we hava a match, we have the managed object ID of the Host
var hosts = VcPlugin.getAllHostSystems();
for (var i = 0; i < trapData.length; i++) {
var tempHost = hosts[i];
if (tempHost.name == HostName) {
Host = tempHost;
break;
}
}

// We search for the OID in the Message to get the Field with the recieved error Message
var SNMPTrap;
for (var y = 0; y < trapData.length; y++) {
var prop = trapData[y];
if (prop.get("oid") == MessageOID) {
SNMPTrap = prop.get("value");
break;
}
}

// Our search values in the Value Field of the Message
// When the Field contains the search string we beome the position. Otherwise be become a -1 value back.
var SNMPAlert = SNMPTrap.indexOf("New alert");
var SNMPCancel = SNMPTrap.indexOf("is cancelled");

// We check if the SNMP Trap has "New Alert" in the value field. Is so, we have a new alert.
if ( SNMPAlert != -1) {
NewAlert = true}
else {
NewAlert = false
};

Then we go to the Decsion. I name it “New Alert”. As Input we only need “NewAlert”. In the Decision field itself we set “NewAlert is true”.

After that, we go to the Enter Maintenance Mode. Here we only need to input variables:

Local Parameter Variable Name Module Direction Type Value
Host Host Enter Maintenance in VC:HostSystem
timeout timeout Enter Maintenance in number 0

Our Visual Binding has to look like this:

The same Variables and the same Visual Binding is required for Exit Maintenance Mode Workflow.

Local Parameter Variable Name Module Direction Type Value
Host Host Exit Maintenance in VC:HostSystem
timeout timeout Exit Maintenance in number 0

At last, we have to connect our Elements.  For the connections we Connect the start to “Retrieve Host” from there we connect the “New Alert”. From the “New Alert” we go with the Green line to “Enter Maintenance Mode” and with the red line to “Exit Maintenance Mode”.

Both Elements were connected to the End.

At last, we validate our Workflow and save our work.

After we have finished our Workflows, we create a Policy Template. For that, go to “policy Template” and create a folder with a name of your choice. I have a folder with the Name “vcoportal.de”.

With a “right click” on the folder you can open a context menu and choose “ Add policy template..:”

First we have to insert a name and a description. I choose “SNMP Trap with data” as name.

Then we go to the Scripting tab

There we have to insert the Device from with we want to catch our data. You can insert the device by clicking on the first button.

In the Dialog we choose SNMP:SnmpDevice

Then we check the SNMP Device and then click on the Second button.

As trigger we choose “onTrap”

At last, we have to insert this Scripting in “Script” field from the “OnTrap” Trigger.


// Author Christian Strijbos ([email protected])
// based on Examples and a Blog Post of  William Lam
// SNMP Policy to Check for Host Maintenance in case of an host error

// Execute Host Maintenace after trap ID
// To catch the Workflow ID, just go to the Workflow, type CTRL-C, open Notepad and Type CTRL-V
// You will get the ID of the Workflow in the id. Field.
var wfId = "83808080808080808080808080808080AA8A808001345464207298aebf2a6a5a5";

// process SNMP trap
var key = event.getValue("key");
var snmpResult = SnmpService.retrievePolicyData(key);
var trapData = System.getModule("com.vmware.library.snmp").processSnmpResult(snmpResult);
runWF(wfId,trapData);

// function to launch WF
function runWF(wfId,trapData) {
var workflowToLaunch = Server.getWorkflowWithId(wfId);
if (workflowToLaunch == null) {
throw "Workflow not found";
}
var workflowParameters = new Properties();
workflowParameters.put("trapData",trapData);
System.log("Launching Execute Host Maintenace after trap WF: " + wfId);
var wfToken = workflowToLaunch.execute(workflowParameters);
}

Some special notes here: In the Policy tab, variables are not highlighted. So if you write scripts on your own, make sure you write your variables well. Also there is no validation available, so there are a lot of possibility’s to make things go wrong 🙁

Save and close the template.

Next we want to apply out policy. Make a “right click” on the Policy Template and choose “Apply Policy..” in the Context menü.

In the menu you have to choose our SNMP Device

You can find your Policy under the “policy” Tab.

Right Click on it and choose “Edit”.

There you can choose our Startup Policy.  I choose “on Server Startup, start the Policy”. Save and  close the Policy.

At last, “right click” on the policy and start it.

After that, your policy is active and wait’s for SNMP traps from the vCOPS.

My setup follows the same principle like the integration with the SNMP Plugin with the vCenter Server like described in this Link:

http://blogs.vmware.com/orchestrator/2011/09/snmp-plug-in-integration-with-vcenter.html

vCO_Package_SNMP_vCOPS
vCO_Package_SNMP_vCOPS
de.vcoportal.snmp.vcops.package
35.8 KiB
Details...
0

LittleCMDB (An Orchestrator and WaveMaker project) – Part 7

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

Part7

Today we will make some more error corrections for our LittleCMDB. Has anyone build the LittleCMDB yet? Do you use vAPPS in your environment? Than you have a problem with the LittleCMDB. The Workflow will stop on the “Extract virtual machine information” workflow.

Why that?  To answer this Question we must take a look at the Workflow and the API. Let’s start with the Workflow. The Workflow exist out of different elements. The first element “Get Folder” grabs the Folder for the virtual machine.

For a “normal” virtual machine this works perfectly. The element uses the VM name and the “parent” object in the API to get the needed information.

Now let’s have a look on a virtual machine which is located under a vAPP.

Did you see the difference? For a virtual machine the parameter “parent” is used and the parameter “parentVApp” is Unset. For a virtual machine under a vApp that’s changed. So, when the Workflow hits a virtual machine located under a vApp the Workflow will fail.

How can we fix this problem? Don’t worry, that easy 😉

First, we have  to copy the Workflow “Extract virtual machine information”. We do so by going to:

Library –> vCenter –> Virtual Machine management –> Others There we can find our Workflow.

Just “right click”  on the Workflow and choose in the menu “Duplicate Workflow”.

Give the Workflow a name, I take the name “Extract virtual machine information_WithChanges” and choose a location for the Workflow. I would recommend  to keep all your customized workflows together. I will insert the Workflow into my vcoportal.de folder and there in a subfolder “Helper” (for me that is better to export my project 😉 ). Copy the version history.

After we have duplicated the Workflow, we go to the chosen Folder and edit it.

First I change the Version history and insert a comment.

Then we go to the Schema Tab and there to the “Get Folder” Element. Here we change the Scripting to:


if (vm.parent != null){
folder = vm.parent;} else
{
folder = vm.parentVApp;}

folderName = folder.name;
folderId = folder.sdkId;

The scripting here is simple. We just look if the parent value is unset, then we use parentVApp. After we are finished validate and save the workflow.

At last, we go to our “GetVMConfig” Workflow. There we delte the “Extract virtual machine information” Workflow and insert our “Extract virtual machine information_WithChanges” workflow.

After that, insert the connections and the vm parameter (VMtoGet). Normally it should be insert automatically. Validate our Workflow and enjoy.

That’s all for Part7.

De Vcoportal Part7
De Vcoportal Part7
de.vcoportal.package_part7.package
126.3 KiB
Details...
0

LittleCMDB (An Orchestrator and WaveMaker project) – Part 6

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

Part6

Let’s have a look on our LittleCMDB. We can capture virtual machines, we insert the captured data into a SQL DB and we have a Website to get a look on our data. Till now, that okay but we have some “problems” with our CMDB. What’s with virtual Machines were the configuration is changed after the first capture? At the moment will we not get this configuration changes. Why we don’t get the changes? In our decision “VM in DB” we have the condition “when the VM is in our DB we go back to NumberofVMs”. We don’t look for configuration changes.

That’s not smart 🙂 ……… This means our DB could be outdated with one week if enough configuration changes were made…

So let’s start and make our LittleCMDB more “production” ready.

First we remove the red dotted line from “VM in DB” to “NumberofVMs”.

First we insert from Bottom to top a Scriptable Task and a Decision. We do this four times. When we are finished your schema should look like mine.

Then we will insert the next Workflows. Here we are on a decision we must made…… We can choose the SQL “Update” workflows or generate Scriptable Task with our own code. I will use scriptable task for the update of the datasets. Why that? When you use the “Update” Workflows, error correction and data search is sometimes a problem. You can only insert “one” value (the value to update the dataset). In the data search, this leads to problems. So I will use scriptable task in which I can insert all needed parameter and my required error correction.

So insert four scriptable workflows on the left of the other workflows.

At the End your schema must look like this:

Don’t worry about the sum of Workflow……it will be very easy 😉

Know we start with the Scriptable Task at the bottom. First we give a name and description. I will call it “GetVMfromVM_Info”. As description you can insert “We read the information from the VM_Info Table split it and comparing it with the actual data.”

Here are the required Variables for the Element:

Local Parameter Variable Name Module Direction Type
VMName VMName GetVMInfofromVM_Info in String
VMInfo_Table VMInfo_Table GetVMInfofromVM_Info in SQL:Table
VMUUID VMUUID GetVMInfofromVM_Info in String
VMInfofromDB VMInfofromDB GetVMInfofromVM_Info in SQL:ActiveRecord
datastoreName datastoreName GetVMInfofromVM_Info in Array/string
cpuCount cpuCount GetVMInfofromVM_Info in number
memoryMB memoryMB GetVMInfofromVM_Info in number
CPUNumberfromDB CPUNumberfromDB GetVMInfofromVM_Info out number
MemNumberfromDB MemNumberfromDB GetVMInfofromVM_Info out number
VM_Info_Change VM_info_Change GetVMInfofromVM_Info out Boolean
V_ID V_ID GetVMInfofromVM_Info Out String

Don’t forget to map the VMInfo_table variable to the VM_Info table.

Here is the required Script for the Task:

// -------------------------------------------------------------
// we search for the Data of the virtual Machine with the Name and the UUID. First we define the search columns
var columns = {
 VMUUID : VMUUID,
 VMName : VMName,

};

// Get the Data from the Table and put them in a SQL Active Record
VMInfofromDB = VMInfo_table.readRecords(columns);
// The data from the SQL Record is a "String" with is separated with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringMem = VMInfofromDB.toString();
// In the Array, we search for the Keyword "MemConfig" under which our Memory configuration is stored
var MemSearch = SplitConfigArraytoStringMem.search("MemConfig");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 10 after the Start Position (MemConfig + = is about 10 positions)
var MemStart = MemSearch + 10;
// Here we split at the beginning of the Value with the rest of the string
var MemStringTemp = SplitConfigArraytoStringMem.slice(MemStart);
// We split on the first "," found. That's our value End
var MemStringEnd = MemStringTemp.search(",");
// Here we take the start and the end we figured out before and save the value into the Variable
MemNumberfromDB = MemStringTemp.slice(0, MemStringEnd);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringCPU = VMInfofromDB.toString();
// In the Array, we search for the Keyword "CPUConfig" under which our Memory configuration is stored
var CPUSearch = SplitConfigArraytoStringCPU.search("CPUConfig");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 10 after the Start Position (CPUConfig + = is about 10 positions)
var CPUStart = CPUSearch + 10;
// Here we split at the beginning of the Value with the rest of the string
var CPUStringTemp = SplitConfigArraytoStringCPU.slice(CPUStart);
// We split on the first "}" found. That's our value End
var CPUStringEnd = CPUStringTemp.search("}");
// Here we take the start and the end we figured out before and save the value into the Variable
CPUNumberfromDB = CPUStringTemp.slice(0, CPUStringEnd);
// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
// The V_ID Field is required to update the SQL DB when there is a change
var SplitConfigArraytoStringVID = VMInfofromDB.toString();
// In the Array, we search for the Keyword "V_ID" under which our V_ID is stored
var VIDSearch = SplitConfigArraytoStringVID.search("VMID");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 5 after the Start Position (VMID + = is about 5 positions)
var VIDStart = VIDSearch + 5;
// Here we split at the beginning of the Value with the rest of the string
var VIDStringTemp = SplitConfigArraytoStringVID.slice(VIDStart);
// We split on the first "," found. That's our value End
var VIDStringEnd = VIDStringTemp.search(",");
// Here we take the start and the end we figured out before and save the value into the Variable
V_ID = VIDStringTemp.slice(0, VIDStringEnd);

//-----------------------------------------------------------------------------------------------------------------
// After we have our "configuration" Values, we have to check if there is a difference between the VM Data and
// the data stored in the DB.

if ((CPUNumberfromDB != cpuCount) || (MemNumberfromDB != memoryMB)){
// When there is a difference, we set the Variable to true
VM_Info_Change = true;}
else {
// When there is no difference, we set the Variable to false
VM_Info_Change = false;}

I made a lot comments in the scripting element so I hope everybody understand the Idea to split the array and get on the DB data.

Next we go to our decision up to the scripting element. We give it a name. I chose “VM_Info_change”. As variable for this decision we need the following:

Local Parameter Variable Name Module Direction Type
VM_Info_Change VM_Info_Change VM_Info_Change in boolean

In the Decision field we set the Value to “is true”

At least, we are going to work with the “Scriptable task” to the left. I call it  “Update active record for ‘VM_Info’” Element.  For that, we need the following In- and Outputs

Local Parameter Variable Name Module Direction Type
VMName VMName Update Active Record for ‘VM_Info’ in String
V_ID V_ID Update Active Record for ‘VM_Info’ in String
VMUUID VMUUID Update Active Record for ‘VM_Info’ in String
cpuCount cpuCount Update Active Record for ‘VM_Info’ in Number
memoryMB memoryMB Update Active Record for ‘VM_Info’ in Number
MemNumberfromDB MemNumberfromDB Update Active Record for ‘VM_Info’ in Number
CPUNumberfromDB CPUNumberfromDB Update Active Record for ‘VM_Info’ in Number
VMInfo_table VMInfo_table Update Active Record for ‘VM_Info’ in SQL:Table
VMInfoRead_result VMInfoRead_result Update Active Record for ‘VM_Info’ in SQL:ActiveRecord
UpdateResult_VM_Info UpdateResult_VM_Info Update Active Record for ‘VM_Info’ out Number

Here is the script we insert into the Scripting field:

// we need the original values to load the record from the DB
var NewArray = new Array(V_ID,VMUUID,VMName,CPUNumberfromDB,MemNumberfromDB)

// we search for the record in the DB with the data from there
VMInfoRead_result = System.getModule("com.vmware.library.sql").findUniqueRecord(VMInfo_table,NewArray);

var columns = {
 VMID : V_ID,
 VMUUID : VMUUID,
 VMName : VMName,
 CPUConfig : cpuCount,
 MemConfig : memoryMB
};
UpdateResult_VM_Info = VMInfo_table.updateRecord(VMInfoRead_result, columns);
System.log("Update DB with new virtual machine information")

Now we are going to connect the first Elements. We start with the “VM_in_DB” Element and connect it with the “red” line to the “GetVMfromVM_Info” Element. The “GetVMfromVM_Info” will be connected to the “VM_Info_Change” element. From this element we connect the “true” (the green line) to “Update active record for ‘VM_Info” and the “false” (the red line) to the “Scriptable Task above. As last connection we draw the line from “Update active record for ‘VM_Info” to the Scriptable Task above. When you are ready your connections must look like my.

After we have finished our connections, we go further with the “Scriptable  Task” Element we have already connected. First we insert a name and description. I use as name “GetVMfromHost_info” and as description “Get the Information from the database regarding the Host information”. Then we have to define our needed variables:

Local Parameter Variable Name Module Direction Type
VMHost_Table VMHost_Table GetVMfromHost_info in SQL:Table
VMUUID VMUUID GetVMfromHost_info in String
V_ID V_ID GetVMfromHost_info in string
VMInfofromDB VMInfofromDB GetVMfromHost_info in SQL:ActiveRecord
runningHostName runningHostName GetVMfromHost_info in String
clusterName clusterName GetVMfromHost_info in String
resourcePoolName resourcePoolName GetVMfromHost_info in String
folderName folderName GetVMfromHost_info in String
HostfromDB HostfromDB GetVMfromHost_info out String
ClusterfromDB ClusterfromDB GetVMfromHost_info out String
RPfromDB RPfromDB GetVMfromHost_info out String
FolderfromDB FolderfromDB GetVMfromHost_info out String
VM_Host_Change VM_Host_Change GetVMfromHost_info out boolean

Also here is it required, to point the Variable “VMHost_table” to the “VM_Host” Table

Then we can start our scripting. In the basic, the following scripting is the same as we already did for the “GetVMInfofromVM_Info” table. Here is the Script:

// -------------------------------------------------------------
// we search for the Data of the virtual Machine with the Name and the UUID. First we define the search columns
var columns = {
 VMID : V_ID,
 VMUUID : VMUUID,
};

// Get the Data from the Table and put them in a SQL Active Record
VMInfofromDB = VMHost_table.readRecords(columns);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringHost = VMInfofromDB.toString();
// In the Array, we search for the Keyword
var HostSearch = SplitConfigArraytoStringHost.search("Host");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 5 after the Start Position
var HostStart = HostSearch + 5;
// Here we split at the beginning of the Value with the rest of the string
var HostStringTemp = SplitConfigArraytoStringHost.slice(HostStart);
// We split on the first "," found. That's our value End
var HostStringEnd = HostStringTemp.search(",");
// Here we take the start and the end we figured out before and save the value into the Variable
HostfromDB = HostStringTemp.slice(0, HostStringEnd);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringCluster = VMInfofromDB.toString();
// In the Array, we search for the Keyword
var ClusterSearch = SplitConfigArraytoStringCluster.search("Cluster");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 8 after the Start Position
var ClusterStart = ClusterSearch + 8;
// Here we split at the beginning of the Value with the rest of the string
var ClusterStringTemp = SplitConfigArraytoStringCluster.slice(ClusterStart);
// We split on the first "}" found. That's our value End
var ClusterStringEnd = ClusterStringTemp.search(",");
// Here we take the start and the end we figured out before and save the value into the Variable
ClusterfromDB = ClusterStringTemp.slice(0, ClusterStringEnd);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringFolder = VMInfofromDB.toString();
// In the Array, we search for the Keyword
var FolderSearch = SplitConfigArraytoStringFolder.search("Folder");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 7 after the Start Position
var FolderStart = FolderSearch + 7;
// Here we split at the beginning of the Value with the rest of the string
var FolderStringTemp = SplitConfigArraytoStringCluster.slice(FolderStart);
// We split on the first "," found. That's our value End
var FolderStringEnd = FolderStringTemp.search(",");
// Here we take the start and the end we figured out before and save the value into the Variable
FolderfromDB = FolderStringTemp.slice(0, FolderStringEnd);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringRP = VMInfofromDB.toString();
// In the Array, we search for the Keyword
var RPSearch = SplitConfigArraytoStringRP.search("ResourcePool");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 13 after the Start Position
var RPStart = RPSearch + 13;
// Here we split at the beginning of the Value with the rest of the string
var RPStringTemp = SplitConfigArraytoStringRP.slice(RPStart);
// We split on the first "}" found. That's our value End
var RPStringEnd = RPStringTemp.search("}");
// Here we take the start and the end we figured out before and save the value into the Variable
RPfromDB = RPStringTemp.slice(0, RPStringEnd);

//-----------------------------------------------------------------------------------------------------------------
// After we have our "configuration" Values, we have to check if there is a difference between the VM Data and
// the data stored in the DB.
if ((HostfromDB != runningHostName) || (ClusterfromDB != clusterName) || (RPfromDB != resourcePoolName) || (FolderfromDB != folderName)){
// When there is a difference, we set the Variable to true
VM_Host_Change = true;}
else {
// When there is no difference, we set the Variable to false
VM_Host_Change = false;}

After we finished our scripting we went to the “Decision”. Here we enter a name; I use “VM_Host_Change” and a description. In the Decision we need the Variable “Vm_Host_Change”

Local Parameter Variable Name Module Direction Type
VM_Host_Change VM_Host_Change VM_Host_Change in boolean

We set the Value in the Decision field to “is true”.

Next we define the In- and Outputs for the “Scriptable Task”. I call the Workflow “Update active record for ‘VM_Host’”. We need the following variables:

Local Parameter Variable Name Module Direction Type
V_ID V_ID Update Active Record for ‘VM_Host’ in String
VMUUID VMUUID Update Active Record for ‘VM_Host’ in String
clusterName clusterName Update Active Record for ‘VM_Host’ in String
runningHostName runningHostName Update Active Record for ‘VM_Host’ in String
resourcePoolName resourcePoolName Update Active Record for ‘VM_Host’ in String
folderName folderName Update Active Record for ‘VM_Host’ in String
ClusterfromDB ClusterfromDB Update Active Record for ‘VM_Host’ in String
HostfromDB HostfromDB Update Active Record for ‘VM_Host’ in String
RPfromDB RPfromDB Update Active Record for ‘VM_Host’ in String
FolderfromDB FolderfromDB Update Active Record for ‘VM_Host’ in String
UpdateResult_VM_Host UpdateResult_VM_Host Update Active Record for ‘VM_Host’ in Number
VMHost_table VMHost_table Update Active Record for ‘VM_Host’ in SQL:Table
VMHost_ReadResult VMHost_ReadResult Update Active Record for ‘VM_Host’ in SQL:ActiveRecord
UpdateResult_VM_Host UpdateResult_VM_Host Update Active Record for ‘VM_Host’ Out Number

Here is the script which we need in this module:

// we need the original values to load the record from the DB
var NewArray = new Array(V_ID,VMUUID,ClusterfromDB,HostfromDB,RPfromDB,FolderfromDB)

// we search for the record in the DB with the data from there
VMHost_ReadResult = System.getModule("com.vmware.library.sql").findUniqueRecord(VMHost_table,NewArray);

var columns = {
 VMID : V_ID,
 VMUUID : VMUUID,
 Cluster : clusterName,
 Host : runningHostName,
 ResourcePool : resourcePoolName,
 Folder : folderName
};

UpdateResult_VM_Host = VMHost_table.updateRecord(VMHost_ReadResult, columns);
System.log("Update DB with new host information")

&nbsp;

After we have finished our mappings, we can connect the different workflows together. Also here it is the same schema as before. We connect the “GetVMfromHost_Info” to the decision “VM_Host_Change” from there we connect the false path to the “Scriptable Task” above and the true Path to “Update active record from ‘VM_Host”. From there we connect to also to the Scriptable task.

Now, I think everybody has an understanding from the method which is used here, so I will only provide the variables and the scripts for the last elements.

I call the next scriptable task “GetVMfromVM_Network”.  Here are the required in- and outputs and the script:

Local Parameter Variable Name Module Direction Type
V_ID V_ID GetVMInfofromVM_Network in string
VMNetwork_table VMNetwork_table GetVMInfofromVM_Network in SQL:Table
VMUUID VMUUID GetVMInfofromVM_Network in String
VMInfofromDB VMInfofromDB GetVMInfofromVM_Network in SQL:ActiveRecord
ipAddresses ipAddresses GetVMInfofromVM_Network in Array/string
networks networks GetVMInfofromVM_Network in Array/string
IPfromDB IPfromDB GetVMInfofromVM_Network out String
NetworksfromDB NetworksfromDB GetVMInfofromVM_Network out String
VM_Network_Change VM_Network_Change GetVMInfofromVM_Network out boolean
IpAddressToString IpAddressToString GetVMInfofromVM_Network out string
NetworksToString NetworksToString GetVMInfofromVM_Network out string
// -------------------------------------------------------------
// we search for the Data of the virtual Machine with the Name and the UUID. First we define the search columns
var columns = {
 VMID : V_ID,
 VMUUID : VMUUID,
};

// Get the Data from the Table and put them in a SQL Active Record
VMInfofromDB = VMNetwork_table.readRecords(columns);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringIP = VMInfofromDB.toString();
// In the Array, we search for the Keyword "IPAddress"
var IPSearch = SplitConfigArraytoStringIP.search("IPAddress");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 10 after the Start Position
var IPStart = IPSearch + 10;
// Here we split at the beginning of the Value with the rest of the string
var IPStringTemp = SplitConfigArraytoStringIP.slice(IPStart);
// We split on the first "," followed from a space. That's our value End. That's different then before because
// the vm can have more than one ip which is separated thru a ","
var IPStringEnd = IPStringTemp.search(/\s?,\s/);
// Here we take the start and the end we figured out before and save the value into the Variable
IPfromDB = IPStringTemp.slice(0, IPStringEnd);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringNet = VMInfofromDB.toString();
// In the Array, we search for the Keyword
var NetSearch = SplitConfigArraytoStringNet.search("Network");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 8 after the Start Position
var NetStart = NetSearch + 8;
// Here we split at the beginning of the Value with the rest of the string
var NetStringTemp = SplitConfigArraytoStringNet.slice(NetStart);
// We split on the first "," folowed from a space. That's our value End. That's different then before because
// the vm can have more than one network which is separated thru a ","
var NetStringEnd = NetStringTemp.search(/\s?,\s/);
// Here we take the start and the end we figured out before and save the value into the Variable
NetworksfromDB = NetStringTemp.slice(0, NetStringEnd);
//-----------------------------------------------------------------------------------------------------------------
// After we have our "configuration" Values, we have to check if there is a difference between the VM Data and
// the data stored in the DB.

// Catch empty Network and IpAddresses and set a placeholder text
if ((ipAddresses == null) || (ipAddresses == "")) {
IpAddressToString = "No IP adress found"
} else {
IpAddressToString = ipAddresses.toString()
};

if ((networks== null) || (networks == "" )){
NetworksToString = "No networks found"
} else {
NetworksToString =networks.toString()
};

if ((IPfromDB != IpAddressToString) || (NetworksfromDB != NetworksToString)){
// When there is a difference, we set the Variable to true
VM_Network_Change = true;}
else {
// When there is no difference, we set the Variable to false
VM_Network_Change = false;}

When you have a deeper look at the script, you will see that there is a change between this script and the two scripts before. Here we have (as by the insert into the DB) to convert our API Network information into a string! You will see the same conversation in the datastore script. Next we work with the Decision above. I call it “VM_Network_Change” and set the Value “VM_network_change” to true. Here is the table with the Variables:

Local Parameter Variable Name Module Direction Type
VM_Network_Change VM_Network_Change VM_Network_Change in boolean

Our last part for this three pair configuration is the “Scriptable task”. I call it “Update active record for ‘VM_Network”. We use the following in- and outputs:

Local Parameter Variable Name Module Direction Type
V_ID V_ID Update active record for ‘VM_Network in String
VMUUID VMUUID Update active record for ‘VM_Network in String
NetworksToString NetworksToString Update active record for ‘VM_Network in String
IpAddressToString IpAddressToString Update active record for ‘VM_Network in String
IPfromDB IPfromDB Update active record for ‘VM_Network in String
NetworksfromDB NetworksfromDB Update active record for ‘VM_Network in String
VMNetwork_table VMNetwork_table Update active record for ‘VM_Network in SQL:Table
VMNetworkRead_result VMNetworkRead_result Update active record for ‘VM_Network in SQL:ActiceRecord
UpdateResult_VM_Network UpdateResult_VM_Network Update active record for ‘VM_Network Out Number

And here is the script:

// We must catch "null" values and change them to ""
// we do this for IPfromDB and NetworksfromDB
// we need the original values to load the record from the DB
if (IPfromDB == "null"){
IPfromDB = "";}
if (NetworksfromDB == "null"){
NetworksfromDB = "";}

var NewArray = new Array(V_ID,VMUUID,NetworksfromDB,IPfromDB)

// we search for the record in the DB with the data from there
VMNetworkRead_result = System.getModule("com.vmware.library.sql").findUniqueRecord(VMNetwork_table,NewArray);

var columns = {
 VMID : V_ID,
 VMUUID : VMUUID,
 Network : NetworksToString,
 IPAddress : IpAddressToString
};

UpdateResult_VM_Network = VMNetwork_table.updateRecord(VMNetworkRead_result, columns);
System.log("Update DB with new network Information")

&nbsp;

Now we can make our connections. Just follow the logic witch was used before. It is the same here…

Now let’s configure the last three pair of Workflows. We start with the scriptable task. I name it “GetVMfromVM_Datastore” and here are the used variables:

Local Parameter Variable Name Module Direction Type
V_ID V_ID GetVMInfofromVM_Datastore in string
VMDatastore_table VMDatastore_table GetVMInfofromVM_Datastore in SQL:Table
VMUUID VMUUID GetVMInfofromVM_Datastore in String
VMInfofromDB VMInfofromDB GetVMInfofromVM_Datastore in SQL:ActiveRecord
datastoresName datastoresName GetVMInfofromVM_Datastore in Array/string
diskSizes diskSizes GetVMInfofromVM_Datastore in Array/Number
DatastorefromDB DatastorefromDB GetVMInfofromVM_Datastore out String
DiskfromDB DiskfromDB GetVMInfofromVM_Datastore out String
VM_Datastore_Change VM_Datastore_Change GetVMInfofromVM_Datastore out boolean
DiskSizetoString DiskSizetoString GetVMInfofromVM_Datastore out String
DatastoreNamestoString DatastoreNamestoString GetVMInfofromVM_Datastore out String

And here is the required script:

// -------------------------------------------------------------
// we search for the Data of the virtual Machine with the Name and the UUID. First we define the search columns
var columns = {
 VMID : V_ID,
 VMUUID : VMUUID,

};

// Get the Data from the Table and put them in a SQL Active Record
VMInfofromDB = VMDatastore_table.readRecords(columns);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringDisk = VMInfofromDB.toString();
// In the Array, we search for the Keyword
var DiskSearch = SplitConfigArraytoStringDisk.search("DiskSize");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 9 after the Start Position
var DiskStart = DiskSearch + 9;
// Here we split at the beginning of the Value with the rest of the string
var DiskStringTemp = SplitConfigArraytoStringDisk.slice(DiskStart);
// We split on the first "," folowed from a space. That's our value End. That's different then before because
// the vm can have more than one ip which is separated thru a ","
var DiskStringEnd = DiskStringTemp.search(/\s?,\s/);
// Here we take the start and the end we figured out before and save the value into the Variable
DiskfromDB = DiskStringTemp.slice(0, DiskStringEnd);

// The data from the SQL Record is a "String" with is sepearted with ",". We have to Split the String in Single Files.....
// First, we put the String into a temporally Variable.
var SplitConfigArraytoStringData = VMInfofromDB.toString();
// In the Array, we search for the Keyword
var DataSearch = SplitConfigArraytoStringData.search("Datastore");
// The above defined search give us the Starting Position of our Keyword. We want the blank value, so we have to split
// on Position 10 after the Start Position
var DataStart = DataSearch + 10;
// Here we split at the beginning of the Value with the rest of the string
var DataStringTemp = SplitConfigArraytoStringData.slice(DataStart);
// We split on the first "}". That's our value End
var DataStringEnd = DataStringTemp.search("}");
// Here we take the start and the end we figured out before and save the value into the Variable
DatastorefromDB = DataStringTemp.slice(0, DataStringEnd);
//-----------------------------------------------------------------------------------------------------------------
// After we have our "configuration" Values, we have to check if there is a difference between the VM Data and
// the data stored in the DB.
// Catch empty disksizes and datastoreName and replace with a string
if ((diskSizes == null) || (diskSizes == "")){
DiskSizeToString = "Could not read Disk Size"
} else {
DiskSizeToString = diskSizes.toString();
};

if ((datastoresName == null) || (datastoresName = "")) {
DatastoreNamesToString = "Could not read Datastore Name"
} else {
DatastoreNamesToString = datastoresName.toString();
};

if ((DiskfromDB != DiskSizeToString) || (DatastorefromDB != DatastoreNamesToString)){
// When there is a difference, we set the Variable to true
VM_Datastore_Change = true;}
else {
// When there is no difference, we set the Variable to false
VM_Datastore_Change = false;}

Next we change the name for the decision to “VM_Datastore_Change”. As input we need:

Local Parameter Variable Name Module Direction Type
VM_Datastore_Change VM_Datastore_Change VM_Datastore_Change in boolean

Also here we set the Value VM_Datastore_Change to “true”.

Our last configuration must be done on the “Scriptable task”. I call it “Update active record for ‘VM_Datastore’”. Here we need the in- and outputs:

Local Parameter Variable Name Module Direction Type
V_ID V_ID Update active record for ‘VM_Datastore’ in String
VMUUID VMUUID Update active record for ‘VM_Datastore’ in String
DiskSizetoString DiskSizetoString Update active record for ‘VM_Datastore’ in String
DatastoreNamesToString DatastoreNamesToString Update active record for ‘VM_Datastore’ in String
DiskfromDB DiskfromDB Update active record for ‘VM_Datastore’ in String
DatastorefromDB DatastorefromDB Update active record for ‘VM_Datastore’ in String
VMDatastore_table VMDatastore_table Update active record for ‘VM_Datastore’ in SQL:Table
VMDatastoreRead_result VMDatastoreRead_result Update active record for ‘VM_Datastore’ in SQL:Active Record
UpdateResult_VM_Datastore UpdateResult_VM_Datastore Update active record for ‘VM_Datastore’ out Number

And this script:

// We must catch "null" values and change them to ""
// we do this for DiskfromDB and DatastorefromDB
// we need the original values to load the record from the DB
if (DiskfromDB == "null"){
DiskfromDB = "";}
if (DatastorefromDB == "null"){
DatastorefromDB = "";}

// we search for the record in the DB with the data from there
var NewArray = new Array(V_ID,VMUUID,DiskfromDB,DatastorefromDB)

VMDatastoreRead_result = System.getModule("com.vmware.library.sql").findUniqueRecord(VMDatastore_table,NewArray);

// Now we start to update the record with the new data
var columns = {
 VMID : V_ID,
 VMUUID : VMUUID,
 DiskSize : DiskSizeToString,
 Datastore : DatastoreNamesToString
};
UpdateResult_VM_Datastore = VMDatastore_table.updateRecord(VMDatastoreRead_result, columns);
System.log("Update DB with new Storage Information")

At least we have to make our last connections. We start from “GetVMfromVM_Datastore” and go to the “VM_Datastore_Change”. From there we go with the false (the red) line to “NumberofVMs”. With the true (the green) line we go to “Update active record for ‘VM_Datastore’”. From there we connect to “NumberofVMs”.

After we have finished our configuration, let’s validate the workflow

And start….

If everything is fine, your DB will be updated with the last information and configuration changes of our virtual machines…..

That’s all for Part6…..

De Vcoportal Part6
De Vcoportal Part6
de.vcoportal.package_part6.package
126.0 KiB
Details...