You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by fa...@apache.org on 2014/07/23 21:30:54 UTC
svn commit: r1612929 - in
/vcl/trunk/managementnode/lib/VCL/Module/Provisioning: VMware/VMware.pm
vbox.pm
Author: fapeeler
Date: Wed Jul 23 19:30:53 2014
New Revision: 1612929
URL: http://svn.apache.org/r1612929
Log:
VCL-772
removed node_status from VMware.pm and vbox.pm
Modified:
vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
vcl/trunk/managementnode/lib/VCL/Module/Provisioning/vbox.pm
Modified: vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm?rev=1612929&r1=1612928&r2=1612929&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm Wed Jul 23 19:30:53 2014
@@ -1106,237 +1106,6 @@ sub get_active_vmx_file_path {
#/////////////////////////////////////////////////////////////////////////////
-=head2 node_status
-
- Parameters : $computer_id or $hash->{computer}{id} (optional)
- Returns : string -- 'READY', 'POST_LOAD', or 'RELOAD'
- Description : Checks the status of a VM. 'READY' is returned if the VM is
- accessible via SSH, the virtual disk mode is dedicated if
- necessary, the image loaded matches the requested image, and the
- OS module's post-load tasks have run. 'POST_LOAD' is returned if
- the VM only needs to have the OS module's post-load tasks run
- before it is ready. 'RELOAD' is returned otherwise.
-
-=cut
-
-sub node_status {
- my $self;
-
- # Get the argument
- my $argument = shift;
-
- # Check if this subroutine was called an an object method or an argument was passed
- if (ref($argument) =~ /VCL::Module/i) {
- $self = $argument;
- }
- elsif (!ref($argument) || ref($argument) eq 'HASH') {
- # An argument was passed, check its type and determine the computer ID
- my $computer_id;
- if (ref($argument)) {
- # Hash reference was passed
- $computer_id = $argument->{id};
- }
- elsif ($argument =~ /^\d+$/) {
- # Computer ID was passed
- $computer_id = $argument;
- }
- else {
- # Computer name was passed
- ($computer_id) = get_computer_ids($argument);
- }
-
- if ($computer_id) {
- notify($ERRORS{'DEBUG'}, 0, "computer ID: $computer_id");
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "unable to determine computer ID from argument:\n" . format_data($argument));
- return;
- }
-
- # Create a DataStructure object containing data for the computer specified as the argument
- my $data;
- eval {
- $data= new VCL::DataStructure({computer_identifier => $computer_id});
- };
- if ($EVAL_ERROR) {
- notify($ERRORS{'WARNING'}, 0, "failed to create DataStructure object for computer ID: $computer_id, error: $EVAL_ERROR");
- return;
- }
- elsif (!$data) {
- notify($ERRORS{'WARNING'}, 0, "failed to create DataStructure object for computer ID: $computer_id, DataStructure object is not defined");
- return;
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "created DataStructure object for computer ID: $computer_id");
- }
-
- # Create a VMware object
- my $object_type = 'VCL::Module::Provisioning::VMware::VMware';
- if ($self = ($object_type)->new({data_structure => $data})) {
- notify($ERRORS{'DEBUG'}, 0, "created $object_type object to check the status of computer ID: $computer_id");
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "failed to create $object_type object to check the status of computer ID: $computer_id");
- return;
- }
-
- # Create an OS object for the VMware object to access
- if (!$self->create_os_object()) {
- notify($ERRORS{'WARNING'}, 0, "failed to create OS object");
- return;
- }
- }
-
- my $reservation_id = $self->data->get_reservation_id();
- my $computer_name = $self->data->get_computer_node_name();
- my $image_name = $self->data->get_image_name();
- my $request_forimaging = $self->data->get_request_forimaging();
- my $imagerevision_id = $self->data->get_imagerevision_id();
-
- notify($ERRORS{'DEBUG'}, 0, "attempting to check the status of computer $computer_name, image: $image_name");
-
- # Create a hash reference and populate it with the default values
- my $status;
- $status->{currentimage} = '';
- $status->{ssh} = 0;
- $status->{image_match} = 0;
- $status->{status} = 'RELOAD';
-
- # Check if node is pingable and retrieve the power status if the reservation ID is 0
- # The reservation ID will be 0 is this subroutine was not called as an object method, but with a computer ID argument
- # The reservation ID will be 0 when called from healthcheck.pm
- # The reservation ID will be > 0 if called from a normal VCL reservation
- # Skip the ping and power status checks for a normal reservation to speed things up
- if (!$reservation_id) {
- if (_pingnode($computer_name)) {
- notify($ERRORS{'DEBUG'}, 0, "VM $computer_name is pingable");
- $status->{ping} = 1;
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "VM $computer_name is not pingable");
- $status->{ping} = 0;
- }
-
- my $vmx_file_path = $self->get_vmx_file_path();
- $status->{vmstate} = $self->power_status($vmx_file_path);
- if (!defined($status->{vmstate})) {
- $status->{vmstate} = "off";
- }
- }
-
- # Check if SSH is available
- if ($self->os->is_ssh_responding()) {
- notify($ERRORS{'DEBUG'}, 0, "VM $computer_name is responding to SSH");
- $status->{ssh} = 1;
- }
- else {
- notify($ERRORS{'OK'}, 0, "VM $computer_name is not responding to SSH, returning 'RELOAD'");
- $status->{status} = 'RELOAD';
- $status->{ssh} = 0;
-
- # Skip remaining checks if SSH isn't available
- return $status;
- }
-
- # Get the contents of currentimage.txt and update the datastructure
- my $current_image_revision_id = $self->os->get_current_image_info();
- $status->{currentimagerevision_id} = $current_image_revision_id;
-
- $status->{currentimage} = $self->data->get_computer_currentimage_name();
- my $current_image_name = $status->{currentimage};
- my $vcld_post_load_status = $self->data->get_computer_currentimage_vcld_post_load();
-
- if (!$current_image_revision_id) {
- notify($ERRORS{'OK'}, 0, "unable to retrieve image name from currentimage.txt on VM $computer_name, returning 'RELOAD'");
- return $status;
- }
- elsif ($current_image_revision_id eq $imagerevision_id) {
- notify($ERRORS{'OK'}, 0, "currentimage.txt image $current_image_revision_id ($current_image_name) matches requested imagerevision_id $imagerevision_id ($image_name) on VM $computer_name");
- $status->{image_match} = 1;
- }
- else {
- notify($ERRORS{'OK'}, 0, "currentimage.txt imagerevision_id $current_image_revision_id ($current_image_name) does not match requested imagerevision_id $imagerevision_id ($image_name) on VM $computer_name, returning 'RELOAD'");
- return $status;
- }
-
- # If the VM is dedicated, check if the vmdk of the VM already loaded is shared or dedicated
- my $is_vm_dedicated = $self->is_vm_dedicated();
- if ($request_forimaging || $is_vm_dedicated) {
- # Determine the vmx file path actively being used by the VM
- my $vmx_file_path = $self->get_active_vmx_file_path();
- if (!$vmx_file_path) {
- notify($ERRORS{'WARNING'}, 0, "failed to determine the vmx file path actively being used by $computer_name, returning 'RELOAD'");
- return $status;
- }
-
- # Set the vmx file path in this object so that it overrides the default value that would normally be constructed
- if (!$self->set_vmx_file_path($vmx_file_path)) {
- notify($ERRORS{'WARNING'}, 0, "failed to set the vmx file to the path that was determined to be in use by the VM: $vmx_file_path, returning 'RELOAD'");
- return $status;
- }
-
- # Get the information contained within the vmx file
- my $vmx_info = $self->get_vmx_info($vmx_file_path);
-
- # Get the vmdk info from the vmx info
- my @vmdk_identifiers = keys %{$vmx_info->{vmdk}};
- if (!@vmdk_identifiers) {
- notify($ERRORS{'WARNING'}, 0, "did not find vmdk file in vmx info ({vmdk} key), returning 'RELOAD':\n" . format_data($vmx_info));
- return $status;
- }
- elsif (scalar(@vmdk_identifiers) > 1) {
- notify($ERRORS{'WARNING'}, 0, "found multiple vmdk files in vmx info ({vmdk} keys), returning 'RELOAD':\n" . format_data($vmx_info));
- return $status;
- }
-
- # Get the vmdk file path from the vmx information
- my $vmdk_file_path = $vmx_info->{vmdk}{$vmdk_identifiers[0]}{vmdk_file_path};
- if (!$vmdk_file_path) {
- notify($ERRORS{'WARNING'}, 0, "vmdk file path was not found in the vmx file info, returning 'RELOAD':\n" . format_data($vmx_info));
- return $status;
- }
-
- # Get the vmdk mode from the vmx information and make sure it is not nonpersistent
- my $vmdk_mode = $vmx_info->{vmdk}{$vmdk_identifiers[0]}{mode};
- if (!$vmdk_mode) {
- notify($ERRORS{'WARNING'}, 0, "vmdk mode was not found in the vmx info, returning 'RELOAD':\n" . format_data($vmx_info));
- return $status;
- }
-
- notify($ERRORS{'DEBUG'}, 0, "vmdk file path used by the VM already loaded: $vmdk_file_path, mode: $vmdk_mode");
-
- # Can't use if nonpersistent
- if ($vmdk_mode =~ /nonpersistent/i) {
- notify($ERRORS{'OK'}, 0, "VM already loaded may NOT be used, vmdk mode: '$vmdk_mode', returning 'RELOAD'");
- return $status;
- }
-
- if ($is_vm_dedicated) {
- if ($self->is_vmdk_file_shared($vmdk_file_path)) {
- notify($ERRORS{'DEBUG'}, 0, "VM already loaded may NOT be used, the vmdk appears to be shared, returning '$status'");
- return $status;
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "VM already loaded may be used, the vmdk does NOT appear to be shared");
- }
- }
- }
-
- # Check if the OS post_load tasks have run
- if ($vcld_post_load_status) {
- notify($ERRORS{'DEBUG'}, 0, "OS module post_load tasks have been completed on VM $computer_name");
- $status->{status} = 'READY';
- }
- else {
- notify($ERRORS{'OK'}, 0, "OS module post_load tasks have not been completed on VM $computer_name, returning 'POST_LOAD'");
- $status->{status} = 'POST_LOAD';
- }
-
- return $status;
-}
-
-#/////////////////////////////////////////////////////////////////////////////
-
=head2 vmhost_data
Parameters : none
Modified: vcl/trunk/managementnode/lib/VCL/Module/Provisioning/vbox.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/vbox.pm?rev=1612929&r1=1612928&r2=1612929&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/Provisioning/vbox.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/Provisioning/vbox.pm Wed Jul 23 19:30:53 2014
@@ -827,184 +827,6 @@ sub get_image_size {
#/////////////////////////////////////////////////////////////////////////////
-=head2 node_status
-
- Parameters : $nodename, $log
- Returns : array of related status checks
- Description : checks on ping,sshd, currentimage, OS
-
-=cut
-
-# This is where VBoxManage will need to be called, and the output parsed into useable data, currently always returning RELOAD to force the code into creating a new VM.
-
-sub node_status {
- my $self = shift;
-
- my $vmpath = 0;
- my $datastorepath = 0;
- my $requestedimagename = 0;
- my $vmhost_type = 0;
- my $log = 0;
- my $vmhost_hostname = 0;
- my $vmhost_imagename = 0;
- my $vmclient_shortname = 0;
- my $image_os_type = 0;
- my $request_forimaging = 0;
- my $computer_node_name = 0;
- my $identity_keys = 0;
- my $imagerevision_id = 0;
-
- # Check if subroutine was called as a class method
- if (ref($self) !~ /vbox/i) {
- if (ref($self) eq 'HASH') {
- $log = $self->{logfile};
- #notify($ERRORS{'DEBUG'}, $log, "self is a hash reference");
-
- $computer_node_name = $self->{computer}->{hostname};
- $identity_keys = $self->{managementnode}->{keys};
- $requestedimagename = $self->{imagerevision}->{imagename};
- $image_os_type = $self->{image}->{OS}->{type};
- $vmhost_type = $self->{vmhost}->{vmprofile}->{vmtype}->{name};
- $vmhost_imagename = $self->{vmhost}->{imagename};
- $vmpath = $self->{vmhost}->{vmprofile}->{vmpath};
- $datastorepath = $self->{vmhost}->{vmprofile}->{datastorepath};
- $vmhost_hostname = $self->{vmhost}->{hostname};
-
- } ## end if (ref($self) eq 'HASH')
- # Check if node_status returned an array ref
- elsif (ref($self) eq 'ARRAY') {
- notify($ERRORS{'DEBUG'}, $log, "self is a array reference");
- }
-
- $vmclient_shortname = $1 if ($computer_node_name =~ /([-_a-zA-Z0-9]*)(\.?)/);
-
- } ## end if (ref($self) !~ /vbox/i)
- else {
- # called as an object
- # Collect local variables from DataStructure
-
- $vmpath = $self->data->get_vmhost_profile_vmpath;
- $datastorepath = $self->data->get_vmhost_profile_datastore_path;
- $requestedimagename = $self->data->get_image_name;
- $vmhost_type = $self->data->get_vmhost_type;
- $vmhost_hostname = $self->data->get_vmhost_hostname;
- $vmhost_imagename = $self->data->get_vmhost_image_name;
- $vmclient_shortname = $self->data->get_computer_short_name;
- $image_os_type = $self->data->get_image_os_type;
- $request_forimaging = $self->data->get_request_forimaging();
- $identity_keys = $self->data->get_management_node_keys;
- $imagerevision_id = $self->data->get_imagerevision_id();
- } ## end else [ if (ref($self) !~ /vbox/i)
-
- notify($ERRORS{'DEBUG'}, $log, "identity_keys= $identity_keys");
- notify($ERRORS{'DEBUG'}, $log, "requestedimagename= $requestedimagename");
- notify($ERRORS{'DEBUG'}, $log, "image_os_type= $image_os_type");
- notify($ERRORS{'DEBUG'}, $log, "request_forimaging= $request_forimaging");
- notify($ERRORS{'DEBUG'}, $log, "vmpath= $vmpath");
- notify($ERRORS{'DEBUG'}, $log, "datastorepath= $datastorepath");
-
- # Create a hash to store status components
- my %status;
-
- # Initialize all hash keys here to make sure they're defined
- $status{status} = 0;
- $status{currentimage} = 0;
- $status{ping} = 0;
- $status{ssh} = 0;
- $status{vmstate} = 0; #on or off
- $status{image_match} = 0;
-
- if (!$identity_keys) {
- notify($ERRORS{'CRITICAL'}, $log, "could not set ssh identity variable for image $vmhost_imagename type= $vmhost_type host= $vmhost_hostname");
- }
-
- # Check if node is pingable
- notify($ERRORS{'DEBUG'}, $log, "checking if $vmclient_shortname is pingable");
- if (_pingnode($vmclient_shortname)) {
- $status{ping} = 1;
- notify($ERRORS{'OK'}, $log, "$vmclient_shortname is pingable ($status{ping})");
- }
- else {
- notify($ERRORS{'OK'}, $log, "$vmclient_shortname is not pingable ($status{ping})");
- $status{ping} = 0;
- }
-
- my $mybasedirname = $requestedimagename;
- my $myimagename = $requestedimagename;
-
- # #vm running
- my @sshcmd = run_ssh_command($vmhost_hostname, $identity_keys, "VBoxManage -q showvminfo $requestedimagename\_$vmclient_shortname --machinereadable | grep VMState=", "root");
- foreach my $l (@{$sshcmd[1]}) {
- notify($ERRORS{'OK'}, $log, "$l");
- $status{vmstate} = "on" if ($l =~ /running/);
- $status{vmstate} = "off" if ($l =~ /poweroff/);
- $status{vmstate} = "stuck" if ($l =~ /paused/);
- ##if ($l =~ /No such virtual machine/) {
- ## #ok wait something is using that hostname
- ## #reset $status{image_match} controlVM will detect and remove it
- ## $status{image_match} = 0;
- ##}
- } ## end foreach my $l (@{$sshcmd[1]})
- notify($ERRORS{'OK'}, $log, "$vmclient_shortname vmstate reports $status{vmstate}");
-
- # Check if $self->os is defined, it may not be if xCAT.pm object is created from a monitoring script
- my $os = $self->os(0);
- if (!$os) {
- my $data = $self->create_datastructure_object({computer_identifier => $computer_node_name, image_identifier => $requestedimagename});
- if (!$data) {
- notify($ERRORS{'WARNING'}, 0, "unable to determine status of $computer_node_name, \$self->os is not defined, failed to create DataStructure object for image set as image: '$requestedimagename'");
- return;
- }
-
- # Set the data, create_os_object copies the data from the calling object to the new OS object
- $self->set_data($data);
-
- my $image_os_module_perl_package = $data->get_image_os_module_perl_package();
- $os = $self->create_os_object($image_os_module_perl_package);
- if (!$os) {
- notify($ERRORS{'WARNING'}, 0, "unable to determine status of $computer_node_name, failed to create OS object for image set as imagename: 'requestedimagename'");
- return;
- }
- }
-
- # Check if the node is responding to SSH
- my $ssh_responding = $os->is_ssh_responding();
- if ($ssh_responding) {
- $status{ssh} = 1;
- $status{currentimage} = $self->os->get_current_image_info("current_image_name");
- $status{currentimagerevisionid} = $self->os->get_current_image_info();
- if ($status{currentimagerevisionid}) {
- chomp($status{currentimagerevisionid});
- if ($status{currentimagerevisionid} eq $imagerevision_id) {
- $status{image_match} = 1;
- notify($ERRORS{'OK'}, $log, "$vmclient_shortname is loaded with requestedimagename imagerevision_id=$imagerevision_id $requestedimagename");
- }
- else {
- notify($ERRORS{'OK'}, $log, "$vmclient_shortname reports current image is currentimage= $status{currentimage} requestedimagename= $requestedimagename");
- }
- } ## end if ($status{currentimage})
- } ## end if ($sshd eq "on")
-
-
- # Determine the overall machine status based on the individual status results
- if ($status{ssh} && $status{image_match}) {
- $status{status} = 'READY';
- }
- else {
- $status{status} = 'RELOAD';
- }
-
- if ($request_forimaging) {
- $status{status} = 'RELOAD';
- notify($ERRORS{'OK'}, $log, "forimaging flag enabled RELOAD machine");
- }
-
- notify($ERRORS{'OK'}, $log, "returning node status hash reference (\$node_status->{status}=$status{status})");
- return \%status;
-} ## end sub node_status
-
-#/////////////////////////////////////////////////////////////////////////////
-
=head2 does_image_exist
Parameters : imagename