Author: arkurth
Date: Thu Sep  1 19:37:28 2011
New Revision: 1164226

URL: http://svn.apache.org/viewvc?rev=1164226&view=rev
Log:
VCL-506
Added subroutines to utils.pm: update_computer_procnumber, 
update_computer_procspeed, and update_computer_ram. Added get_cpu_core_count, 
get_cpu_speed, and get_total_memory to Linux.pm, vSphere_SDK.pm, and 
VIM_SSH.pm. Added code to VMware.pm to call these and update the database 
periodically for VM hosts.

Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
    
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
    
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
    
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
    incubator/vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm?rev=1164226&r1=1164225&r2=1164226&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Thu Sep  1 
19:37:28 2011
@@ -2976,7 +2976,7 @@ sub enable_dhcp {
                return;
        }
 
-       my $computer_node_name   = $self->data->get_computer_node_name();
+       my $computer_node_name = $self->data->get_computer_node_name();
        
        my $interface_name_argument = shift;
        my @interface_names;
@@ -3031,6 +3031,141 @@ EOF
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 get_cpu_core_count
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the quantitiy of CPU cores the computer has.
+
+=cut
+
+sub get_cpu_core_count {
+       my $self = shift;
+       if (ref($self) !~ /VCL::Module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $computer_node_name = $self->data->get_computer_node_name();
+       
+       my $command = "cat /proc/cpuinfo";
+       my ($exit_status, $output) = $self->execute($command);
+       
+       if (!defined($output)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to retrieve CPU info from 
$computer_node_name");
+               return;
+       }
+       
+       # Get the number of 'processor :' lines and the 'cpu cores :' and 
'siblings :' values from the cpuinfo output
+       my $processor_count = scalar(grep(/^processor\s*:/, @$output));
+       if (!$processor_count) {
+               notify($ERRORS{'WARNING'}, 0, "unable to determine 
$computer_node_name CPU core count, output does not contain any 'processor :' 
lines:\n" . join("\n", @$output));
+               return;
+       }
+       my ($cpu_cores) = map { $_ =~ /cpu cores\s*:\s*(\d+)/ } @$output;
+       $cpu_cores = 1 unless $cpu_cores;
+       
+       my ($siblings) = map { $_ =~ /siblings\s*:\s*(\d+)/ } @$output;
+       $siblings = 1 unless $siblings;
+       
+       # The actual CPU core count can be determined by the equation:
+       my $cpu_core_count = ($processor_count * $cpu_cores / $siblings);
+       
+       # If hyperthreading is enabled, siblings will be greater than CPU cores
+       # If hyperthreading is not enabled, they will be equal
+       my $hyperthreading_enabled = ($siblings > $cpu_cores) ? 'yes' : 'no';
+       
+       notify($ERRORS{'DEBUG'}, 0, "retrieved $computer_node_name CPU core 
count: $cpu_core_count
+                        cpuinfo 'processor' line count: $processor_count
+                        cpuinfo 'cpu cores': $cpu_cores
+                        cpuinfo 'siblings': $siblings
+                        hyperthreading enabled: $hyperthreading_enabled");
+       
+       return $cpu_core_count;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 get_cpu_speed
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the speed of the computer's CPUs in MHz.
+
+=cut
+
+sub get_cpu_speed {
+       my $self = shift;
+       if (ref($self) !~ /VCL::Module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $computer_node_name = $self->data->get_computer_node_name();
+       
+       my $command = "cat /proc/cpuinfo";
+       my ($exit_status, $output) = $self->execute($command);
+       
+       if (!defined($output)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to retrieve CPU info from 
$computer_node_name");
+               return;
+       }
+       
+       my ($mhz) = map { $_ =~ /cpu MHz\s*:\s*(\d+)/ } @$output;
+       if ($mhz) {
+               $mhz = int($mhz);
+               notify($ERRORS{'DEBUG'}, 0, "retrieved $computer_node_name CPU 
speed: $mhz MHz");
+               return $mhz;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to determine 
$computer_node_name CPU speed CPU speed, 'cpu MHz :' line does not exist in the 
cpuinfo output:\n" . join("\n", @$output));
+               return;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 get_total_memory
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the computer's total memory capacity in MB.
+
+=cut
+
+sub get_total_memory {
+       my $self = shift;
+       if (ref($self) !~ /VCL::Module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $computer_node_name = $self->data->get_computer_node_name();
+       
+       my $command = "dmesg | grep Memory:";
+       my ($exit_status, $output) = $self->execute($command);
+       
+       if (!defined($output)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to retrieve memory info 
from $computer_node_name");
+               return;
+       }
+       
+       # Output should look like this:
+       # Memory: 1024016k/1048576k available (2547k kernel code, 24044k 
reserved, 1289k data, 208k init)
+       my ($memory_kb) = map { $_ =~ /Memory:.*\/(\d+)k available/ } @$output;
+       if ($memory_kb) {
+               my $memory_mb = int($memory_kb / 1024);
+               notify($ERRORS{'DEBUG'}, 0, "retrieved $computer_node_name 
total memory capacity: $memory_mb MB");
+               return $memory_mb;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to determine 
$computer_node_name total memory capacity from command: '$command', output:\n" 
. join("\n", @$output));
+               return;
+       }
+}
+
+##/////////////////////////////////////////////////////////////////////////////
+
 1;
 __END__
 

Modified: 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm?rev=1164226&r1=1164225&r2=1164226&view=diff
==============================================================================
--- 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
 (original)
+++ 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VIM_SSH.pm
 Thu Sep  1 19:37:28 2011
@@ -1791,6 +1791,144 @@ sub snapshot_exists {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 get_cpu_core_count
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the quantitiy of CPU cores the VM host has.
+
+=cut
+
+sub get_cpu_core_count {
+       my $self = shift;
+       if (ref($self) !~ /VCL::Module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $vmhost_hostname = $self->data->get_vmhost_hostname();
+       
+       my $vim_cmd_arguments = "hostsvc/hosthardware";
+       my ($exit_status, $output) = $self->_run_vim_cmd($vim_cmd_arguments);
+       return if !$output;
+       
+       # The CPU info should be contained in the output:
+       #       cpuInfo = (vim.host.CpuInfo) {
+       #      dynamicType = <unset>,
+       #      numCpuPackages = 2,
+       #      numCpuCores = 8,
+       #      numCpuThreads = 8,
+       #      hz = 2000070804,
+       #   },
+       
+       my ($cpu_cores_line) = grep(/^\s*numCpuCores\s*=/i, @$output);
+       if (!$cpu_cores_line) {
+               notify($ERRORS{'WARNING'}, 0, "unable to determine VM host 
$vmhost_hostname CPU core count, output does not contain a 'numCpuCores =' 
line:\n" . join("\n", @$output));
+               return;
+       }
+       elsif ($cpu_cores_line =~ /(\d+)/) {
+               my $cpu_core_count = $1;
+               notify($ERRORS{'DEBUG'}, 0, "retrieved VM host $vmhost_hostname 
CPU core count: $cpu_core_count");
+               return $cpu_core_count;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to determine VM host 
$vmhost_hostname CPU core count from line: $cpu_cores_line");
+               return;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 get_cpu_speed
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the speed of the VM host's CPUs in MHz.
+
+=cut
+
+sub get_cpu_speed {
+       my $self = shift;
+       if (ref($self) !~ /VCL::Module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $vmhost_hostname = $self->data->get_vmhost_hostname();
+       
+       my $vim_cmd_arguments = "hostsvc/hosthardware";
+       my ($exit_status, $output) = $self->_run_vim_cmd($vim_cmd_arguments);
+       return if !$output;
+       
+       # The CPU info should be contained in the output:
+       #       cpuInfo = (vim.host.CpuInfo) {
+       #      dynamicType = <unset>,
+       #      numCpuPackages = 2,
+       #      numCpuCores = 8,
+       #      numCpuThreads = 8,
+       #      hz = 2000070804,
+       #   },
+       
+       my ($hz_line) = grep(/^\s*hz\s*=/i, @$output);
+       if (!$hz_line) {
+               notify($ERRORS{'WARNING'}, 0, "unable to determine VM host 
$vmhost_hostname CPU speed, output does not contain a 'hz =' line:\n" . 
join("\n", @$output));
+               return;
+       }
+       elsif ($hz_line =~ /(\d+)/) {
+               my $mhz = int($1 / 1000000);
+               notify($ERRORS{'DEBUG'}, 0, "retrieved VM host $vmhost_hostname 
CPU speed: $mhz MHz");
+               return $mhz;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to determine VM host 
$vmhost_hostname CPU speed from line: $hz_line");
+               return;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 get_total_memory
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the VM host's total memory capacity in MB.
+
+=cut
+
+sub get_total_memory {
+       my $self = shift;
+       if (ref($self) !~ /VCL::Module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $vmhost_hostname = $self->data->get_vmhost_hostname();
+       
+       my $vim_cmd_arguments = "hostsvc/hosthardware";
+       my ($exit_status, $output) = $self->_run_vim_cmd($vim_cmd_arguments);
+       return if !$output;
+       
+       # The following line should be contained in the output:
+       #        memorySize = 17178869760,
+       
+       my ($memory_size_line) = grep(/^\s*memorySize\s*=/i, @$output);
+       if (!$memory_size_line) {
+               notify($ERRORS{'WARNING'}, 0, "unable to determine VM host 
$vmhost_hostname total memory capacity, output does not contain a 'memorySize 
=' line:\n" . join("\n", @$output));
+               return;
+       }
+       elsif ($memory_size_line =~ /(\d+)/) {
+               my $memory_mb = int($1 / 1024 / 1024);
+               notify($ERRORS{'DEBUG'}, 0, "retrieved VM host $vmhost_hostname 
total memory capacity: $memory_mb MB");
+               return $memory_mb;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to determine VM host 
$vmhost_hostname total memory capacity from line: $memory_size_line");
+               return;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 DESTROY
 
  Parameters  : none

Modified: 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm?rev=1164226&r1=1164225&r2=1164226&view=diff
==============================================================================
--- 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm 
(original)
+++ 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm 
Thu Sep  1 19:37:28 2011
@@ -171,6 +171,16 @@ our %VM_OS_CONFIGURATION = (
        },
 );
 
+=head2 $VM_MINIMUM_MEMORY_MB
+
+ Data type   : string
+ Description : Minimum amount of memory in megabytes to be allocated to any VM.
+
+=cut
+
+our $VM_MINIMUM_MEMORY_MB = 512;
+
+
 =head2 $VSPHERE_SDK_PACKAGE
 
  Data type   : string
@@ -243,12 +253,12 @@ sub initialize {
        }
        
        my $request_state_name = $self->data->get_request_state_name();
-       
        my $vm_computer_name = $self->data->get_computer_node_name();
-       
        my $vmhost_computer_name = $vmhost_data->get_computer_node_name();
        my $vmhost_image_name = $vmhost_data->get_image_name();
        my $vmhost_os_module_package = 
$vmhost_data->get_image_os_module_perl_package();
+       my $vmhost_lastcheck_time = 
$vmhost_data->get_computer_lastcheck_time(0);
+       my $vmhost_computer_id = $self->data->get_vmhost_computer_id();
        
        my $vmware_api;
        
@@ -308,13 +318,6 @@ sub initialize {
                return;
        }
        
-       # Configure the SSH authorized_keys file to persist through reboots if 
the VM host is running VMware ESXi
-       # This shouldn't need to be done more than once, only call this if the 
state is 'new' to reduce the number of times it is called
-       notify($ERRORS{'DEBUG'}, 0, "product: $vmhost_product_name, OS object: 
" . ref($self->{vmhost_os}));
-       if ($request_state_name eq 'new' && ref($self->{vmhost_os}) =~ /Linux/i 
&& $vmhost_product_name =~ /ESXi/) {
-               $self->configure_vmhost_dedicated_ssh_key();
-       }
-       
        # Make sure the vmx and vmdk base directories can be accessed
        my $vmx_base_directory_path = $self->get_vmx_base_directory_path();
        if (!$vmx_base_directory_path) {
@@ -339,6 +342,80 @@ sub initialize {
                return;
        }
        
+       # Retrieve the VM host's hardware info if:
+       #    -request state is 'timeout', don't slow down user reservations
+       #    -VM host computer.lastcheck is NULL or more than 30 days old
+       if ($request_state_name eq 'timeout' && (!$vmhost_lastcheck_time || 
(time - convert_to_epoch_seconds($vmhost_lastcheck_time)) > (60 * 60 * 24 * 
30))) {
+               # Configure the SSH authorized_keys file to persist through 
reboots if the VM host is running VMware ESXi
+               # This shouldn't need to be done more than once, only call this 
if the state is 'reclaim'
+               if (ref($self->{vmhost_os}) =~ /Linux/i && $vmhost_product_name 
=~ /ESXi/) {
+                       $self->configure_vmhost_dedicated_ssh_key();
+               }
+               
+               # Retrieve the CPU core count, update the database if necessary
+               my $cpu_core_count;
+               if ($self->api->can('get_cpu_core_count')) {
+                       $cpu_core_count = $self->api->get_cpu_core_count();
+               }
+               elsif (!$cpu_core_count && 
$self->vmhost_os->can('get_cpu_core_count')) {
+                       $cpu_core_count = 
$self->vmhost_os->get_cpu_core_count();
+               }
+               
+               if (!$cpu_core_count) {
+                       notify($ERRORS{'OK'}, 0, "VM host computer.procnumber 
not updated, CPU core count could not be retrieved from the API or VM host OS 
object");
+               }
+               elsif ($cpu_core_count eq 
$vmhost_data->get_computer_processor_count()) {
+                       notify($ERRORS{'DEBUG'}, 0, "VM host 
computer.procnumber is already correct in the database");
+               }
+               else {
+                       update_computer_procnumber($vmhost_computer_id, 
$cpu_core_count);
+               }
+               
+               # Retrieve the CPU speed, update the database if necessary
+               my $cpu_speed;
+               if ($self->api->can('get_cpu_speed')) {
+                       $cpu_speed = $self->api->get_cpu_speed();
+               }
+               elsif (!$cpu_speed && $self->vmhost_os->can('get_cpu_speed')) {
+                       $cpu_speed = $self->vmhost_os->get_cpu_speed();
+               }
+               
+               if (!$cpu_speed) {
+                       notify($ERRORS{'OK'}, 0, "VM host computer.procspeed 
not updated, CPU speed could not be retrieved from the API or VM host OS 
object");
+               }
+               elsif ($cpu_speed eq 
$vmhost_data->get_computer_processor_speed()) {
+                       notify($ERRORS{'DEBUG'}, 0, "VM host computer.procspeed 
is already correct in the database");
+               }
+               else {
+                       update_computer_procspeed($vmhost_computer_id, 
$cpu_speed);
+               }
+               
+               # Retrieve the RAM, update the database if necessary
+               my $ram_mb;
+               if ($self->api->can('get_total_memory')) {
+                       $ram_mb = $self->api->get_total_memory();
+               }
+               elsif (!$ram_mb && $self->vmhost_os->can('get_total_memory')) {
+                       $ram_mb = $self->vmhost_os->get_total_memory();
+               }
+               
+               if (!$ram_mb) {
+                       notify($ERRORS{'OK'}, 0, "VM host computer.RAM not 
updated, total memory could not be retrieved from the API or VM host OS 
object");
+               }
+               elsif ($ram_mb eq $vmhost_data->get_computer_ram()) {
+                       notify($ERRORS{'DEBUG'}, 0, "VM host computer.RAM is 
already correct in the database");
+               }
+               else {
+                       update_computer_ram($vmhost_computer_id, $ram_mb);
+               }
+               
+               # Update the VM host computer lastcheck time to now
+               update_computer_lastcheck($vmhost_computer_id);
+       }
+       elsif ($request_state_name eq 'timeout') {
+               notify($ERRORS{'DEBUG'}, 0, "VM host hardware parameters not 
updated in the database, last check is less than 30 days ago: 
$vmhost_lastcheck_time");
+       }
+       
        return 1;
 }
 
@@ -4626,7 +4703,8 @@ sub get_vm_ethernet_adapter_type {
                If not, the value is rounded down.
                
                The RAM value is also checked to make sure it is not lower than
-               512 MB. If so, 512 MB is returned.
+               the $VM_MINIMUM_MEMORY_MB value. If so, the 
$VM_MINIMUM_MEMORY_MB
+               is returned.
 
 =cut
 
@@ -4655,7 +4733,7 @@ sub get_vm_ram {
        # Get the minimum memory size for the OS
        my $vm_os_configuration = $self->get_vm_os_configuration();
        my $vm_guest_os = $vm_os_configuration->{guestOS} || 'unknown';
-       my $vm_os_memsize = $vm_os_configuration->{memsize} || 512;
+       my $vm_os_memsize = $vm_os_configuration->{memsize} || 
$VM_MINIMUM_MEMORY_MB;
        if ($image_minram_mb < $vm_os_memsize) {
                notify($ERRORS{'DEBUG'}, 0, "image minimum RAM value 
($image_minram_mb MB) is too low for the $vm_guest_os guest OS, adjusting to 
$vm_os_memsize MB");
                return $vm_os_memsize;

Modified: 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm?rev=1164226&r1=1164225&r2=1164226&view=diff
==============================================================================
--- 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
 (original)
+++ 
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
 Thu Sep  1 19:37:28 2011
@@ -1798,6 +1798,106 @@ sub get_available_space {
        return $available_bytes;
 }
 
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 get_cpu_core_count
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the quantitiy of CPU cores the VM host has.
+
+=cut
+
+sub get_cpu_core_count {
+       my $self = shift;
+       if (ref($self) !~ /module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $vmhost_hostname = $self->data->get_vmhost_hostname();
+       
+       # Get the host view
+       my $host_view = $self->_get_host_view() || return;
+       
+       my $cpu_core_count = $host_view->hardware->cpuInfo->numCpuCores;
+       if ($cpu_core_count) {
+               notify($ERRORS{'DEBUG'}, 0, "retrieved VM host $vmhost_hostname 
CPU core count: $cpu_core_count");
+               return $cpu_core_count;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to determine VM host 
$vmhost_hostname CPU core count");
+               return;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 get_cpu_speed
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the speed of the VM host's CPUs in MHz.
+
+=cut
+
+sub get_cpu_speed {
+       my $self = shift;
+       if (ref($self) !~ /module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $vmhost_hostname = $self->data->get_vmhost_hostname();
+       
+       # Get the host view
+       my $host_view = $self->_get_host_view() || return;
+       
+       my $hz = $host_view->hardware->cpuInfo->hz;
+       if ($hz) {
+               my $mhz = int($hz / 1000000);
+               notify($ERRORS{'DEBUG'}, 0, "retrieved VM host $vmhost_hostname 
CPU speed: $mhz MHz");
+               return $mhz;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to determine VM host 
$vmhost_hostname CPU speed");
+               return;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 get_total_memory
+
+ Parameters  : none
+ Returns     : integer
+ Description : Retrieves the VM host's total memory capacity in MB.
+
+=cut
+
+sub get_total_memory {
+       my $self = shift;
+       if (ref($self) !~ /module/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return;
+       }
+       
+       my $vmhost_hostname = $self->data->get_vmhost_hostname();
+       
+       # Get the host view
+       my $host_view = $self->_get_host_view() || return;
+       
+       my $memory_bytes = $host_view->hardware->memorySize;
+       if (!$memory_bytes) {
+               notify($ERRORS{'WARNING'}, 0, "unable to determine VM host 
$vmhost_hostname total memory capacity");
+               return;
+       }
+       
+       my $memory_mb = int($memory_bytes / 1024 / 1024);
+       notify($ERRORS{'DEBUG'}, 0, "retrieved VM host $vmhost_hostname total 
memory capacity: $memory_mb MB");
+       return $memory_mb;
+}
+
 ##############################################################################
 
 =head1 PRIVATE OBJECT METHODS

Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1164226&r1=1164225&r2=1164226&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Thu Sep  1 19:37:28 2011
@@ -210,6 +210,9 @@ our @EXPORT = qw(
   update_computer_address
   update_computer_state
   update_computer_lastcheck
+  update_computer_procnumber
+  update_computer_procspeed
+  update_computer_ram
   update_currentimage
   update_computer_imagename
   update_image_name
@@ -2035,7 +2038,6 @@ sub update_computer_lastcheck {
        $log = 0 unless (defined $log);
 
        notify($ERRORS{'WARNING'}, $log, "computer id is not defined") unless 
(defined($computer_id));
-       notify($ERRORS{'WARNING'}, $log, "$datestring is not defined") unless 
(defined($datestring));
        return 0 unless (defined $computer_id);
 
        unless (defined($datestring) ) {
@@ -2062,6 +2064,125 @@ sub update_computer_lastcheck {
                return 0;
        }
 } ## end
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 update_computer_procnumber
+
+ Parameters  : $computer_id, $cpu_count
+ Returns     : boolean
+ Description : Updates the computer.procnumber value for the specified 
computer.
+
+=cut
+
+sub update_computer_procnumber {
+       my ($computer_id, $cpu_count) = @_;
+
+       if (!$computer_id || !$cpu_count) {
+               notify($ERRORS{'WARNING'}, 0, "computer ID and CPU count 
arguments were not supplied correctly");
+               return;
+       }
+
+       my $update_statement = <<EOF;
+UPDATE
+computer
+SET
+computer.procnumber = '$cpu_count'
+WHERE
+computer.id = $computer_id
+EOF
+
+       # Call the database execute subroutine
+       if (database_execute($update_statement)) {
+               notify($ERRORS{'DEBUG'}, 0, "updated the procnumber value to 
$cpu_count for computer ID $computer_id");
+               return 1;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to update the procnumber 
value to $cpu_count for computer ID $computer_id");
+               return 0;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 update_computer_procspeed
+
+ Parameters  : $computer_id, $cpu_speed
+ Returns     : boolean
+ Description : Updates the computer.procspeed value for the specified computer.
+                                       The $cpu_speed argument should contain 
an integer value of the
+                                       CPU speed in MHz.
+
+=cut
+
+sub update_computer_procspeed {
+       my ($computer_id, $cpu_speed_mhz) = @_;
+
+       if (!$computer_id || !$cpu_speed_mhz) {
+               notify($ERRORS{'WARNING'}, 0, "computer ID and CPU speed 
arguments were not supplied correctly");
+               return;
+       }
+
+       my $update_statement = <<EOF;
+UPDATE
+computer
+SET
+computer.procspeed = '$cpu_speed_mhz'
+WHERE
+computer.id = $computer_id
+EOF
+
+       # Call the database execute subroutine
+       if (database_execute($update_statement)) {
+               notify($ERRORS{'DEBUG'}, 0, "updated the procspeed value to 
$cpu_speed_mhz for computer ID $computer_id");
+               return 1;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to update the procspeed 
value to $cpu_speed_mhz for computer ID $computer_id");
+               return 0;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 update_computer_ram
+
+ Parameters  : $computer_id, $ram_mb
+ Returns     : boolean
+ Description : Updates the computer.ram value for the specified computer.
+                                       The $ram_mb argument should contain an 
integer value of the
+                                       RAM in MB.
+
+=cut
+
+sub update_computer_ram {
+       my ($computer_id, $ram_mb) = @_;
+
+       if (!$computer_id || !$ram_mb) {
+               notify($ERRORS{'WARNING'}, 0, "computer ID and RAM arguments 
were not supplied correctly");
+               return;
+       }
+
+       my $update_statement = <<EOF;
+UPDATE
+computer
+SET
+computer.ram = '$ram_mb'
+WHERE
+computer.id = $computer_id
+EOF
+
+       # Call the database execute subroutine
+       if (database_execute($update_statement)) {
+               notify($ERRORS{'DEBUG'}, 0, "updated the RAM value to $ram_mb 
for computer ID $computer_id");
+               return 1;
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to update the RAM value 
to $ram_mb for computer ID $computer_id");
+               return 0;
+       }
+}
+
 #/////////////////////////////////////////////////////////////////////////////
 
 =head2 update_request_password


Reply via email to