vCO – Configure NTP on ESX

In this example I set the NTP Server and then check if the NTP Service is running. If not I start it.

//myhost is input parameter of type VcHostSystem
//ntpServer is input parameter of type String[] (string array)

var hostDateTimeConfig = new VcHostDateTimeConfig();
hostDateTimeConfig.ntpConfig = new VcHostNtpConfig();
hostDateTimeConfig.ntpConfig.server = ntpServer;

//Set the ntp servers
myhost.configManager.dateTimeSystem.updateDateTimeConfig(hostDateTimeConfig);

//Check if the service is already running
var hostServiceInfo = myhost.configManager.serviceSystem.serviceInfo;
for each (var hostService in hostServiceInfo.service)
{
if (hostService.label == “NTP Daemon”)
{
//if the service is not running start it
if (hostService.running == false)
{
System.log(“Starting service ” + hostService.label + ” now”);
var ntpID = myhost.configManager.dateTimeSystem.id;
host.configManager.serviceSystem.startService(“ntpd”);
}
else
{
System.log(“Service ” + hostService.label + ” is already running”);
}
}
}

Published by txusa

VMware Certified Design Expert - VCDX 92. VMware Architect, automation enthusiast.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: