rkuechler
Contributor
Contributor

vRO 8.6.1: Change value(s) in vCenter Host "Advaned System Settings"?

Jump to solution

Hi
I stuck in a new problem, probably an easy one for an expert...  😟

I simply want do change an Advanced Systems Setting of an ESXi host. One can access these in the vCenter WebGUI -> Host -> Configure -> Advanced System Settings. That's all. Not much, isn't it?

But as long as I search and google, I cannot find a way that I - as a beginner - can understand. Isn't there simply a predefined workflow or action which can do this? Even in the vRO API Explorer I didn't find a solution.

Thanks for every hint.
Regards
Roman

0 Kudos
1 Solution

Accepted Solutions
eoinbyrne
Expert
Expert

Hi, No problem, always happy to help

Anyway, I wrote the below in a 7.6 client. I've not tested the update part but it looks like it should be feasiible. The 'printAdvancedOptions' function works fine on the setup I was connected to but I didn't want to update anything as it's in use.

You'll need to pass in the VcHostSystem as an input

// helper to create an Option value and store it on the update list
function addOptionUpdate(name, value, updateList)
{
	// 1. create a new VcOptionValue instance with the name/value you want it to have
	var myNewOptionValue = new VcOptionValue(name, value);
	
	// 2. add it to the array
	updateList.push(myNewOptionValue)	
}

// Print the contents of advanced options
function printAdvancedOptions(optionManager)
{
	for each(var option in optionManager.setting)
	{
		System.log(option.key + " :: " + option.getValue());
	}
}


var hostConfigManager = hostSystem.configManager;
var hostAdvancedOptionManager = hostConfigManager.advancedOption;


// List option names + values this way - do before and after & compare logs to make sure only the updates were changed
System.log("Advanced options for Host " + hostSystem.name);
printAdvancedOptions(hostAdvancedOptionManager)

// Now update options like this

// create an empty array to hold the option values to update. This will be passed to the method call later
var myUpdatedOptions = [];

// use the helper function to handle creating & adding to the list
addOptionUpdate("Syslog.global.logHost", "tcp://whatevertheloghostnameis.subdomain.domain:portnumber", myUpdatedOptions);
//addOptionUpdate(<option name>, <option value>, myUpdatedOptions); // add as many as you need

// all updates ready, call the method to update
// wrap in try/catch just in case 
try
{
	hostAdvancedOptionManager.updateOptions(myUpdateOptions);
}
catch(error)
{
	throw "Encountered an ERROR updating the Host options for Host  " + hostSystem.name + " - Error was " + error;
}

System.log("Options updated!");

// List them again to verify
System.log("Advanced options for Host " + hostSystem.name);
printAdvancedOptions(hostAdvancedOptionManager)

 

View solution in original post

6 Replies
eoinbyrne
Expert
Expert

Hi again 🙂

If you look here - https://www.vroapi.com/Class/VC/6.5.0/VcHostConfigManager

eoinbyrne_0-1646835471028.png

 

Inside this scripting class you can see the Options are stored in the highlighted member

eoinbyrne_1-1646835551357.png

The methods below can query and set the options for the class.

eoinbyrne_2-1646835638655.png

You can get the VcHostConfigManager from here on the VcHostSystem

eoinbyrne_3-1646835720230.png

 

rkuechler
Contributor
Contributor

Hi again as well  😀

You have a lot of work to do with me... 

I was able to instantiate an object from the vCenter plugin. From there I could access the subclasses "VcHostConfigManger", and then "VcOptionManager". But due to a lack of sufficient JavaScript experience, it's difficult for me how to use the "updateOptions(VcOptionsValue[] arg0)" method within this class?

Could you kindly show me how I can change the value (the URL to the syslog server) of the "Syslog.global.logHost" key in the advanced systems settings, for example? See the screenshot:

rkuechler_0-1646897565305.png

Regards

 

0 Kudos
eoinbyrne
Expert
Expert

Hi, No problem, always happy to help

Anyway, I wrote the below in a 7.6 client. I've not tested the update part but it looks like it should be feasiible. The 'printAdvancedOptions' function works fine on the setup I was connected to but I didn't want to update anything as it's in use.

You'll need to pass in the VcHostSystem as an input

