VMware Explore happening NOW!

[Orchestrator] Configure Host Time Settings

In looking around vCO, at least in the default plug-in, there was not a good variety of workflows for configuring hosts. This workflow, will set the NTP server on a host.

Schema

Not a very creative schema, and for good reason. Also note, it is designed to work on a single host at a time. If you want to do all hosts, you can include this workflow inside a larger one to process a number of hosts:

image

This workflow has only a single input of type Vc:HostSystem and a single attribute, a string, for the NTP server.

Code

This is where things get a bit interesting. Using Onyx I was able to capture the basics of the JavaScript. I then beat my head against the wall getting it translated. Thanks to Joerg Lew of vcoportal.de I got the last bits I needed to make it successful:

// ——- UpdateDateTimeConfig ——-
var config = new VcHostDateTimeConfig();
config.timeZone = “UTC”;
config.ntpConfig = new VcHostNtpConfig();
var ntpServerArray = new Array()
ntpServerArray.push(ntpServer);
config.ntpConfig.server = ntpServerArray;
config.ntpConfig.server[0] = ntpServer;

// ——- Update Config ——-
var dts = VMHost.configManager.dateTimeSystem;
dts.updateDateTimeConfig(config);

// ——- EnableRuleset ——-
var ruleset = VMHost.configManager.firewallSystem;
ruleset.enableRuleset(“ntpClient”);

// ——- UpdateServicePolicy ——-
var serviceSystem = VMHost.configManager.serviceSystem;
serviceSystem.updateServicePolicy(“ntpd”, “automatic”);  // HostServiceSystem

// ——- StartService ——-
serviceSystem.startService(“ntpd”);  // HostServiceSystem

The first block builds the configuration that gets sent along to the host. The second block actually sends said configuration (also, it’s where I threw some derp on using nested managed objects… suffice it to say, it works now and JavaScript is not PowerCLI). The third set enables the NTP Client in the ESXi firewall. The fourth and fifth blocks handle setting NTP to start with the host and turning it on now.

In Action

There aren’t many exciting ways to show a workflow in action and using screenshots always feels like those cooking shows “baked at 450 for 3 hours” or so. But, here it goes:

Running:

image

Host Before:

image

Host After:

image

Download

This workflow can be pulled down from here. If you have any questions, comments, enhancements, etc. Drop me a line.