Author: arkurth
Date: Thu May 3 14:25:45 2012
New Revision: 1333476
URL: http://svn.apache.org/viewvc?rev=1333476&view=rev
Log:
VCL-503
Updated OS.pm::execute_new. It wasn't handling the arguments correctly if
called as an object method and passed a hash reference.
Added 'ignore_error' argument. This prevents the subroutine from looping and
generating warning messages if the command being executed is known to break the
SSH connection.
VCL-413
Updated Module.pm::create_mn_os_object to populate the 'noimage' image info in
the DataStructure object created for the management node. This prevents errors
in case anything attempt to access image info.
VCL-580
Changed order of Linux.pm::pre_capture to configure rc-local after configuring
the external SSH service. The rc-local code was failing when capturing a base
image because the ext_sshd file didn't exist.
VCL-545
Updated libvirt.pm::initialize. It wasn't returning false if it failed.
Fixed problem with copy_vmdk. Under OS's other than Fedora 16, the qemu-img
utility can't copy a vmdk split into multiple files. The workaround is to first
convert them to raw files, then copy them.
VCL-30
Removed check to see if OS module implements is_user_connected in reserved.pm.
This is now in OS.pm so all OS's implement it.
Removed check_connection subroutine from utils.pm. It is no longer called --
replaced by code in OS modules.
Other
Updated OS.pm::create_text_file to only enclose the file path in quotes if it
contains a space. If the path contains ~ and is enclosed in quotes, the home
directory isn't interpreted.
Moved copy_file subroutine from Linux.pm to OS.pm since it may be used on other
OS's.
Modified:
incubator/vcl/trunk/managementnode/lib/VCL/Module.pm
incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm
incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt.pm
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt/KVM.pm
incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm
incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module.pm?rev=1333476&r1=1333475&r2=1333476&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module.pm Thu May 3 14:25:45
2012
@@ -363,7 +363,7 @@ sub create_mn_os_object {
# Create a DataStructure object containing computer data for the
management node
my $mn_data;
eval {
- $mn_data = new VCL::DataStructure();
+ $mn_data = new VCL::DataStructure('image_id' => 'noimage');
};
# Attempt to load the OS module
@@ -386,6 +386,7 @@ sub create_mn_os_object {
notify($ERRORS{'WARNING'}, 0, "failed to create management node
OS object");
return;
}
+
}
#/////////////////////////////////////////////////////////////////////////////
@@ -450,7 +451,7 @@ sub create_vmhost_os_object {
}
# Load the VM host OS module
- notify($ERRORS{'DEBUG'}, 0, "attempting to load VM host OS module:
$vmhost_os_perl_package");
+ notify($ERRORS{'DEBUG'}, 0, "attempting to load VM host OS module:
$vmhost_os_perl_package (image: $vmhost_profile_image_id)");
eval "use $vmhost_os_perl_package";
if ($EVAL_ERROR) {
notify($ERRORS{'WARNING'}, 0, "VM host OS module could NOT be
loaded: $vmhost_os_perl_package, error: $EVAL_ERROR");
@@ -888,11 +889,11 @@ sub code_loop_timeout {
my $seconds_elapsed = $current_time - $start_time;
my $seconds_remaining = $end_time - $current_time;
- notify($ERRORS{'OK'}, 0, "attempt " .
($attempt_count-1) . ": code returned false, seconds elapsed/remaining:
$seconds_elapsed/$seconds_remaining, sleeping for $attempt_delay_seconds
seconds");
+ notify($ERRORS{'OK'}, 0, "attempt " .
($attempt_count-1) . ": $message ($seconds_elapsed/$seconds_remaining seconds)
sleeping for $attempt_delay_seconds seconds");
sleep $attempt_delay_seconds;
}
- notify($ERRORS{'OK'}, 0, "attempt $attempt_count: $message");
+ #notify($ERRORS{'OK'}, 0, "attempt $attempt_count: $message");
if (&$code_ref(@{$args_array_ref})) {
notify($ERRORS{'OK'}, 0, "$message, code returned
true");
Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm?rev=1333476&r1=1333475&r2=1333476&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm Thu May 3 14:25:45
2012
@@ -396,7 +396,7 @@ sub wait_for_reboot {
wait delay: $attempt_delay_seconds");
# Wait for the computer to become unresponsive to ping
- if (!$self->wait_for_no_ping($total_wait_seconds,
$attempt_delay_seconds)) {
+ if (!$self->wait_for_no_ping($total_wait_seconds, 5)) {
# Computer never stopped responding to ping
notify($ERRORS{'WARNING'}, 0, "$computer_node_name
never became unresponsive to ping");
next ATTEMPT;
@@ -991,9 +991,6 @@ sub set_vcld_post_load_status {
if ($image_os_type =~ /windows/i) {
$command .= " && unix2dos currentimage.txt";
}
- else {
- $command .= " && dos2unix currentimage.txt";
- }
my ($exit_status, $output) = run_ssh_command($computer_node_name,
$management_node_keys, $command, '', '', 1);
if (defined($exit_status) && $exit_status == 0) {
@@ -1718,14 +1715,19 @@ sub create_text_file {
# Join the hex values together into a string
my $hex_string = join('', @hex_values);
+ # Enclose the file path in quotes if it contains any spaces
+ if ($file_path =~ / /) {
+ $file_path = "\"$file_path\"";
+ }
+
# Create a command to echo the hex string to the file
# Use -e to enable interpretation of backslash escapes
my $command .= "echo -n -e \"$hex_string\"";
if ($concatenate) {
- $command .= " >> \"$file_path\"";
+ $command .= " >> $file_path";
}
else {
- $command .= " > \"$file_path\"";
+ $command .= " > $file_path";
}
my ($exit_status, $output) = $self->execute($command);
@@ -1849,39 +1851,60 @@ return execute_new(@_);
=cut
sub execute_new {
- my $argument = shift;
- my ($computer_name, $command, $display_output, $timeout_seconds,
$max_attempts, $port, $user, $password, $identity_key);
-
+ my ($argument) = @_;
+ my ($computer_name, $command, $display_output, $timeout_seconds,
$max_attempts, $port, $user, $password, $identity_key, $ignore_error);
+
+ # Check if this subroutine was called as an object method
+ if (ref($argument) && ref($argument) =~ /VCL::Module/) {
+ # Subroutine was called as an object method ($self->execute)
+ my $self = shift;
+ ($argument) = @_;
+
+ #notify($ERRORS{'DEBUG'}, 0, "called as an object method: " .
ref($self));
+
+ # Get the computer name from the reservation data
+ $computer_name = $self->data->get_computer_node_name();
+ if (!$computer_name) {
+ notify($ERRORS{'WARNING'}, 0, "called as an object
method, failed to retrieve computer name from reservation data");
+ return;
+ }
+ #notify($ERRORS{'DEBUG'}, 0, "retrieved computer name from
reservation data: $computer_name");
+ }
+
# Check the argument type
- if (ref($argument) && ref($argument) eq 'HASH') {
- $computer_name = $argument->{node};
- $command = $argument->{command};
- $display_output = $argument->{display_output};
- $timeout_seconds = $argument->{timeout};
- $max_attempts = $argument->{max_attempts};
- $port = $argument->{port};
- $user = $argument->{user};
- $password = $argument->{password};
- $identity_key = $argument->{identity_key};
- }
- else {
- if (ref($argument)) {
- # Reference passed, not a hash reference, must be VCL
Module reference
- if ($argument->isa('VCL::Module')) {
- $computer_name =
$argument->data->get_computer_node_name();
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "invalid argument
reference type passed: " . ref($argument) . ", if a reference is passed as the
argument it may only be a hash or VCL::Module reference");
- return;
- }
+ if (ref($argument)) {
+ if (ref($argument) eq 'HASH') {
+ #notify($ERRORS{'DEBUG'}, 0, "first argument is a hash
reference:\n" . format_data($argument));
+
+ $computer_name = $argument->{node} if (!$computer_name);
+ $command = $argument->{command};
+ $display_output = $argument->{display_output};
+ $timeout_seconds = $argument->{timeout};
+ $max_attempts = $argument->{max_attempts};
+ $port = $argument->{port};
+ $user = $argument->{user};
+ $password = $argument->{password};
+ $identity_key = $argument->{identity_key};
+ $ignore_error = $argument->{ignore_error};
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "invalid argument
reference type passed: " . ref($argument) . ", if a reference is passed as the
argument it may only be a hash or VCL::Module reference");
+ return;
+ }
+ }
+ else {
+ # Argument is not a reference, computer name must be the first
argument unless this subroutine was called as an object method
+ # If called as an object method, $computer_name will already be
populated
+ if (!$computer_name) {
+ $computer_name = shift;
+ #notify($ERRORS{'DEBUG'}, 0, "first argument is a
scalar, should be the computer name: $computer_name, remaining arguments:\n" .
format_data(\@_));
}
else {
- # Argument is not a reference, computer name must be
the first argument
- $computer_name = $argument;
+ #notify($ERRORS{'DEBUG'}, 0, "first argument should be
the command:\n" . format_data(\@_));
}
# Get the remaining arguments
- ($command, $display_output, $timeout_seconds, $max_attempts,
$port, $user, $password, $identity_key) = @_;
+ ($command, $display_output, $timeout_seconds, $max_attempts,
$port, $user, $password, $identity_key, $ignore_error) = @_;
}
if (!$computer_name) {
@@ -1938,7 +1961,7 @@ sub execute_new {
raw_pty => 1,
no_terminal => 1,
ssh_option => $ssh_options,
- timeout => 3,
+ timeout => 5,
);
if ($ssh) {
@@ -1962,19 +1985,26 @@ sub execute_new {
# If false sets it to "absolute timeout"
#$ssh->restart_timeout_upon_receive(1);
my $initialization_output = $ssh->read_all();
- #notify($ERRORS{'DEBUG'}, 0, "SSH
initialization output:\n$initialization_output");
- if (defined($initialization_output) &&
$initialization_output =~ /password:/i) {
- if (defined($password)) {
- notify($ERRORS{'WARNING'}, 0,
"unable to connect to $computer_name, SSH is requesting a password but password
authentication is not implemented, password is configured,
output:\n$initialization_output");
- $return_null = 1;
- return;
- }
- else {
- notify($ERRORS{'WARNING'}, 0,
"unable to connect to $computer_name, SSH is requesting a password but password
authentication is not implemented, password is not configured,
output:\n$initialization_output");
- $return_null = 1;
- return;
+ if (defined($initialization_output)) {
+ notify($ERRORS{'DEBUG'}, 0, "SSH
initialization output:\n$initialization_output");
+ if ($initialization_output =~
/password:/i) {
+ if (defined($password)) {
+
notify($ERRORS{'WARNING'}, 0, "unable to connect to $computer_name, SSH is
requesting a password but password authentication is not implemented, password
is configured, output:\n$initialization_output");
+
+ # In EVAL block here,
'return' won't return from entire subroutine, set flag
+ $return_null = 1;
+ return;
+ }
+ else {
+
notify($ERRORS{'WARNING'}, 0, "unable to connect to $computer_name, SSH is
requesting a password but password authentication is not implemented, password
is not configured, output:\n$initialization_output");
+ $return_null = 1;
+ return;
+ }
}
}
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "SSH
initialization output is undefined");
+ }
};
return if ($return_null);
@@ -2007,16 +2037,20 @@ sub execute_new {
};
if ($EVAL_ERROR) {
- if ($EVAL_ERROR =~ /^(\w+) at \//) {
- notify($ERRORS{'DEBUG'}, 0, $attempt_string .
"$1 error occurred executing command on $computer_name: '$command'");
+ if ($ignore_error) {
+ notify($ERRORS{'DEBUG'}, 0, "executed command
on $computer_name: '$command', ignoring error, returning null");
+ return;
+ }
+ elsif ($EVAL_ERROR =~ /^(\w+) at \//) {
+ notify($ERRORS{'WARNING'}, 0, $attempt_string .
"$1 error occurred executing command on $computer_name: '$command'");
}
else {
- notify($ERRORS{'DEBUG'}, 0, $attempt_string .
"error occurred executing command on $computer_name: '$command'\nerror:
$EVAL_ERROR");
+ notify($ERRORS{'WARNING'}, 0, $attempt_string .
"error occurred executing command on $computer_name: '$command'\nerror:
$EVAL_ERROR");
}
next ATTEMPT;
}
elsif (!$ssh_wait_status) {
- notify($ERRORS{'DEBUG'}, 0, $attempt_string . "command
timed out after $timeout_seconds seconds on $computer_name: '$command'");
+ notify($ERRORS{'WARNING'}, 0, $attempt_string .
"command timed out after $timeout_seconds seconds on $computer_name:
'$command'");
next ATTEMPT;
}
@@ -2127,7 +2161,7 @@ sub manage_server_access {
my @userlist_admin;
my @userlist_login;
my %user_hash;
- my $allow_list;
+ my $allow_list = '';
if ($server_request_admingroupid) {
@userlist_admin =
getusergroupmembers($server_request_admingroupid);
@@ -2244,6 +2278,7 @@ sub manage_server_access {
}
$allow_list .= " $res_accounts{$res_userid}{username}";
}
+
notify($ERRORS{'OK'}, 0, "allow_list= $allow_list");
$self->data->set_server_allow_users($allow_list);
@@ -2337,7 +2372,7 @@ sub process_connect_methods {
#Disable firewall port
if (defined($port)) {
- notify($ERRORS{'DEBUG'}, 0, "attempting to open firewall port
$port on $computer_node_name for '$name' connect method");
+ notify($ERRORS{'DEBUG'}, 0, "attempting to close firewall port
$port on $computer_node_name for '$name' connect method");
if ($self->disable_firewall_port($protocol, $port, $remote_ip, 1))
{
notify($ERRORS{'OK'}, 0, "closing firewall port $port on
$computer_node_name for $remote_ip $name connect method");
}
@@ -2429,24 +2464,18 @@ sub is_user_connected {
my $computer_node_name = $self->data->get_computer_node_name();
my $request_state_name = $self->data->get_request_state_name();
my $user_unityid = $self->data->get_user_login_id();
- my $computer_ip_address = $self->data->get_computer_ip_address();
- my $remote_ip = $self->data->get_reservation_remote_ip();
my $connect_methods = $self->data->get_connect_methods();
my $start_time = time();
+ my $timeout_time = ($start_time + ($time_limit * 60));
my $time_exceeded = 0;
my $break = 0;
my $ret_val = "no";
# Figure out number of loops for log messages
- my $maximum_loops = $time_limit * 2;
- my $loop_count = 0;
-
- while (!$break) {
- $loop_count++;
-
- notify($ERRORS{'OK'}, 0, "checking for connection by
$user_unityid on $computer_node_name, attempt $loop_count ");
-
+ while (!$break) {
+ notify($ERRORS{'OK'}, 0, "checking for connection by
$user_unityid on $computer_node_name");
+
if (is_request_deleted($request_id)) {
notify($ERRORS{'OK'}, 0, "user has deleted request");
$break = 1;
@@ -2482,19 +2511,98 @@ sub is_user_connected {
}
}
else {
- notify($ERRORS{'CRITICAL'}, 0, "OS
module does not support check_connection" . ref($self));
+ notify($ERRORS{'CRITICAL'}, 0, "OS
module does not support check_connection_on_port: " . ref($self));
return;
}
}
}
- notify($ERRORS{'DEBUG'}, 0, "sleeping for 20 seconds");
- sleep 20;
+
+ my $current_time = time();
+ my $seconds_elapsed = ($current_time - $start_time);
+ my $seconds_until_timeout = ($timeout_time - $current_time);
+
+ notify($ERRORS{'DEBUG'}, 0, "$user_unityid has not connected to
$computer_node_name ($seconds_elapsed/$seconds_until_timeout seconds
elapsed/remaining), sleeping for 15 seconds");
+ sleep 15;
}
return $ret_val;
}
#/////////////////////////////////////////////////////////////////////////////
+=head2 copy_file
+
+ Parameters : $source_file_path, $destination_file_path
+ Returns : boolean
+ Description : Copies a file or directory on the computer to another location
on
+ the computer.
+
+=cut
+
+sub copy_file {
+ 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;
+ }
+
+ # Get the path arguments
+ my $source_file_path = shift;
+ my $destination_file_path = shift;
+ if (!$source_file_path || !$destination_file_path) {
+ notify($ERRORS{'WARNING'}, 0, "source and destination file path
arguments were not specified");
+ return;
+ }
+
+ # Normalize the source and destination paths
+ $source_file_path = normalize_file_path($source_file_path);
+ $destination_file_path = normalize_file_path($destination_file_path);
+
+ # Escape all spaces in the path
+ my $escaped_source_path = escape_file_path($source_file_path);
+ my $escaped_destination_path = escape_file_path($destination_file_path);
+
+ # Make sure the source and destination paths are different
+ if ($escaped_source_path eq $escaped_destination_path) {
+ notify($ERRORS{'WARNING'}, 0, "unable to copy file, source and
destination file path arguments are the same: $escaped_source_path");
+ return;
+ }
+
+ # Get the destination parent directory path and create the directory if
it does not exist
+ my $destination_directory_path =
parent_directory_path($destination_file_path);
+ if (!$destination_directory_path) {
+ notify($ERRORS{'WARNING'}, 0, "unable to determine destination
parent directory path: $destination_file_path");
+ return;
+ }
+ $self->create_directory($destination_directory_path) || return;
+
+ my $computer_node_name = $self->data->get_computer_node_name();
+
+ # Execute the command to copy the file
+ my $command = "cp -fr $escaped_source_path $escaped_destination_path";
+ notify($ERRORS{'DEBUG'}, 0, "attempting to copy file on
$computer_node_name: '$source_file_path' -> '$destination_file_path'");
+ my ($exit_status, $output) = $self->execute($command);
+ if (!defined($output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to copy
file on $computer_node_name:\nsource path: '$source_file_path'\ndestination
path: '$destination_file_path'\ncommand: '$command'");
+ return;
+ }
+ elsif (grep(/^cp: /i, @$output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to copy file on
$computer_node_name:\nsource path: '$source_file_path'\ndestination path:
'$destination_file_path'\ncommand: '$command'\noutput:\n" . join("\n",
@$output));
+ return;
+ }
+ elsif (!@$output || grep(/->/i, @$output)) {
+ notify($ERRORS{'OK'}, 0, "copied file on $computer_node_name:
'$source_file_path' --> '$destination_file_path'");
+ return 1;
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "unexpected output returned from
command to copy file on $computer_node_name:\nsource path:
'$source_file_path'\ndestination path: '$destination_file_path'\ncommand:
'$command'\noutput:\n" . join("\n", @$output));
+ return;
+ }
+
+ return 1;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
=head2 copy_file_to
Parameters : $source_path, $destination_path
@@ -2585,46 +2693,61 @@ sub find_files {
# Get the computer short and hostname
my $computer_node_name = $self->data->get_computer_node_name() ||
return;
- # Run the find command
- my $command = "/usr/bin/find \"$base_directory_path\"";
- if ($search_type) {
- if ($search_type =~ /regex/i) {
- $command .= " -type f -iregex \"$file_pattern\"";
+ my @find_commands = (
+ '/usr/bin/find',
+ 'find',
+ );
+
+ COMMAND: for my $find_command (@find_commands) {
+ # Run the find command
+ my $command = "$find_command \"$base_directory_path\"";
+
+ if ($search_type) {
+ if ($search_type =~ /regex/i) {
+ $command .= " -type f -iregex
\"$file_pattern\"";
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "invalid search
type argument was specified: '$search_type'");
+ return;
+ }
}
else {
- notify($ERRORS{'WARNING'}, 0, "invalid search type
argument was specified: '$search_type'");
+ $command .= " -type f -iname \"$file_pattern\"";
+ }
+
+ notify($ERRORS{'DEBUG'}, 0, "attempting to find files on
$computer_node_name, base directory path: '$base_directory_path', pattern:
$file_pattern, command: $command");
+
+ my ($exit_status, $output) = $self->execute($command, 0);
+ if (!defined($output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to
find files on $computer_node_name, base directory path: '$base_directory_path',
pattern: $file_pattern, command:\n$command");
return;
}
+ elsif (grep(/find:.*No such file or directory/i, @$output)) {
+ notify($ERRORS{'DEBUG'}, 0, "base directory does not
exist on $computer_node_name: $base_directory_path");
+ @$output = ();
+ }
+ elsif (grep(/find: not found/i, @$output)) {
+ # /usr/bin/find doesn't exist, try command without the
full path
+ notify($ERRORS{'DEBUG'}, 0, "'$find_command' command is
not present on $computer_node_name");
+ next;
+ }
+ elsif (grep(/find: /i, @$output)) {
+ notify($ERRORS{'WARNING'}, 0, "error occurred
attempting to find files on $computer_node_name\nbase directory path:
$base_directory_path\npattern: $file_pattern\ncommand: $command\noutput:\n" .
join("\n", @$output));
+ return;
+ }
+
+ my @files;
+ LINE: for my $line (@$output) {
+ push @files, $line;
+ }
+
+ my $file_count = scalar(@files);
+
+ notify($ERRORS{'DEBUG'}, 0, "files found: $file_count, base
directory: '$base_directory_path', pattern: '$file_pattern'\ncommand:
'$command', output:\n" . join("\n", @$output));
+ return @files;
}
- else {
- $command .= " -type f -iname \"$file_pattern\"";
- }
-
- notify($ERRORS{'DEBUG'}, 0, "attempting to find files on
$computer_node_name, base directory path: '$base_directory_path', pattern:
$file_pattern, command: $command");
-
- my ($exit_status, $output) = $self->execute($command, 0);
- if (!defined($output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to find
files on $computer_node_name, base directory path: '$base_directory_path',
pattern: $file_pattern, command:\n$command");
- return;
- }
- elsif (grep(/^find:.*No such file or directory/i, @$output)) {
- notify($ERRORS{'DEBUG'}, 0, "base directory does not exist on
$computer_node_name: $base_directory_path");
- @$output = ();
- }
- elsif (grep(/^find: /i, @$output)) {
- notify($ERRORS{'WARNING'}, 0, "error occurred attempting to
find files on $computer_node_name\nbase directory path:
$base_directory_path\npattern: $file_pattern\ncommand: $command\noutput:\n" .
join("\n", @$output));
- return;
- }
-
- my @files;
- LINE: for my $line (@$output) {
- push @files, $line;
- }
-
- my $file_count = scalar(@files);
- notify($ERRORS{'DEBUG'}, 0, "files found: $file_count, base directory:
'$base_directory_path', pattern: '$file_pattern'");
- return @files;
+ return;
}
#/////////////////////////////////////////////////////////////////////////////
@@ -2736,7 +2859,6 @@ sub get_tools_file_paths {
notify($ERRORS{'DEBUG'}, 0, "attempting for find tools files:\npattern:
$pattern\narchitecture: $architecture\nother architecture:
$other_architecture");
# Find files already on the computer
- #my $computer_directory_path = "$NODE_CONFIGURATION_DIRECTORY";
my $computer_directory_path = $self->get_node_configuration_directory();
my @existing_computer_file_array =
$self->find_files($computer_directory_path, '*');
my %existing_computer_files = map { $_ => 1 }
@existing_computer_file_array;
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=1333476&r1=1333475&r2=1333476&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Thu May 3
14:25:45 2012
@@ -148,14 +148,6 @@ sub pre_capture {
#Fetch exclude_list
my @exclude_list = $self->get_exclude_list();
- # Write /etc/rc.local script
- if(!(grep( /rc.local/ , @exclude_list ) ) ){
- if (!$self->generate_rc_local()){
- notify($ERRORS{'WARNING'}, 0, "unable to generate
/etc/rc.local script on $computer_node_name");
- return;
- }
- }
-
# Generate external_sshd_config
if(!(grep( /\/etc\/ssh\/external_sshd_config/ , @exclude_list ) ) ){
if(!$self->generate_ext_sshd_config()){
@@ -171,6 +163,14 @@ sub pre_capture {
return;
}
}
+
+ # Write /etc/rc.local script
+ if(!(grep( /rc.local/ , @exclude_list ) ) ){
+ if (!$self->generate_rc_local()){
+ notify($ERRORS{'WARNING'}, 0, "unable to generate
/etc/rc.local script on $computer_node_name");
+ return;
+ }
+ }
# Configure the private and public interfaces to use DHCP
if (!$self->enable_dhcp()) {
@@ -1773,81 +1773,6 @@ sub copy_file_from {
#/////////////////////////////////////////////////////////////////////////////
-=head2 copy_file
-
- Parameters : $source_file_path, $destination_file_path
- Returns : boolean
- Description : Copies a single file on the Linux computer to another location
on
- the computer. The source and destination file path arguments may
- not be directory paths nor may they contain wildcards.
-
-=cut
-
-sub copy_file {
- 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;
- }
-
- # Get the path arguments
- my $source_file_path = shift;
- my $destination_file_path = shift;
- if (!$source_file_path || !$destination_file_path) {
- notify($ERRORS{'WARNING'}, 0, "source and destination file path
arguments were not specified");
- return;
- }
-
- # Normalize the source and destination paths
- $source_file_path = normalize_file_path($source_file_path);
- $destination_file_path = normalize_file_path($destination_file_path);
-
- # Escape all spaces in the path
- my $escaped_source_path = escape_file_path($source_file_path);
- my $escaped_destination_path = escape_file_path($destination_file_path);
-
- # Make sure the source and destination paths are different
- if ($escaped_source_path eq $escaped_destination_path) {
- notify($ERRORS{'WARNING'}, 0, "unable to copy file, source and
destination file path arguments are the same: $escaped_source_path");
- return;
- }
-
- # Get the destination parent directory path and create the directory if
it does not exist
- my $destination_directory_path =
parent_directory_path($destination_file_path);
- if (!$destination_directory_path) {
- notify($ERRORS{'WARNING'}, 0, "unable to determine destination
parent directory path: $destination_file_path");
- return;
- }
- $self->create_directory($destination_directory_path) || return;
-
- my $computer_node_name = $self->data->get_computer_node_name();
-
- # Execute the command to copy the file
- my $command = "cp -fr $escaped_source_path $escaped_destination_path";
- notify($ERRORS{'DEBUG'}, 0, "attempting to copy file on
$computer_node_name: '$source_file_path' -> '$destination_file_path'");
- my ($exit_status, $output) = $self->execute($command);
- if (!defined($output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to copy
file on $computer_node_name:\nsource path: '$source_file_path'\ndestination
path: '$destination_file_path'\ncommand: '$command'");
- return;
- }
- elsif (grep(/^cp: /i, @$output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to copy file on
$computer_node_name:\nsource path: '$source_file_path'\ndestination path:
'$destination_file_path'\ncommand: '$command'\noutput:\n" . join("\n",
@$output));
- return;
- }
- elsif (!@$output || grep(/->/i, @$output)) {
- notify($ERRORS{'OK'}, 0, "copied file on $computer_node_name:
'$source_file_path' --> '$destination_file_path'");
- return 1;
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "unexpected output returned from
command to copy file on $computer_node_name:\nsource path:
'$source_file_path'\ndestination path: '$destination_file_path'\ncommand:
'$command'\noutput:\n" . join("\n", @$output));
- return;
- }
-
- return 1;
-}
-
-#/////////////////////////////////////////////////////////////////////////////
-
=head2 get_file_size
Parameters : @file_paths
@@ -2051,11 +1976,11 @@ sub set_file_permissions {
=cut
sub generate_rc_local {
- my $self = shift;
- if (ref($self) !~ /linux/i) {
- notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
- return 0;
- }
+ my $self = shift;
+ if (ref($self) !~ /linux/i) {
+ notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
+ return 0;
+ }
my $request_id = $self->data->get_request_id();
my $management_node_keys = $self->data->get_management_node_keys();
@@ -2190,7 +2115,7 @@ sub generate_rc_local {
}
}
-
+
return 1;
}
@@ -2296,7 +2221,7 @@ sub generate_ext_sshd_start {
notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it
must be called as a class method");
return 0;
}
-
+
# If using systemd, check for the systemctl command
if($self->file_exists("/bin/systemctl") ) {
if(!($self->generate_ext_sshd_systemd)) {
@@ -3273,7 +3198,7 @@ sub stop_service {
#/////////////////////////////////////////////////////////////////////////////
-=head2 check_connection
+=head2 check_connection_on_port
Parameters : $port
Returns : (connected|conn_wrong_ip|timeout|failed)
Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm?rev=1333476&r1=1333475&r2=1333476&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Thu May 3
14:25:45 2012
@@ -10709,7 +10709,7 @@ sub get_environment_variable_value {
#/////////////////////////////////////////////////////////////////////////////
-=head2 check_connection
+=head2 check_connection_on_port
Parameters : $port
Returns : (connected|conn_wrong_ip|timeout|failed)
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=1333476&r1=1333475&r2=1333476&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt.pm
(original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt.pm
Thu May 3 14:25:45 2012
@@ -89,7 +89,7 @@ sub initialize {
notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
return;
}
-
+
my $node_name = $self->data->get_vmhost_short_name();
my $vmhost_username = $self->data->get_vmhost_profile_username();
my $vmhost_password = $self->data->get_vmhost_profile_password();
@@ -129,10 +129,11 @@ sub initialize {
notify($ERRORS{'DEBUG'}, 0, "libvirt $driver_name
driver object could not be initialized to control $node_name");
}
}
-
+
# Make sure the driver module object was successfully initialized
if (!$self->driver()) {
notify($ERRORS{'WARNING'}, 0, "failed to initialize libvirt
provisioning module, driver object could not be created and initialized");
+ return;
}
notify($ERRORS{'DEBUG'}, 0, ref($self) . " provisioning module
initialized");
Modified:
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt/KVM.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt/KVM.pm?rev=1333476&r1=1333475&r2=1333476&view=diff
==============================================================================
---
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt/KVM.pm
(original)
+++
incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/libvirt/KVM.pm
Thu May 3 14:25:45 2012
@@ -82,16 +82,37 @@ sub initialize {
my $node_name = $self->data->get_vmhost_short_name();
my ($driver_name) = ref($self) =~ /::([^:]+)$/;
- # Check to see if qemu exists on the VM host
- my $test_file_path = '/usr/bin/qemu';
- if ($self->vmhost_os->file_exists($test_file_path)) {
- notify($ERRORS{'DEBUG'}, 0, "$driver_name driver module
successfully initialized, verified '$test_file_path' exists on $node_name");
- return 1;
+ # Check to see if required commands exist on the VM host
+ my @test_commands = (
+ 'virsh',
+ 'qemu-img',
+ 'virt-win-reg',
+ );
+
+ my @missing_commands;
+ for my $command (@test_commands) {
+ my ($exit_status, $output) = $self->vmhost_os->execute("which
$command");
+ if (!defined($output)) {
+ notify($ERRORS{'WARNING'}, 0, "unable to initialize
$driver_name driver module to control $node_name, failed to execute command to
determine if the '$command' command is available");
+ return;
+ }
+ elsif (grep(/(which:|no $command)/, @$output)) {
+ notify($ERRORS{'DEBUG'}, 0, "'$command' command is NOT
available on $node_name");
+ push @missing_commands, $command;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "verified '$command'
command is available on $node_name");
+ }
}
- else {
- notify($ERRORS{'DEBUG'}, 0, "$driver_name driver module not
initialized, '$test_file_path' does NOT exist on $node_name");
+
+ if (@missing_commands) {
+ notify($ERRORS{'DEBUG'}, 0, "unable to initialize $driver_name
driver module to control $node_name, the following commands are not
available:\n" . join("\n", @missing_commands));
return;
}
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "$driver_name driver module
successfully initialized to control $node_name");
+ return 1;
+ }
}
#/////////////////////////////////////////////////////////////////////////////
@@ -197,7 +218,7 @@ sub pre_define {
}
}
else {
- notify($ERRORS{'WARNING'}, 0, "unable to prepare
virtual disk, failed to locate virtual disk file in the repository");
+ notify($ERRORS{'WARNING'}, 0, "unable to prepare
virtual disk, master image file could NOT be located, it does not exist in the
datastore and node $node_name is not configured to use an image repository");
return;
}
@@ -484,9 +505,6 @@ sub copy_virtual_disk {
# Get the size of all of the source files
my $source_size_bytes =
$self->get_virtual_disk_size_bytes(@source_file_paths) || 0;
- # Join the array of file paths into a string
- my $source_file_paths_string = join('" "', @source_file_paths);
-
# Make sure the destination file extension matches the disk format
my ($destination_file_name, $destination_directory_path,
$destination_file_extension) = fileparse($destination_file_path, qr/\.[^.]*/);
if (!$destination_file_extension) {
@@ -498,26 +516,70 @@ sub copy_virtual_disk {
return;
}
+ # Remove trailing space from directory path
+ $destination_directory_path =~ s/\/+$//;
+
# Attempt to create the parent directory
if (!$self->vmhost_os->create_directory($destination_directory_path)) {
notify($ERRORS{'WARNING'}, 0, "unable to copy virtual disk,
failed to create destination parent directory: $destination_directory_path");
return;
}
- my $start_time = time;
- #my $command = "qemu-img convert -O $disk_format -o
preallocation=metadata \"$source_file_paths_string\"
\"$destination_file_path\"";
- my $command = "qemu-img convert -O $disk_format
\"$source_file_paths_string\" \"$destination_file_path\"";
-
my $source_file_count = scalar(@source_file_paths);
- my $copy_info_string = "source file paths ($source_file_count):\n" .
get_array_summary_string(@source_file_paths) . "\n";
- $copy_info_string .= "source size: " .
get_file_size_info_string($source_size_bytes) . "\n";
- $copy_info_string .= "destination file path: $destination_file_path\n";
- $copy_info_string .= "destination format: $disk_format\n";
+ my $source_file_paths_string;
+ my $convert_to_raw = 0;
- notify($ERRORS{'DEBUG'}, 0, "attempting to copy/convert virtual disk on
$node_name:\n$copy_info_string");
+ # Check if the source file paths appear to be in the 2GB sparse vmdk
format
+ # qemu-img included in anything earlier than Fedora 16 doesn't handle
this properly
+ if ($source_file_count > 1 && $source_file_paths[0] =~ /-s\d+\.vmdk$/i)
{
+ $convert_to_raw = 1;
+ for my $source_file_path (@source_file_paths) {
+ my ($source_file_name, $source_directory_path,
$source_file_extension) = fileparse($source_file_path, qr/\.[^.]*/);
+
+ my $raw_file_path =
"$destination_directory_path/$source_file_name.raw";
+ $source_file_paths_string .= "\"$raw_file_path\" ";
+
+ # Convert from raw to raw
+ # There seems to be a bug in qemu-img if you specify
"-f vmdk", it results in a empty file
+ # Leaving the -f option off also results in an empty
file
+ my $command = "qemu-img convert -f raw
\"$source_file_path\" -O raw \"$raw_file_path\" && qemu-img info
\"$raw_file_path\"";
+
+ notify($ERRORS{'DEBUG'}, 0, "attempting to convert vmdk
file to raw format: $source_file_path --> $raw_file_path");
+ my ($exit_status, $output) =
$self->vmhost_os->execute($command, 0, 1800);
+ if (!defined($exit_status)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to
execute command to convert vmdk file to raw format:\n$command");
+ return;
+ }
+ elsif ($exit_status) {
+ notify($ERRORS{'WARNING'}, 0, "failed to
convert vmdk file to raw format on $node_name\ncommand: '$command'\noutput:\n"
. join("\n", @$output));
+ return;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "converted vmdk
file to raw format on $node_name: $source_file_path --> $raw_file_path,
output:\n" . join("\n", @$output));
+ }
+ }
+
+ # Remove trailing last space
+ $source_file_paths_string =~ s/\s+$//;
+ }
+ else {
+ # Join the array of file paths into a string
+ $source_file_paths_string = join('" "', @source_file_paths);
+ }
+
+ my $command = "qemu-img convert $source_file_paths_string -O
$disk_format \"$destination_file_path\" && qemu-img info
\"$destination_file_path\"";
+
+ # If the image had to be converted to raw format first, add command to
delete raw files
+ if ($convert_to_raw) {
+ $command .= " ; rm -f $source_file_paths_string";
+ }
+
+ notify($ERRORS{'DEBUG'}, 0, "attempting to copy/convert virtual disk to
$disk_format format --> $destination_file_path");
+
+ my $start_time = time;
my ($exit_status, $output) = $self->vmhost_os->execute($command, 0,
1800);
if (!defined($exit_status)) {
- notify($ERRORS{'WARNING'}, 0, "failed to execute command to
convert image $node_name: '$command'");
+ notify($ERRORS{'WARNING'}, 0, "failed to execute command to
copy/convert virtual disk on $node_name:\n$command");
return;
}
elsif ($exit_status) {
@@ -538,12 +600,11 @@ sub copy_virtual_disk {
}
my $destination_size_bytes =
$self->get_virtual_disk_size_bytes($destination_file_path) || 0;
- $copy_info_string .= "destination size: " .
get_file_size_info_string($destination_size_bytes) . "\n" .
# Get a string which displays various copy rate information
- $copy_info_string .=
get_copy_speed_info_string($destination_size_bytes, $duration_seconds);
+ my $copy_speed_info_string =
get_copy_speed_info_string($destination_size_bytes, $duration_seconds);
- notify($ERRORS{'OK'}, 0, "copied virtual disk on
$node_name:\n$copy_info_string");
+ notify($ERRORS{'OK'}, 0, "copied virtual disk on $node_name, output:\n"
. join("\n", @$output) . "\n---\n$copy_speed_info_string");
return 1;
}
Modified: incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm?rev=1333476&r1=1333475&r2=1333476&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm Thu May 3 14:25:45
2012
@@ -287,14 +287,7 @@ sub process {
goto RETVALCONN;
} ## end else [ if (defined $remote_ip && $remote_ip eq '0') [...
[elsif ($acknowledge_attempts < 180)
- if($self->os->can("is_user_connected")) {
- #Use new code if it exists
- $retval_conn = $self->os->is_user_connected($time_limit);
- }
- else {
- #use old code
- $retval_conn = check_connection($nodename,
$computer_ip_address, $computer_type, $remote_ip, $time_limit, $image_os_name,
0, $request_id, $user_unityid,$image_os_type);
- }
+ $retval_conn = $self->os->is_user_connected($time_limit);
if ($retval_conn eq "nologin") {
Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1333476&r1=1333475&r2=1333476&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Thu May 3 14:25:45 2012
@@ -88,7 +88,6 @@ our @EXPORT = qw(
_sshd_status
changelinuxpassword
check_blockrequest_time
- check_connection
check_endtimenotice_interval
check_ssh
check_time
@@ -1333,257 +1332,6 @@ sub _checknstartservice {
#/////////////////////////////////////////////////////////////////////////////
-=head2 check_connection
-
- Parameters : $nodename, $ipaddress, $type, $remoteIP, $time_limit, $osname,
$dbh, $requestid, $user
- Returns : value - deleted failed timeout connected conn_wrong_ip
- Description : uses ssh to log into remote node and preform checks on user
connection
-=cut
-
-sub check_connection {
- my ($nodename, $ipaddress, $type, $remoteIP, $time_limit, $osname,
$dbh, $requestid, $user,$image_os_type) = @_;
- my ($package, $filename, $line, $sub) = caller(0);
- notify($ERRORS{'OK'}, 0, "nodename not set") if (!defined($nodename));
- notify($ERRORS{'OK'}, 0, "ipaddress not set") if
(!defined($ipaddress));
- notify($ERRORS{'OK'}, 0, "type not set") if (!defined($type));
- notify($ERRORS{'OK'}, 0, "remoteIP not set") if (!defined($remoteIP));
- notify($ERRORS{'OK'}, 0, "time_limit not set") if
(!defined($time_limit));
- notify($ERRORS{'OK'}, 0, "osname not set") if (!defined($osname));
- notify($ERRORS{'OK'}, 0, "dbh not set") if (!defined($dbh));
- notify($ERRORS{'OK'}, 0, "requestid not set") if
(!defined($requestid));
- notify($ERRORS{'OK'}, 0, "user not set") if (!defined($user));
- notify($ERRORS{'OK'}, 0, "image_os_type not set") if
(!defined($image_os_type));
-
- my $start_time = time();
- my $time_exceeded = 0;
- my $break = 0;
- my $ret_val = "no";
-
- $dbh = getnewdbh() if !$dbh;
- my $identity_keys = get_management_node_info()->{keys};
-
- # Figure out number of loops for log messates
- my $maximum_loops = $time_limit * 2;
- my $loop_count = 0;
- my @SSHCMD;
-
- while (!$break) {
- $loop_count++;
-
- notify($ERRORS{'OK'}, 0, "checking for connection by $user on
$nodename, attempt $loop_count ");
-
- # confirm we still have an active db handle
- if (!$dbh || !($dbh->ping)) {
- notify($ERRORS{'WARNING'}, 0, "database handle died,
trying to create another one");
- $dbh = getnewdbh();
- notify($ERRORS{'OK'}, 0, "database handle re-set") if
($dbh->ping);
- notify($ERRORS{'WARNING'}, 0, "inuse process: database
handle NOT re-set") if (!($dbh->ping));
- }
- if (is_request_deleted($requestid)) {
- notify($ERRORS{'OK'}, 0, "user has deleted request");
- $break = 1;
- $ret_val = "deleted";
- return $ret_val;
- }
- #notify($ERRORS{'OK'},0,"comparing wait time for connection");
- $time_exceeded = time_exceeded($start_time, $time_limit);
- if ($time_exceeded) {
- notify($ERRORS{'OK'}, 0, "$time_limit minute time limit
exceeded begin cleanup process");
- #time_exceeded, begin cleanup process
- $break = 1;
- if ($package =~ /reserved/) {
- notify($ERRORS{'OK'}, 0, "user never logged in
returning nologin");
- $ret_val = "nologin";
- }
- else {
- $ret_val = "timeout";
- }
- return $ret_val;
- } ## end if ($time_exceeded)
- else { #time not exceeded check for connection
- if ($type =~ /blade|virtualmachine/) {
- my $shortnodename = $nodename;
- $shortnodename = $1 if ($nodename =~
/([-_a-zA-Z0-9]*)\./);
- if ($image_os_type =~ /windows/i) {
- undef @SSHCMD;
- @SSHCMD =
run_ssh_command($shortnodename, $identity_keys, "netstat -an", "root", 22, 1);
- foreach my $line (@{$SSHCMD[1]}) {
- #check for rdp and ssh
connections
- # rdp:3389,ssh:22
- #check for connection refused,
if ssh is gone something
- #has happenned put in timeout
state
- if ($line =~ /Connection
refused|Permission denied/) {
- chomp($line);
-
notify($ERRORS{'WARNING'}, 0, "$line");
- if ($package =~
/reserved/) {
- $ret_val =
"failed";
- }
- else {
- $ret_val =
"timeout";
- }
- return $ret_val;
- } ## end if ($line =~
/Connection refused|Permission denied/)
- if ($line =~
/\s+($ipaddress:3389)\s+([.0-9]*):([0-9]*)\s+(ESTABLISHED)/) {
- if ($2 eq $remoteIP) {
- $break = 1;
- $ret_val =
"connected";
- return $ret_val;
- }
- else {
- #this isn't the
remoteIP
- $ret_val =
"conn_wrong_ip";
- return $ret_val;
- }
- } ## end if ($line =~
/\s+($ipaddress:3389)\s+([.0-9]*):([0-9]*)\s+(ESTABLISHED)/)
- } #foreach
-
- } ## end if ($osname =~ /win|vmwarewin/)
- elsif ($image_os_type =~ /osx/i) {
- undef @SSHCMD;
- @SSHCMD =
run_ssh_command($shortnodename, $identity_keys, "netstat -an", "root", 22, 1);
- foreach my $line (@{$SSHCMD[1]}) {
- #check for rdp
connections
- # rdp:3389
- #check for
connection refused, if ssh is gone something
- #has happenned
put in timeout state
- if ($line =~
/Connection refused|Permission denied/) {
-
chomp($line);
-
notify($ERRORS{'WARNING'}, 0, "$line");
-
if ($package =~ /reserved/) {
-
$ret_val = "failed";
-
}
-
else {
-
$ret_val = "timeout";
-
}
-
return $ret_val;
- } ## end if
($line =~ /Connection refused|Permission denied/)
- if ($line =~
/tcp4\s+([0-9]*)\s+([0-9]*)\s+($ipaddress.3389)\s+([.0-9]*).([0-9]*)(.*)(ESTABLISHED)/)
{
- if ($4
eq $remoteIP) {
-
$break = 1;
-
$ret_val = "connected";
-
return $ret_val;
- }
- else {
-
#this isn't the remoteIP
-
$ret_val = "conn_wrong_ip";
-
return $ret_val;
- }
- } ## end tcp4
check
- } #foreach
-
- } ## end if ($osname =~ /osx/)
- elsif ($image_os_type =~ /linux/i) {
- #run two checks
- # 1:check connected IP address
- # 2:simply check who ouput
- my @lines;
- undef @SSHCMD;
- @SSHCMD =
run_ssh_command($shortnodename, $identity_keys, "netstat -an", "root", 22, 1);
- foreach my $line (@{$SSHCMD[1]}) {
- if ($line =~ /Connection
refused|Permission denied/) {
- chomp($line);
-
notify($ERRORS{'WARNING'}, 0, "$line");
- if ($package =~
/reserved/) {
- $ret_val =
"failed";
- }
- else {
- $ret_val =
"timeout";
- }
- return $ret_val;
- } ## end if ($line =~
/Connection refused|Permission denied/)
- if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s($ipaddress:22)\s+([.0-9]*):([0-9]*)(.*)(ESTABLISHED)/)
{
- if ($4 eq $remoteIP) {
- $break = 1;
- $ret_val =
"connected";
- return $ret_val;
- }
- else {
- #this isn't the
remoteIP
- $ret_val =
"conn_wrong_ip";
- return $ret_val;
- }
- } # tcp check
- } #foreach
- #who; too make sure we didn't miss
it through netstat
- undef @SSHCMD;
- @SSHCMD =
run_ssh_command($shortnodename, $identity_keys, "who", "root");
- foreach my $w (@{$SSHCMD[1]}) {
- if ($w =~ /$user/) {
- $break = 1;
-
notify($ERRORS{'CRITICAL'}, 0, "found user connected through who command on
node $nodename , strange that netstat missed it\nnetstat output:\n @lines");
- $ret_val = "connected";
- return $ret_val;
- }
- }
-
- } ## end elsif ($image_os_type =~ /linux/) [ if
($osname =~ /windows/)
- } ## end if ($type =~ /blade|virtualmachine/)
- elsif ($type eq "lab") {
- undef @SSHCMD;
- @SSHCMD = run_ssh_command($nodename,
$identity_keys, "netstat -an", "vclstaff", 24, 1);
- foreach my $line (@{$SSHCMD[1]}) {
- chomp($line);
- if ($line =~ /Connection
refused|Permission denied/) {
- notify($ERRORS{'WARNING'}, 0,
"$line");
- if ($package =~ /reserved/) {
- $ret_val = "failed";
- }
- else {
- $ret_val = "timeout";
- }
- return $ret_val;
- } ## end if ($line =~ /Connection
refused|Permission denied/)
- if ($osname =~ /sun4x_/) {
- if ($line =~
/\s*($ipaddress\.22)\s+([.0-9]*)\.([0-9]*)(.*)(ESTABLISHED)/) {
- if ($2 eq $remoteIP) {
- $break = 1;
- $ret_val =
"connected";
- return $ret_val;
- }
- else {
- #this isn't the
remoteIP
- $ret_val =
"conn_wrong_ip";
- return $ret_val;
- }
- } ## end if ($line =~
/\s*($ipaddress\.22)\s+([.0-9]*)\.([0-9]*)(.*)(ESTABLISHED)/)
- } ## end if ($osname =~ /sun4x_/)
- elsif ($osname =~ /rhel/) {
- if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s($ipaddress:22)\s+([.0-9]*):([0-9]*)(.*)(ESTABLISHED)/)
{
- if ($4 eq $remoteIP) {
- $break = 1;
- $ret_val =
"connected";
- return $ret_val;
- }
- else {
- #this isn't the
remoteIP
- $ret_val =
"conn_wrong_ip";
- return $ret_val;
- }
- } ## end if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s($ipaddress:22)\s+([.0-9]*):([0-9]*)(.*)(ESTABLISHED)/)
- if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s::ffff:($ipaddress:22)\s+::ffff:([.0-9]*):([0-9]*)(.*)(ESTABLISHED)
/) {
- if ($4 eq $remoteIP) {
- $break = 1;
- $ret_val =
"connected";
- return $ret_val;
- }
- else {
- #this isn't the
remoteIP
- $ret_val =
"conn_wrong_ip";
- return $ret_val;
- }
- } ## end if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s::ffff:($ipaddress:22)\s+::ffff:([.0-9]*):([0-9]*)(.*)(ESTABLISHED)
/)
- } ## end elsif ($osname =~ /rhel/) [
if ($osname =~ /sun4x_/)
- } #foreach
- } #if lab
- }
- notify($ERRORS{'DEBUG'}, 0, "sleeping for 20 seconds");
- sleep 20;
- }
- return $ret_val;
-} ## end sub check_connection
-
-#/////////////////////////////////////////////////////////////////////////////
-
=head2 isconnected
Parameters : $nodename, $type, $remoteIP, $osname, $ipaddress