Hi Guys,
I'm trying to get a scriptable task to start SSH on an ESXi host and its not quite happening. I'll try to explain briefly what I've done so far.
So I've created an attribute / array of ESXi hosts and created an input to use the array as predefined objects. Next I have a scriptable task as follows where its going wrong.
// Start SSH service on ESXi host
var myVcHostServiceSystem = new VcHostServiceSystem() ;
myVcHostServiceSystem.startService("TSM-SSH")
System.log ("Starting SSH service on: " + host.name);
This keeps on failing saying
Unable to create object : VcHostServiceSystem : com.vmware.vmo.plugin.vi4.model.VimHostServiceSystem
Can anybody shed some light?
Thanks
Mr G
Hi,
Well, the error says it VcHostServiceSystem represents ServiceSystem managed object, and managed objects shouldn't be directly instantiated in scripting using the Javascript's operator new syntax:
var myVcHostServiceSystem = new VcHostServiceSystem(); // won't work for managed objects
Instead, you should fetch a reference to the managed objects. For this particular case, it looks like you can get it from the host, using the following scripting code:
var myVcHostServiceSystem = host.configManager.serviceSystem; // 'host' is your ESXi host object of type VC:HostSystem / VcHostSystem
Hi,
Well, the error says it VcHostServiceSystem represents ServiceSystem managed object, and managed objects shouldn't be directly instantiated in scripting using the Javascript's operator new syntax:
var myVcHostServiceSystem = new VcHostServiceSystem(); // won't work for managed objects
Instead, you should fetch a reference to the managed objects. For this particular case, it looks like you can get it from the host, using the following scripting code:
var myVcHostServiceSystem = host.configManager.serviceSystem; // 'host' is your ESXi host object of type VC:HostSystem / VcHostSystem
Just to add to this thread, I actually blogged about this 5 years ago and the code is still valid
Manage Services on your ESXi hosts with vCO