// helper to create an Option value and store it on the update list
function addOptionUpdate(name, value, updateList)
{
	// 1. create a new VcOptionValue instance with the name/value you want it to have
	var myNewOptionValue = new VcOptionValue(name, value);
	
	// 2. add it to the array
	updateList.push(myNewOptionValue)	
}

// Print the contents of advanced options
function printAdvancedOptions(optionManager)
{
	for each(var option in optionManager.setting)
	{
		System.log(option.key + " :: " + option.getValue());
	}
}


var hostConfigManager = hostSystem.configManager;
var hostAdvancedOptionManager = hostConfigManager.advancedOption;


// List option names + values this way - do before and after & compare logs to make sure only the updates were changed
System.log("Advanced options for Host " + hostSystem.name);
printAdvancedOptions(hostAdvancedOptionManager)

// Now update options like this

// create an empty array to hold the option values to update. This will be passed to the method call later
var myUpdatedOptions = [];

// use the helper function to handle creating & adding to the list
addOptionUpdate("Syslog.global.logHost", "tcp://whatevertheloghostnameis.subdomain.domain:portnumber", myUpdatedOptions);
//addOptionUpdate(<option name>, <option value>, myUpdatedOptions); // add as many as you need

// all updates ready, call the method to update
// wrap in try/catch just in case 
try
{
	hostAdvancedOptionManager.updateOptions(myUpdateOptions);
}
catch(error)
{
	throw "Encountered an ERROR updating the Host options for Host  " + hostSystem.name + " - Error was " + error;
}

System.log("Options updated!");

// List them again to verify
System.log("Advanced options for Host " + hostSystem.name);
printAdvancedOptions(hostAdvancedOptionManager)

 

rkuechler
Contributor
Contributor

Great! That works fine.  😊

A question: why do I have to pass the instance "myNewOptionValue" first in an array "myUpdateOptions", and then second have to use this array as the argument in the update method ".updateOptions(myUpdateOptions)"?

 

hostAdvancedOptionManager.updateOptions(myUpdateOptions);

 

 

I have simplified your code in some "quick'n'dirty" lines to demonstrate my question:
While this works fine:...

 

var hostConfigManager = in_VcHostSystem.configManager;
var hostAdvancedOptionManager = hostConfigManager.advancedOption;

var myUpdatedOptions = [];
var myNewOptionValue = new VcOptionValue("Syslog.global.logHost", "ssl://syslog.service.domain.com:514");
myUpdatedOptions.push(myNewOptionValue);
hostAdvancedOptionManager.updateOptions(myUpdatedOptions);

 


...this doesn't work at all:

 

var hostConfigManager = in_VcHostSystem.configManager;
var hostAdvancedOptionManager = hostConfigManager.advancedOption;

var myNewOptionValue = new VcOptionValue("Syslog.global.logHost", "ssl://syslog.service.domain.com:514");
hostAdvancedOptionManager.updateOptions(myNewOptionValue);

 

 

 

 

 

What makes the difference? Why the "detour" via an array?
Regards

 

 

0 Kudos
eoinbyrne
Expert
Expert

The reason we need to use the array there is just because that's the argument signature of the method provided by VMware for this 🙂

eoinbyrne_0-1646995697245.png

It expects the array in order to permit the caller to update 'one or more' options in the same call. From a programming perspective, this approach is entirely normal (in my past jobs as a Java developer, we'd normally use Lists / Collection classes to provide for the same capability to pass lists of things around).

The simplest way I can say this is that if your API / SDK supports an array/list/collection of objects of the same type like this, then the single update is just the trivial case of many updates & you can cater for both with one method/function.

It would be entirely possible for VMware to have provided two methods here

udpateOptions(VcOptionValue arg0) // this is the single case

VS

updateOptions(VcOptionValue[] arg0) // this takes many

But, from a design perspective having two distinct calls for the same thing leads to risks as it could lead to two different implementations of the same functionality and therefore with possibly different bugs and test requirements. It's better design to collapse this into the 'one or many' like this and remove those risks (& reduce the work required to dev/test/release!)

Hope that made sense. I realize that wrapping your head around arrays & objects can be a little daunting but you'll find that once you get used to it you'll notice it becomes quite comfortable and even 'normal' in vRO code 🙂

 

rkuechler
Contributor
Contributor

Thank you for your detailed explanation.
I don't take it for granted that anyone would take that much time to help others.

Regards

0 Kudos