Function: vCenter Host System NTP Server Toggle

by Simon Sparks · 2 February 2026

To use this function add it to the class library file named PluginVCHostSystemService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: PluginVCHostSystemService.ts

Public Function: NtpServerConfigure

public NtpServerConfigure(objVcHostSystem: VcHostSystem, arrNtpServerIp: string[]): void {

    this.NtpServerToggle(objVcHostSysteme, arrNtpServerIp);
}

Public Function: NtpServerUnconfigure

public NtpServerUnconfigure(objVcHostSysteme: VcHostSystem): void {
    
    this.NtpServerToggle(objVcHostSysteme, [])
}

Private Function: NtpServerToggle

private NtpServerToggle(objVcHostSystem: VcHostSystem, arrNtpServerIp: string[]): void {
    let objVcHostNtpConfig: VcHostNtpConfig = new VcHostNtpConfig();
    objVcHostNtpConfig.server = arrNtpServerIp

    let objVcHostDateTimeConfig: VcHostDateTimeConfig = new VcHostDateTimeConfig();
    objVcHostDateTimeConfig.ntpConfig = objVcHostNtpConfig;

    let objVcHostConfigManager: VcHostConfigManager = objVcHostSystem.configManager;

    let objVcHostDateTimeSystem: VcHostDateTimeSystem = objVcHostConfigManager.dateTimeSystem;

    objVcHostDateTimeSystem.updateDateTimeConfig(objVcHostDateTimeConfig);

    let objVcHostFirewallRulesetIpList: VcHostFirewallRulesetIpList = new VcHostFirewallRulesetIpList();
    objVcHostFirewallRulesetIpList.allIp = false;
    objVcHostFirewallRulesetIpList.ipAddress = arrNtpServerIp;

    let objVcHostFirewallRulesetRulesetSpec: VcHostFirewallRulesetRulesetSpec = new VcHostFirewallRulesetRulesetSpec();
    objVcHostFirewallRulesetRulesetSpec.allowedHosts = objVcHostFirewallRulesetIpList;

    let objVcHostFirewallSystem: VcHostFirewallSystem = objVcHostConfigManager.firewallSystem;

    objVcHostFirewallSystem.updateRuleset("ntpClient", objVcHostFirewallRulesetRulesetSpec);

    let objVcHostServiceSystem: VcHostServiceSystem = objVcHostConfigManager.serviceSystem;
    
    if (arrVcHostNtpIp.length === 0) {
        objVcHostServiceSystem.updateServicePolicy("ntpd", "off");
        objVcHostServiceSystem.stopService("ntpd");
    } else if (arrVcHostNtpIp.length > 0) {
        objVcHostServiceSystem.updateServicePolicy("ntpd", "on");
        objVcHostServiceSystem.startService("ntpd");
    }
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like