I am trying to use some tasks from the vCenter library and the vCloud Director library but they have different variable types:
Specifically I have a work flow that instantiates a vapp based upon todays date, after it instantiates I would like to run a program in each vm guest.
The vCloud Director task "Instantiate a vApp" has an out parameter "vappOut" of type "vCloud:VApp" but getAllVMsofVApp has an input parameter of "vapp" of type "VC:VirtualApp"
I had to reconfigure my plugin to point to system instead of the organization. I am able to execute the script on the guest now.
Actually I just found there is a getVmsFromVApp task in the vCloud Director library, now the next question is how to check if each vm inside the vapp is on the network. Looks like this task generates an Array/Vcloud:VM
I found I could get the status of the virtual machines inside the vapp but when I try to run a process on the guest vm I get an error that vm.sdkconnection is undefined. the vapp is defined inside the vcloud director.
the following code results in:
[2013-07-23 14:50:13.809] [I] Name:win2k8r2
[2013-07-23 14:50:13.813] [I] Status:4
[2013-07-23 14:50:13.828] [I] Href:https://<<snipped>>/api/vApp/vm-a09f3eb2-7d38-4896-8fce-c1181f83902c
[2013-07-23 14:50:13.853] [I] StatusDesc:The object is powered on.
[2013-07-23 14:50:13.857] [I] TypeError: Cannot read property "guestOperationsManager" from undefined (<<snipped>>)
for each (var vm in ArrayOfVms) {
Server.log("Name:"+vm.name);
System.log("Name:"+vm.name);
Server.log("Status:"+vm.status);
System.log("Status:"+vm.status);
Server.log("Href:"+vm.href);
System.log("Href:"+vm.href);
Server.log("StatusDesc:"+vm.vmStatusDescription);
System.log("StatusDesc:"+vm.vmStatusDescription);
var host = vm.sdkConnection;
var guestOperationsManager = host.guestOperationsManager;
var guestAuth = new VcNamePasswordAuthentication();
guestAuth.username = snipped
guestAuth.password = snipped
guestAuth.interactiveSession = true;
var guestProgramSpec = new VcGuestProgramSpec();
guestProgramSpec.programPath = "C:\Users\Administrator\Downloads\<<snipped>>.bat";
guestProgramSpec.arguments = arguments;
guestProgramSpec.workingDirectory = "C:\Users\Administrator\Downloads";
guestProgramSpec.envVariables = environment;
var processManager = guestOperationsManager.processManager;
result = processManager.startProgramInGuest(vm , guestAuth , guestProgramSpec);
System.log("Ran workflow on" + vm.name);
}
Your vm is a vCloud:VM.
You need to get it converted to a VC:virtualMachine using the linked code before doing var host = vm.sdkConnection;
Based upon this I added three parameters to my script: vcenter of type VC:SdkConnection (set to my vcenter) , newvm of type VC:VirtualMachine (unset) and vcloudvm of type vCloud:VM (unset) and modified it as such but I am getting the following error:
[2013-07-24 07:22:59.858] [I] Vim Object Reference Not Found (Dynamic Script Module name : getVCenterVm#2)
for each (var vcloudvm in ArrayOfVms) {
Server.log("Name:"+vcloudvm.name);
System.log("Name:"+vcloudvm.name);
Server.log("Status:"+vcloudvm.status);
System.log("Status:"+vcloudvm.status);
Server.log("Href:"+vcloudvm.href);
System.log("Href:"+vcloudvm.href);
Server.log("StatusDesc:"+vcloudvm.vmStatusDescription);
System.log("StatusDesc:"+vcloudvm.vmStatusDescription);
newvm = System.getModule("com.vmware.pso.library.vcd").getVCenterVm(vcloudvm,vcenter) ;
var host = actionResult.sdkConnection;
var guestOperationsManager = host.guestOperationsManager;
var guestAuth = new VcNamePasswordAuthentication();
snipped
guestAuth.interactiveSession = true;
var guestProgramSpec = new VcGuestProgramSpec();
guestProgramSpec.programPath = "C:\Users\Administrator\Downloads\.bat";
guestProgramSpec.arguments = arguments;
guestProgramSpec.workingDirectory = "C:\Users\Administrator\Downloads";
guestProgramSpec.envVariables = environment;
var processManager = guestOperationsManager.processManager;
result = processManager.startProgramInGuest(vm , guestAuth , guestProgramSpec);
System.log("Ran workflow on" + vm.name);
}
schema:
I had to reconfigure my plugin to point to system instead of the organization. I am able to execute the script on the guest now.