VMware Cloud Community
wsaxon
Contributor
Contributor

How to set advanced host options w/ Perl SDK?

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:

$ perl ./advoptions.pl --server vcenter --host vm1 --name NFS.SendBufferSize --value 64
Changing option NFS.SendBufferSize to 64.
SOAP Fault:
-----------
Fault string: A specified parameter was not correct.
Fault detail: InvalidArgumentFault

This occurs whether I treat the new value as an integer, a string, or use PrimType to set one or the other. It occurs whether I create a new OptionValue instance or change the value of an existing one and submit that. I've tried on a vMA instance (5.0.0.0-472630) as well as a CentOS 6.3 x86_64 host w/ perl 5.10.1 and the perl SDK build 4.1.0-254719, with identical results. Same issue whether I connect to the vCenter server or to a VM host directly.
Here is some sample code. It's similar to the script attached to the other discussion and fails the same way.
#!/usr/bin/perl -w

use strict;
use VMware::VIRuntime;

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

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 $sendBuffer = new OptionValue (key => 'NFS.SendBufferSize', value => PrimType->new('64', 'int') );
        eval { $optionManager->UpdateOptions( changedValue => [$sendBuffer] ); };

        print $@ if ($@);
}

Util::disconnect();

What am I doing wrong here? Any pointers would be appreciated.
Tags (3)
0 Kudos
3 Replies
wsaxon
Contributor
Contributor

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:

(vmodl.fault.InvalidArgument) {
   dynamicType = <unset>,
   faultCause = (vmodl.MethodFault) null,
   invalidProperty = <unset>,
   msg = "A specified parameter was not correct.
",
}

Are some options not supported for changes via script/cli?

0 Kudos
lamw
Community Manager
Community Manager

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
0 Kudos
CoinGrahamIV
Contributor
Contributor

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();

0 Kudos