VMware {code} Community
rickyelqasem
Enthusiast
Enthusiast

I need an c# example for Host Config

I need to change a host(ESXi) setting but what's reconfigTask method for Host config?

HostConfigInfo hostconfig = new HostConfigInfo();

hostconfig.service.service[0].running = false;

_service.?

Ricky El-Qasem VCI/VCP - MCSE - RHCT
0 Kudos
2 Replies
lamw
Community Manager
Community Manager

Ricky,

There is no "reconfigTask" method for a HostSystem and from your snippet of code it looks like you're trying to manipulate the services running with an ESX(i) host, correct? Depending on what you're trying to change, you'll need to use the appropriate managed object manager to do so.

For instance, if you need to make changes to the "Services", you'll need to use HostServiceManager - http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.host.ServiceSystem.html and there are 6 associated methods - RefreshServices, RestartService, StartService, StopService, UninstallService, UpdateServicePolicy

I would highly recommend that you get familiar with the vSphere API reference guide as it provides you with all the information you need to perform various operations against your vSphere environment whether it's vCenter and/or ESX(i) hosts - http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/index.html

If you're new to vSphere APIs or need a refresher, I would recommend taking a look at this document - http://communities.vmware.com/docs/DOC-7270

I would also recommend you take a look at the VMTN Code Central, I know there isn't a whole lot of C# examples but there are a few that you can use as reference - http://communities.vmware.com/community/developer/codecentral

Once you understand where you need to look for certain objects/methods, the implementation should be pretty straight forward in which SDK binding you decide to use. There is also a "search" functionality that comes in very useful in the API reference and also using the vSphere MOB also helps you visulized the vSphere API

0 Kudos
rickyelqasem
Enthusiast
Enthusiast

I'm almost close. The one problem I have now is I cannot get at the service ID. Following the API refernce I think I need an instance of HostConfigSpec which I do not seem to have this option. The code I have so far is:

HostConfigManager hostConfigManager = (HostConfigManager)getObjectProperty(mor, "configManager");

ManagedObjectReference hostserviceSystem = hostConfigManager.serviceSystem;

HostServiceInfo hostserviceinfo = new HostServiceInfo() { };

hostserviceinfo = (HostServiceInfo)getObjectProperty(hostserviceSystem, "serviceInfo");

hostserviceinfo.service[0].policy = "off";

but I need th serviceID to update/stop the service.

My is Type HostConfigSpec missing?

Ricky El-Qasem VCI/VCP - MCSE - RHCT
0 Kudos