You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by ar...@apache.org on 2012/06/20 15:26:28 UTC

svn commit: r1352089 - in /incubator/vcl/trunk/managementnode/lib/VCL: Module/OS/Linux.pm Module/Provisioning/libvirt.pm image.pm

Author: arkurth
Date: Wed Jun 20 13:26:28 2012
New Revision: 1352089

URL: http://svn.apache.org/viewvc?rev=1352089&view=rev
Log:
VCL-545
Updated libvirt.pm. Added missing calls to insertloadlog. Fixed a few bugs with image capture. The code renames the image so that images are not inappropriately named vmware*. It was setting this updated name in the database but incorrectly naming image files saved to the datastore and repository. Updated code to name the files correctly.

Other
Updated image.pm so that a warning is not displayed if the sysadmin email address is not configured.

Added code to Linux.pm::pre_capture to allow the provisioning module to specify the "end_state" -- meaning if a hash reference is passed with an 'end_state' key set to on, the computer is not powered off by the OS module. This is already in Windows.pm but was missing from Linux.pm.

Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
    incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt.pm
    incubator/vcl/trunk/managementnode/lib/VCL/image.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=1352089&r1=1352088&r2=1352089&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Wed Jun 20 13:26:28 2012
@@ -106,14 +106,29 @@ sub get_node_configuration_directory {
 
 sub pre_capture {
 	my $self = shift;
+	my $args = 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();
-	notify($ERRORS{'OK'}, 0, "beginning Linux-specific image capture preparation tasks");
+	# Check if end_state argument was passed
+	if (defined $args->{end_state}) {
+		$self->{end_state} = $args->{end_state};
+	}
+	else {
+		$self->{end_state} = 'off';
+	}
+	
+	my $computer_node_name  = $self->data->get_computer_node_name();
 	
+	# Call OS::pre_capture to perform the pre-capture tasks common to all OS's
+	if (!$self->SUPER::pre_capture($args)) {
+		notify($ERRORS{'WARNING'}, 0, "failed to execute parent class pre_capture() subroutine");
+		return;
+	}
+	
+	notify($ERRORS{'OK'}, 0, "beginning Linux-specific image capture preparation tasks");
 	
 	if (!$self->file_exists("/root/.vclcontrol/vcl_exclude_list.sample")) {
       notify($ERRORS{'DEBUG'}, 0, "/root/.vclcontrol/vcl_exclude_list.sample does not exists");
@@ -179,9 +194,15 @@ sub pre_capture {
 	}
 	
 	# Shut the computer down
-	if (!$self->shutdown()) {
-		notify($ERRORS{'WARNING'}, 0, "failed to shut down $computer_node_name");
-		return;
+	if ($self->{end_state} =~ /off/i) {
+		notify($ERRORS{'DEBUG'}, 0, "shutting down $computer_node_name, provisioning module specified end state: $self->{end_state}");
+		if (!$self->shutdown()) {
+			notify($ERRORS{'WARNING'}, 0, "failed to shut down $computer_node_name");
+			return;
+		}
+	}
+	else {
+		notify($ERRORS{'DEBUG'}, 0, "$computer_node_name not shut down, provisioning module specified end state: $self->{end_state}");
 	}
 
 	notify($ERRORS{'OK'}, 0, "Linux pre-capture steps complete");

Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt.pm
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt.pm?rev=1352089&r1=1352088&r2=1352089&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt.pm Wed Jun 20 13:26:28 2012
@@ -167,6 +167,9 @@ sub load {
 	my $domain_name = $self->get_domain_name();
 	my $driver_name = $self->get_driver_name();
 	my $domain_xml_file_path = $self->get_domain_xml_file_path();
+	
+	insertloadlog($reservation_id, $computer_id, "doesimageexists", "image exists $image_name");
+	insertloadlog($reservation_id, $computer_id, "startload", "$computer_name $image_name");
 
 =item *
 
@@ -218,6 +221,7 @@ used prior to defining the domain.
 		notify($ERRORS{'WARNING'}, 0, "failed to load '$image_name' image on '$computer_name', $driver_name libvirt driver module failed to complete its steps prior to defining the domain");
 		return;
 	}
+	insertloadlog($reservation_id, $computer_id, "transfervm", "performed libvirt driver tasks before defining domain");
 
 =item *
 
@@ -240,6 +244,7 @@ Define the domain on the node by calling
 		notify($ERRORS{'WARNING'}, 0, "failed to load '$image_name' image on '$computer_name', unable to define domain");
 		return;
 	}
+	insertloadlog($reservation_id, $computer_id, "vmsetupconfig", "defined $computer_name domain node $node_name");
 
 =item *
 
@@ -251,6 +256,7 @@ Power on the domain.
 		notify($ERRORS{'WARNING'}, 0, "failed to start '$domain_name' domain on $node_name");
 		return;
 	}
+	insertloadlog($reservation_id, $computer_id, "startvm", "powered on $computer_name domain node $node_name");
 
 =item *
 
@@ -295,12 +301,17 @@ sub capture {
 		return;
 	}
 	
+	my $old_image_name = $self->data->get_image_name();
+	
+	# Construct the new image name
+	my $new_image_name = $self->get_new_image_name();
+	$self->data->set_image_name($new_image_name);
+	
 	my $image_id = $self->data->get_image_id();
 	my $imagerevision_id = $self->data->get_imagerevision_id();
-	my $image_name = $self->data->get_image_name();
 	my $image_type = $self->data->get_imagetype_name();
 	my $node_name = $self->data->get_vmhost_short_name();
-	my $old_image_name = $self->data->get_image_name();
+	my $computer_name = $self->data->get_computer_short_name();
 	my $master_image_directory_path = $self->get_master_image_directory_path();
 	my $master_image_file_path = $self->get_master_image_file_path();
 	my $datastore_image_type = $self->data->get_vmhost_datastore_imagetype_name();
@@ -318,6 +329,27 @@ sub capture {
 		return;
 	}
 	
+	notify($ERRORS{'DEBUG'}, 0, "beginning image capture:\n" . <<EOF
+image id: $image_id
+imagerevision id: $imagerevision_id
+old image name: $old_image_name
+new image name: $new_image_name
+---
+host node: $node_name
+computer: $computer_name
+---
+master image directory path: $master_image_directory_path
+master image file path: $master_image_file_path
+---
+old image type: $image_type
+datastore image type: $datastore_image_type
+---
+repository image type: $repository_image_type
+repository image directory path: $repository_image_directory_path
+repository image file path: $repository_image_file_path
+EOF
+);
+	
 	# Check the power status before proceeding
 	my $power_status = $self->power_status();
 	if (!$power_status) {
@@ -329,10 +361,6 @@ sub capture {
 		return;
 	}
 	
-	# Construct the new image name
-	my $new_image_name = $self->get_new_image_name();
-	$self->data->set_image_name($new_image_name);
-	
 	# Make sure the master image file doesn't already exist
 	if ($self->vmhost_os->file_exists($master_image_file_path)) {
 		notify($ERRORS{'WARNING'}, 0, "master image file already exists on $node_name: $master_image_file_path");
@@ -372,8 +400,8 @@ sub capture {
 	}
 	
 	# Update the image name in the database
-	if ($image_name ne $new_image_name && !update_image_name($image_id, $imagerevision_id, $new_image_name)) {
-		notify($ERRORS{'WARNING'}, 0, "failed to update image name in the database: $image_name --> $new_image_name");
+	if ($old_image_name ne $new_image_name && !update_image_name($image_id, $imagerevision_id, $new_image_name)) {
+		notify($ERRORS{'WARNING'}, 0, "failed to update image name in the database: $old_image_name --> $new_image_name");
 		return;
 	}
 	

Modified: incubator/vcl/trunk/managementnode/lib/VCL/image.pm
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/image.pm?rev=1352089&r1=1352088&r2=1352089&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/image.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/image.pm Wed Jun 20 13:26:28 2012
@@ -102,7 +102,7 @@ sub process {
 	my $computer_type              = $self->data->get_computer_type();
 	my $computer_shortname         = $self->data->get_computer_short_name();
 	my $managementnode_shortname   = $self->data->get_management_node_short_name();
-	my $sysadmin_mail_address      = $self->data->get_management_node_sysadmin_email();
+	my $sysadmin_mail_address      = $self->data->get_management_node_sysadmin_email(1);
 
 	if ($sysadmin_mail_address) {
 		# Notify administrators that image creation is starting
@@ -300,7 +300,7 @@ sub reservation_successful {
 	my $computer_id                = $self->data->get_computer_id();
 	my $computer_shortname         = $self->data->get_computer_short_name();
 	my $managementnode_shortname   = $self->data->get_management_node_short_name();
-	my $sysadmin_mail_address      = $self->data->get_management_node_sysadmin_email();
+	my $sysadmin_mail_address      = $self->data->get_management_node_sysadmin_email(1);
 
 	# Send image creation successful email to user
 	my $body_user = <<"END";
@@ -316,7 +316,8 @@ END
 	mail($user_email, "VCL -- $image_prettyname Image Creation Succeeded", $body_user, $affiliation_helpaddress);
 
 	# Send mail to $sysadmin_mail_address
-	my $body_admin = <<"END";
+	if ($sysadmin_mail_address) {
+		my $body_admin = <<"END";
 VCL Image Creation Completed
 
 Request ID: $request_id
@@ -340,8 +341,9 @@ Computer name: $computer_shortname
 Use Sysprep: $imagemeta_sysprep
 END
 
-	mail($sysadmin_mail_address, "VCL IMAGE Creation Completed: $image_name", $body_admin, $affiliation_helpaddress);
-
+		mail($sysadmin_mail_address, "VCL IMAGE Creation Completed: $image_name", $body_admin, $affiliation_helpaddress);
+	}
+	
 	# Insert reload request data into the datbase
 	if (insert_reload_request($request_data)) {
 		notify($ERRORS{'OK'}, 0, "inserted reload request into database for computer id=$computer_id");
@@ -379,7 +381,7 @@ sub reservation_failed {
 	my $computer_id                = $self->data->get_computer_id();
 	my $computer_shortname         = $self->data->get_computer_short_name();
 	my $managementnode_shortname   = $self->data->get_management_node_short_name();
-	my $sysadmin_mail_address      = $self->data->get_management_node_sysadmin_email();
+	my $sysadmin_mail_address      = $self->data->get_management_node_sysadmin_email(1);
 
 	# Image process failed
 	notify($ERRORS{'CRITICAL'}, 0, "$image_name image creation failed");
@@ -408,7 +410,8 @@ END
 	mail($user_email, "VCL -- NOTICE DELAY Image Creation $image_prettyname", $body_user, $affiliation_helpaddress);
 
 	# Send mail to $sysadmin_mail_address
-	my $body_admin = <<"END";
+	if ($sysadmin_mail_address) {
+		my $body_admin = <<"END";
 VCL Image Creation Failed
 
 Request ID: $request_id
@@ -431,8 +434,9 @@ Computer name: $computer_shortname
 Use Sysprep: $imagemeta_sysprep
 END
 
-	mail($sysadmin_mail_address, "VCL -- NOTICE FAILED Image Creation $image_prettyname", $body_admin, $affiliation_helpaddress);
-
+		mail($sysadmin_mail_address, "VCL -- NOTICE FAILED Image Creation $image_prettyname", $body_admin, $affiliation_helpaddress);
+	}
+	
 	# Update the request state to maintenance, laststate to image
 	if (update_request_state($request_id, "maintenance", "image")) {
 		notify($ERRORS{'OK'}, 0, "request state set to maintenance, laststate to image");