VMware Cloud Community
creativeview
Contributor
Contributor
Jump to solution

Error executing workflow using the WebService API with a VC:VirtualMachine parameter

Hi,

I have taken the example for executing a workflow using powershell via the Webservice API from Joerg Lew website and changed it to pass a input parameter for the Virtual Machine name.

I get no error in powershell but when I check the events for the workflow in Orchestrator I can see it has failed with the error "Validation error for the parameter 'vm'. This is using the out of the box "Start virtual machine and wait" workflow.  Is is a problem with a virtual machine name being provided as a string? I have tried using the virtual machines display name and ID.  I have provided the code below.  Can anyone help out with how to get this working?

$vcoWS = New-WebServiceProxy -Class VCO -Namespace VCO -Uri http://192.168.1.65:8280/vmware-vmo-webcontrol/webservice?WSDL
$workflows = $vcoWS.getWorkflowsWithName("Start virtual machine and wait", "vcoadmin" , "vcoadmin")
$workflow = $workflows[0]
# print out input Parameters
$workflow.inParameters
# generate Array with Input PArameters (WorkflowTokenAttribute - Objects)
$inparams = @()
# fill the array, one entry for each input parameter
$inparams += New-Object -TypeName VCO.WorkflowTokenAttribute
$inparams[0].name = "VM"
$inparams[0].type = "VC:VirtualMachine"
$inparams[0].value = "vm-113"
# ... and exectue (use $null instead on $inparams if Workflow has no input parameters
# ... und ausführen
$workflowToken = $vcoWS.executeWorkflow($workflow.id, "vcoadmin" , "vcoadmin", $inparams)

Thanks,

David

0 Kudos
1 Solution

Accepted Solutions
igorstoyanov
VMware Employee
VMware Employee
Jump to solution

Hi David,

>$inparams[0].type = "VC:VirtualMachine"

This means that the input type for this workflow is an object of type "VC:VirtualMachine". So, passing the name of the VM would not work. The expected value for such an input type is the string representation of an object, which in the case of vCO is an unique object id. The unique vCO object id looks like this:

dunes://service.dunes.ch/CustomSDKObject?id='15.23.34.34/vm-590'&dunesName='VC:VirtualMachine'

but you don't need to know this (technically, if you know the ip of the vCenter and the id of the virtual machine one can construct it but it is not recommended practice).

The proper way to find the string representation of the "VC:VirtualMachine" object with given name you need to do a few more things. I will make the example in java and it should be easy to transform it to powershell.

<java code>

QueryResult result = vcoWS.find("VC:VirtualMachine", "xpath:name=\"vm-113\"", username, password);

String stringObjectRepresentation = null;

if(result.getTotalCount() > 0) {

    FinderResult finderResult = result.getElements()[0];

     stringObjectRepresentation =  finderResult.getDunesUri();

}

</java code>

So, the stringValue should be assigned in the line:

$inparams[0].value = stringObjectRepresentation

Hope this would be helpful.

Probably, Joerg would be able to illustrate this solution with powershell later 😉

Visit http://blogs.vmware.com/orchestrator for the latest in Cloud Orchestration.

View solution in original post

0 Kudos
5 Replies
igorstoyanov
VMware Employee
VMware Employee
Jump to solution

Hi David,

>$inparams[0].type = "VC:VirtualMachine"

This means that the input type for this workflow is an object of type "VC:VirtualMachine". So, passing the name of the VM would not work. The expected value for such an input type is the string representation of an object, which in the case of vCO is an unique object id. The unique vCO object id looks like this:

dunes://service.dunes.ch/CustomSDKObject?id='15.23.34.34/vm-590'&dunesName='VC:VirtualMachine'

but you don't need to know this (technically, if you know the ip of the vCenter and the id of the virtual machine one can construct it but it is not recommended practice).

The proper way to find the string representation of the "VC:VirtualMachine" object with given name you need to do a few more things. I will make the example in java and it should be easy to transform it to powershell.

<java code>

QueryResult result = vcoWS.find("VC:VirtualMachine", "xpath:name=\"vm-113\"", username, password);

String stringObjectRepresentation = null;

if(result.getTotalCount() > 0) {

    FinderResult finderResult = result.getElements()[0];

     stringObjectRepresentation =  finderResult.getDunesUri();

}

</java code>

So, the stringValue should be assigned in the line:

$inparams[0].value = stringObjectRepresentation

Hope this would be helpful.

Probably, Joerg would be able to illustrate this solution with powershell later 😉

Visit http://blogs.vmware.com/orchestrator for the latest in Cloud Orchestration.
0 Kudos
igorstoyanov
VMware Employee
VMware Employee
Jump to solution

Forgot to mention that the example above is to get a VM by name. Since 'vm-113' from David's example looks more like id of a virtual machine, I should also point a way to get a VM by id. There is a special (much more efficient method):
<java code>
FinderResult finderResult = vcoWS.findForId("VC:VirtualMachine", "vcenter/vm-xx", username, password);
String stringObjectRepresentation = finderResult.getDunesUri();
</java code>
Visit http://blogs.vmware.com/orchestrator for the latest in Cloud Orchestration.
0 Kudos
creativeview
Contributor
Contributor
Jump to solution

Thanks Igor. I have converted this to Powershell and it works! I will clean up my code and post an example for anyone else with the same issue.

0 Kudos
creativeview
Contributor
Contributor
Jump to solution

Here's my example for Powershell

$vcoWS = New-WebServiceProxy -Class VCO -Namespace VCO -Uri http://192.168.1.65:8280/vmware-vmo-webcontrol/webservice?WSDL
#find the workflow
$workflows = $vcoWS.getWorkflowsWithName("Start virtual machine and wait", "vcoadmin" , "vcoadmin")
#find the virtual machine
$result = $vcoWS.find("VC:VirtualMachine", "xpath:name='David-Test'", "vcoadmin" , "vcoadmin")
if ($result.TotalCount -gt 0)
{
     #$result
$finderResult = $result.Elements[0]
$stringObjectRepresentation = $finderResult.DunesUri
#Write-Host $stringObjectRepresentation
}
$workflow = $workflows[0]
# print out input Parameters
$workflow.inParameters
# generate Array with Input PArameters (WorkflowTokenAttribute - Objects)
$inparams = @()
# fill the array, one entry for each input parameter
$inparams += New-Object -TypeName VCO.WorkflowTokenAttribute
$inparams[0].name = "VM"
$inparams[0].type = "VC:VirtualMachine"
$inparams[0].value = $stringObjectRepresentation
# Exectue workflow
$workflowToken = $vcoWS.executeWorkflow($workflow.id, "vcoadmin" , "vcoadmin", $inparams)

0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

Hi Guys!

Somehow I missed the party :smileycry: :smileylaugh:!

Thanks Igor and David for the update and the working code examples!

With David's permission I'll update the source on my blog (and maybe include this very common use-case to examples in some other client technologies... ... *cough* wavemaker *cough* .)

Cheers,

Joerg

PS: A final inofficial statement: Rumors harden that the Webservice-API of vCO will change to a (more powerful :smileysilly:) REST-based one in the next major version. So my suggestion: Use the examples here "as-is", but don't spend too much time to digg too deep into the current SOAP-API if you don't need to...Smiley Wink

0 Kudos