In order to facilitate my ability to configure all aspects of an ESX host automatically, I wanted to adjust the amount of memory that is assigned to the COS without having to use VI Client. The perl below is the result of that effort.
As always, I am not responsible for any damage caused to your infrastructure, I recommend you put your host in maintenance mode and move all VMs off of it before attempting any significant action upon it (there should be little risk involved with this script though…). The change will not take effect until you reboot the host (which can be accomplished with the hostops.pl sample script provided as a part of the Perl Toolkit).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
#!/usr/bin/perl -w # # cfg-cos-mem.pl - written by Andrew Sullivan, 2008-12-18 # # Example: # cfg-cos-mem.pl --server --size 512 # # The size parameter must be provided in units of MegaBytes (or MebiBytes if you want to # be proper about it...http://en.wikipedia.org/wiki/MiB). # # After this script completes (and presumably returns successful) the host MUST be # rebooted before the new settings will take effect. # use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../"; use VMware::VIRuntime; # add some additional options my %opts = ( 'size' => { type => "=i", help => "Megabytes of RAM to assign to the COS. Valid values are between 272 and 800.", required => 1, }, ); Opts::add_options(%opts); Opts::parse(); Opts::validate(&validate); Util::connect(); # connect to the server, get the HostSystem object my $server = Opts::get_option('server'); # find the HostSystem MOR via regular expression and the provided funtionality my $host = Vim::find_entity_view( view_type => 'HostSystem', filter => { 'name' => qr/($server)/i } ); # the user is asked to provide MB, but the function expects bytes, so we convert my $size = Opts::get_option('size') * 1024 * 1024; eval { # we need the HostMemorySystem MOR my $hostMemorySystem = Vim::get_view(mo_ref => $host->configManager->memoryManager); # now that we have our MOR, we simply ask it to change the value $hostMemorySystem->ReconfigureServiceConsoleReservation( 'cfgBytes' => $size ); }; # do some error checking if ($@) { if (ref($@) eq "SoapFault") { if (ref($@->detail) eq 'InvalidArgument') { Util::trace(0,"nValue for Console memory size is not valid.n"); } else { Util::trace(0, "Error: " . $@ . " "); } } else { Util::trace(0, "Error: " . $@ . " "); } } print "You MUST reboot the host before the new setting will take effect!! n"; Util::disconnect(); sub validate { my $size = Opts::get_option('size'); my $valid = 1; if ($size 800) { Util::trace(0, "Console memory size must be >= 272 and <= 800 n"); $valid = 0; } return $valid; } |
If you find any errors, bugs or stupidity on my part, please let me know and I’ll get it updated as soon as possible.