As I am capturing the entity name of the VMs in the form of string via vCO SNMP traps and I want to map this entity name with the VMs as VC:VirtualMachine which I am not able to do it now.. Please help me out with this..
Thanks,
Naineyess
Hi Naineyess,
we've done this by using a Action which expects the VM-Name and is searching and returning the VM-Object:
Create an action with the following Input / Output:
Input:
- Name: vmName
- Type: string
Output:
- Type: VC:VirtualMachine
Sourcecode:
if ( vmName == "" ) throw "Missing Parameter: Virtualmachine-Name!";
var myVirtualMachines = VcPlugin.getAllVirtualMachines();
for each (var myVirtualMachine in myVirtualMachines)
{
if ( vmName == myVirtualMachine.name )
return myVirtualMachine;
}
return null;
Regards,
Marc
Hi Naineyess,
we've done this by using a Action which expects the VM-Name and is searching and returning the VM-Object:
Create an action with the following Input / Output:
Input:
- Name: vmName
- Type: string
Output:
- Type: VC:VirtualMachine
Sourcecode:
if ( vmName == "" ) throw "Missing Parameter: Virtualmachine-Name!";
var myVirtualMachines = VcPlugin.getAllVirtualMachines();
for each (var myVirtualMachine in myVirtualMachines)
{
if ( vmName == myVirtualMachine.name )
return myVirtualMachine;
}
return null;
Regards,
Marc
Hi Marc,
Thanks your response well I am trying with the same solution which you have provided.. but it is showing some error "Invalid return" ( for return myVirtualMachine;) ..
Thanks !
Did you set the Output of the Action? Or are you using the code directly as Scriptable Task in your Workflow?
Thanks a lot you saved my life ...
The following method will provide much better performance when there are a lot of VMs in your inventory:
var sdkConnections = VcPlugin.allSdkConnections;
vms = new Array();
for (var i in sdkConnections) {
var host = sdkConnections[i];
var found;
if (host.isInventoryServiceAvailable()) {
found = host.getAllVirtualMachines(null, "matches(name, '" + criteria + "')");
} else {
found = host.getAllVirtualMachines(null, "xpath:matches(name, '" + criteria + "')");
}
for (var j in found) {
vms.push(found[j]);
}
}
The above script will search all vCenter connections. For each one, it will attempt to find a vm that has the matching name. It then adds the matching vms to an array called vms... Ideally, you would hope for only 1 match . The technique shown here has the flexibility for you to add your own error checks after the matching vm(s) has been found.