I want to write a script that will let me set advanced host options, so I can roll them out to all of my hosts in one go vs. touching each host. I have the Enterprise license so I don't have host profiles - scripts are the best option for me. I'm trying to use the UpdateOptions() method to an OptionManager object to make this happen.
The problem I'm having is identical to the one in this discussion: http://communities.vmware.com/message/686401, but the accepted solution is not working for me. Neither my own code nor the script attached to the other discussion will work.
For example, if I try to change the value of NFS.SendBufferSize to any valid, I get a response like this:
I think there is more going on here than a problem w/ a script. If I try to set this by hand on the ESXi machine using vim-cmd, like so:
~ # vim-cmd hostsvc/advopt/update NFS.SendBufferSize int 64
I get a similar error:
Are some options not supported for changes via script/cli?
Take a look at the canned vicfg-advcfg script which is part of the vCLI/vSphere SDK for Perl script that already implements this feature, you can use that script as it refercences the VIExt.pm module
which looks like
sub set_advoption {
my ($ao, $key, $set) = @_;
my ($optDef, $opt) = get_advoption_by_key($ao, $key);
if (defined($optDef) && defined($opt)) {
my $valType = get_advoption_type(ref $optDef->optionType);my $val = new PrimType($set, $valType);
$opt->{value} = $val;$ao->UpdateOptions(changedValue => [$opt]);
return $optDef->label;
} else {
return undef;
}
}
vicfg-cfg-advcfg --server vcenter50-4 --username root --vihost vesxi50-4.primp-industries.com -s 64 NFS.SendBufferSize
Value of Socket send buffer size is 64
I use the VMware::VIExt package for this:
-----------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use VMware::VIRuntime;
use VMware::VIExt;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
my $option = "NFS.SendBufferSize";
my $newValue = "64";
Opts::parse();
Opts::validate();
Util::connect();
my $entities = Vim::find_entity_views(
view_type => 'HostSystem',
properties => ['configManager'],
);
foreach my $entity (@$entities) {
my $optionManager = Vim::get_view(mo_ref => $entity->configManager->advancedOption);
my ($name, $value) = VIExt::get_advoption($optionManager, $option);
print "Current Option $name = $value\n";
VIExt::set_advoption($optionManager, $option, $newValue);
$optionManager->update_view_data();
($name, $value) = VIExt::get_advoption($optionManager, $option);
print "Updated Option $name = $value\n";
print $@ if ($@);
}
Util::disconnect();