VMware Cloud Community
Nainz
Contributor
Contributor

Convert VM name from String(input) to vCloud:VM(output)

Hi,

I know how to convert the VM name from string to VC:VirtualMachine for vCenter and in the same way I want to convert the virtual machine name from string (input) to vCloud:VM(output) for vCD.

Please help me.

0 Kudos
11 Replies
frefal
Enthusiast
Enthusiast

Heres an example.

Inputs:

host (vcloud:host)

vdc (vcloud:vdc)

vappname (string)

vmname (string)

Output:

vcdVM (vcloud:VM)

var queryService = host.getQueryService();

var expression = new VclExpression(VclQueryVMField.CONTAINERNAME, vappname, VclExpressionType.EQUALS);

  var filter1 = new VclFilter(expression);

  var filters = [filter1];

var expression2 = new VclExpression(VclQueryVMField.VDC, vdc.href, VclExpressionType.EQUALS);

  var filter2 = new VclFilter(expression2);

  filters.push(filter2);

var expression3 = new VclExpression(VclQueryVMField.NAME, vmname, VclExpressionType.EQUALS);

  var filter3 = new VclFilter(expression3);

  filters.push(filter3);

var expression4 = new VclExpression(VclQueryVMField.ISVAPPTEMPLATE, false, VclExpressionType.EQUALS);

  var filter4 = new VclFilter(expression4);

  filters.push(filter4);

var filter = new VclFilter(filters,VclFilterType.AND);

var params = new VclQueryParams();

  params.setFilter(filter);

var resultSet = queryService.queryRecords(VclQueryRecordType.ADMINVM, params);

while (resultSet != null)  {

     var records = resultSet.getRecords(new VclQueryResultAdminVMRecord());

     for (i = 0; i < records.length; i++) {

  var vmReference = new VclReference();         

  vmReference.href = records[i].href; 

  vmReference.name = records[i].name; 

  vmReference.type = records[i].type; 

  var vm = host.getEntityByReference(VclFinderType.VM, vmReference);

  vcdVM = vm;

     }

     resultSet = resultSet.getNextPage();

}

0 Kudos
Nainz
Contributor
Contributor


Hey Thanks Smiley Happy

I am getting error as:-

TypeError: Cannot call method "getQueryService" of null (Workflow:vmConversionvCD / Scriptable task (item1)#54823)

Smiley Sad

0 Kudos
frefal
Enthusiast
Enthusiast

No value in the host variable?

0 Kudos
Nainz
Contributor
Contributor

Again error :-

This operation is denied. (Workflow:vmConversionvCD / Scriptable task (item1)#38)

0 Kudos
frefal
Enthusiast
Enthusiast

Is the VCD public rest api base url in VCD / administration / Public Addresses identical to the one you entered in the orchestrator vcloud plugin config?

0 Kudos
Nainz
Contributor
Contributor

frefal can you please explain this point ... I am not getting what exactly you are talking about ..

0 Kudos
frefal
Enthusiast
Enthusiast

You have a HTTPS address entered in vCloud Director under administration / Public Addresses. The box is called "VCD public rest api base url".

When you configured the vCloud Director plug-in in Orchestrator, in the Orchestrator configuration page, did you enter the same address to make the connection from orchestrator to VCD?

Missmatch might be the reason for you problem. For example that you have https://vcd in one place and https://vcd.example.org in the other.

0 Kudos
Nainz
Contributor
Contributor

okay ...

Yeah I checked the urls and both are same, vco url is having the default port no "443"

Smiley Sad what next we can check ..

Thanks Smiley Happy

0 Kudos
frefal
Enthusiast
Enthusiast

The account you use in the orchestrator vcloud plug-in actually have the correct permissions to perform the wanted actions in vcd?

Are you connecting against the System organization, or maybe against another, wrong organization?

0 Kudos
Nainz
Contributor
Contributor

I think those things are fine as I am able to run the workflows like Change the number of CPUs, Change memory capacity, power on/off VMs .. . etc etc  successfully

0 Kudos
Nainz
Contributor
Contributor

And I am connecting against the child organization.

0 Kudos