Author: fapeeler
Date: Fri Sep  2 15:09:54 2011
New Revision: 1164572

URL: http://svn.apache.org/viewvc?rev=1164572&view=rev
Log:
VCL-30

initial work for the ability to add different connection methods 


Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.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/Linux/UnixLab.pm
    incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
    incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm
    incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm
    incubator/vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm?rev=1164572&r1=1164571&r2=1164572&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm Fri Sep  2 
15:09:54 2011
@@ -409,6 +409,8 @@ $SUBROUTINE_MAPPINGS{imagerevision_produ
 $SUBROUTINE_MAPPINGS{imagerevision_revision}   = 
'$self->request_data->{reservation}{RESERVATION_ID}{imagerevision}{revision}';
 $SUBROUTINE_MAPPINGS{imagerevision_userid}     = 
'$self->request_data->{reservation}{RESERVATION_ID}{imagerevision}{userid}';
 
+$SUBROUTINE_MAPPINGS{connect_methods}          = 
'$self->request_data->{reservation}{RESERVATION_ID}{connect_methods}';
+
 #$SUBROUTINE_MAPPINGS{management_node_id} = 
'$self->request_data->{reservation}{RESERVATION_ID}{managementnode}{id}';
 #$SUBROUTINE_MAPPINGS{management_node_ipaddress} = 
'$self->request_data->{reservation}{RESERVATION_ID}{managementnode}{IPaddress}';
 #$SUBROUTINE_MAPPINGS{management_node_hostname} = 
'$self->request_data->{reservation}{RESERVATION_ID}{managementnode}{hostname}';

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=1164572&r1=1164571&r2=1164572&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm Fri Sep  2 15:09:54 
2011
@@ -1788,6 +1788,198 @@ sub manage_server_access {
 
 }
 
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 process_connect_methods
+
+ Parameters  : None
+ Returns     : If successful: 1
+               If failed: 0
+ Description : starts and open port for available connection methods
+
+=cut
+
+sub process_connect_methods {
+       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 $mode = shift;
+       if (!$mode) {
+               notify($ERRORS{'OK'}, 0, "Mode variable not passed in as an 
argument");
+               return 0;
+       }
+       
+       my $computer_node_name   = $self->data->get_computer_node_name();
+       my $connect_methods      = $self->data->get_connect_methods();
+
+       foreach my $CMid (sort keys %{$connect_methods} ) {
+               
+                notify($ERRORS{'OK'}, 0, "id= $$connect_methods{$CMid}{id}") 
if(defined ($$connect_methods{$CMid}{id}) );
+                notify($ERRORS{'OK'}, 0, "description= 
$$connect_methods{$CMid}{description}") if(defined 
($$connect_methods{$CMid}{description}) );
+                notify($ERRORS{'OK'}, 0, "port== 
$$connect_methods{$CMid}{port}") if(defined ($$connect_methods{$CMid}{port}) );
+                notify($ERRORS{'OK'}, 0, "servicename= 
$$connect_methods{$CMid}{servicename}") if(defined 
($$connect_methods{$CMid}{servicename}) );
+                notify($ERRORS{'OK'}, 0, "startupscript= 
$$connect_methods{$CMid}{startupscript}") if(defined 
($$connect_methods{$CMid}{startupscript}) );
+                notify($ERRORS{'OK'}, 0, "autoprov= 
$$connect_methods{$CMid}{autoprovisioned}") if(defined 
($$connect_methods{$CMid}{autoprovisioned}) );
+               my $description = $$connect_methods{$CMid}{description};
+               my $port = $$connect_methods{$CMid}{port};
+               
+               my $service_started = 0;        
+               notify($ERRORS{'OK'}, 0, "checking if servicename exists ");
+               if( defined ($$connect_methods{$CMid}{servicename}) && 
$$connect_methods{$CMid}{servicename} ) {        
+                       # does service exist
+                       my $servicename = $$connect_methods{$CMid}{servicename};
+                       notify($ERRORS{'OK'}, 0, "trying to start servicename 
$servicename ");
+                       if( $self->can("service_exists")) {
+                               if($self->service_exists($servicename)) {
+                                       if( $self->can("start_service")) {
+                                               if( 
$self->start_service($servicename) ) {
+                                                       notify($ERRORS{'OK'}, 
0, "Service $servicename started");
+                                                       $service_started = 1;
+                                               }
+                                               else {
+                                                       
notify($ERRORS{'WARNING'}, 0, "Service $servicename failed to start");
+                                               }
+                                       }
+                               }
+                               else {
+                                       notify($ERRORS{'WARNING'}, 0, "Service 
$servicename does not exist on $computer_node_name");
+                               }
+                       }
+                       else {
+                               notify($ERRORS{'WARNING'}, 0, "service_exists 
not implemented by OS module" . ref($self));
+                       }
+               }
+               
+               if ( !$service_started && defined 
($$connect_methods{$CMid}{startupscript} ) ) {
+                       notify($ERRORS{'OK'}, 0, "startupscript exists and 
service NOT started ");
+
+                       #Service command did not work or does not exist
+                       # Try to use startup script
+                       my $cmd = $$connect_methods{$CMid}{startupscript} . " 
start";
+                       notify($ERRORS{'OK'}, 0, "service not started, attempt 
to run $cmd ");
+                       if( $self->can("execute") ) {
+                               if( $self->execute($cmd, 1) ){
+                               $service_started = 1;   
+                               }       
+                       }
+                       else {
+                               notify($ERRORS{'OK'}, 0, "execute routing not 
available by module" . ref($self) );      
+                       }
+               }       
+               
+               if ( $service_started ) {
+                       #open firewall port
+                       notify($ERRORS{'OK'}, 0, "service started ");
+                       if($self->can("enable_firewall_port")) {
+                       notify($ERRORS{'OK'}, 0, "trying to enable firewall 
port $port on $computer_node_name ");
+                               if(!$self->enable_firewall_port($port)) {
+                               notify($ERRORS{'CRITICAL'}, 0, "Failed to 
enable firewall Connect Method $CMid $description on $computer_node_name");
+                               }
+                       }
+               }
+               else {
+                       notify($ERRORS{'CRITICAL'}, 0, "Connect Method $CMid 
$description failed to start on $computer_node_name");
+               }
+          }
+
+       return 1;       
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 is_user_connected
+
+ Parameters  : None
+ Returns     : If successful: string
+               If failed: false
+ Description : Determines is user is connected.
+
+=cut
+
+sub is_user_connected {
+       
+       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 $time_limit = shift;
+       if ( !$time_limit ) {
+               notify($ERRORS{'WARNING'}, 0, "time_limit variable not passed 
as an argument");
+               return "failed";
+       }
+
+       my $request_id           = $self->data->get_request_id();       
+        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 $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 ");
+
+                if (is_request_deleted($request_id)) {
+                        notify($ERRORS{'OK'}, 0, "user has deleted request");
+                        $break   = 1;
+                        $ret_val = "deleted";
+                        return $ret_val;
+                }
+               
+               $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 ($request_state_name =~ /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
+                       foreach my $CMid (sort keys %{$connect_methods} ) {
+                               if($self->can("check_connection_on_port")) {
+                                       
if(defined($$connect_methods{$CMid}{port}) && $$connect_methods{$CMid}{port}) {
+                                               my $connect_state = 
$self->check_connection_on_port($$connect_methods{$CMid}{port});
+                                               if($connect_state =~ 
/(connected|conn_wrong_ip|timeout|failed)/i){
+                                                       return $connect_state   
+                                               }
+                                       }
+                                       else {
+                                               notify($ERRORS{'WARNING'}, 0, 
"port not defined for connectMethod id $CMid");
+                                       }
+                               }
+                               else {
+                                       notify($ERRORS{'CRITICAL'}, 0, "OS 
module does not support check_connection" . ref($self));
+                                       return;
+                               }
+                       }
+               }
+               notify($ERRORS{'DEBUG'}, 0, "sleeping for 20 seconds");
+                sleep 20;
+       }       
+       return $ret_val;
+}
+
 #///////////////////////////////////////////////////////////////////////////
 
 1;

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=1164572&r1=1164571&r2=1164572&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Fri Sep  2 
15:09:54 2011
@@ -916,6 +916,10 @@ sub grant_access {
        }    #foreach
        notify($ERRORS{'OK'}, 0, "started ext_sshd on $computer_node_name");
 
+       if($self->process_connect_methods('start') ){
+               notify($ERRORS{'OK'}, 0, "processed connection methods on 
$computer_node_name");
+       }
+
        
        return 1;
 } ## end sub grant_access
@@ -1205,53 +1209,6 @@ sub call_post_load_custom {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 execute
-
- Parameters  : $command, $display_output (optional)
- Returns     : array ($exit_status, $output)
- Description : Executes a command on the Linux computer via SSH.
-
-=cut
-
-sub execute {
-       my $self = shift;
-       unless (ref($self) && $self->isa('VCL::Module')) {
-               notify($ERRORS{'CRITICAL'}, 0, "subroutine can only be called 
as an object method");
-               return;
-       }
-       
-       # Get the command argument
-       my $command = shift;
-       if (!$command) {
-               notify($ERRORS{'WARNING'}, 0, "command argument was not 
specified");
-               return;
-       }
-       
-       # Get 2nd display output argument if supplied, or set default value
-       my $display_output = shift || '0';
-       
-       # Get the computer node name
-       my $computer_name = $self->data->get_computer_node_name() || return;
-       
-       # Get the identity keys used by the management node
-       my $management_node_keys = $self->data->get_management_node_keys() || 
'';
-       
-       # Run the command via SSH
-       my ($exit_status, $output) = run_ssh_command($computer_name, 
$management_node_keys, $command, '', '', $display_output);
-       if (defined($exit_status) && defined($output)) {
-               if ($display_output) {
-                       notify($ERRORS{'OK'}, 0, "executed command: '$command', 
exit status: $exit_status, output:\n" . join("\n", @$output));
-               }
-               return ($exit_status, $output);
-       }
-       else {
-               notify($ERRORS{'WARNING'}, 0, "failed to run command on 
$computer_name: $command");
-               return;
-       }
-}
-
-#/////////////////////////////////////////////////////////////////////////////
-
 =head2 run_script
 
  Parameters  : script path
@@ -3031,6 +2988,217 @@ EOF
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 service_exists
+
+ Parameters  : $service_name
+ Returns     : If service exists: 1
+               If service does not exist: 0
+               If error occurred: undefined
+ Description : 
+
+=cut
+
+sub service_exists {
+        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;
+        }
+
+        my $management_node_keys = $self->data->get_management_node_keys();
+        my $computer_node_name   = $self->data->get_computer_node_name();
+
+        my $service_name = shift;
+        if (!$service_name) {
+                notify($ERRORS{'WARNING'}, 0, "service name was not passed as 
an argument");
+                return;
+        }
+
+       my $command = "/sbin/chkconfig --list $service_name";
+       my ($status, $output) = run_ssh_command($computer_node_name, 
$management_node_keys, $command, '', '', 1);
+       if (defined($output) && grep(/error reading information on service/i, 
@{$output})) {
+                notify($ERRORS{'DEBUG'}, 0, "service does not exist: 
$service_name");
+                return 0;
+        }
+        elsif (defined($status) && $status == 0) {
+                notify($ERRORS{'DEBUG'}, 0, "service exists: $service_name");
+        }
+        elsif (defined($status)) {
+                notify($ERRORS{'WARNING'}, 0, "unable to determine if service 
exists: $service_name, exit status: $status, output:\n@{$output}");
+                return;
+        }
+        else {
+                notify($ERRORS{'WARNING'}, 0, "unable to run ssh command to 
determine if service exists");
+                return;
+        }
+
+        return 1;
+       
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 start_service
+
+ Parameters  : $service_name
+ Returns     : If service started: 1
+               If service not started: 0
+               If error occurred: undefined
+ Description : 
+
+=cut
+
+sub start_service {
+        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;
+        }
+
+        my $management_node_keys = $self->data->get_management_node_keys();
+        my $computer_node_name   = $self->data->get_computer_node_name();
+
+        my $service_name = shift;
+        if (!$service_name) {
+                notify($ERRORS{'WARNING'}, 0, "service name was not passed as 
an argument");
+                return;
+        }
+
+       my $command = "/sbin/service $service_name start";
+       my ($status, $output) = run_ssh_command($computer_node_name, 
$management_node_keys, $command, '', '', 1);
+        if (defined($output) && grep(/failed/i, @{$output})) {
+                notify($ERRORS{'DEBUG'}, 0, "service does not exist: 
$service_name");
+                return 0;
+        }
+        elsif (defined($status) && $status == 0) {
+                notify($ERRORS{'DEBUG'}, 0, "service exists: $service_name");
+        }
+        elsif (defined($status)) {
+                notify($ERRORS{'WARNING'}, 0, "unable to determine if service 
exists: $service_name, exit status: $status, output:\n@{$output}");
+                return;
+        }
+        else {
+                notify($ERRORS{'WARNING'}, 0, "unable to run ssh command to 
determine if service exists");
+                return;
+        }
+
+        return 1;
+       
+
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 start_service
+
+ Parameters  : $service_name
+ Returns     : If service started: 1
+               If service not started: 0
+               If error occurred: undefined
+ Description : 
+
+=cut
+
+sub stop_service {
+        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;
+        }
+
+        my $management_node_keys = $self->data->get_management_node_keys();
+        my $computer_node_name   = $self->data->get_computer_node_name();
+
+        my $service_name = shift;
+        if (!$service_name) {
+                notify($ERRORS{'WARNING'}, 0, "service name was not passed as 
an argument");
+                return;
+        }
+
+        my $command = "/sbin/service $service_name stop";
+        my ($status, $output) = run_ssh_command($computer_node_name, 
$management_node_keys, $command, '', '', 1);
+        if (defined($output) && grep(/failed/i, @{$output})) {
+                notify($ERRORS{'DEBUG'}, 0, "service does not exist: 
$service_name");
+                return 0;
+        }
+        elsif (defined($status) && $status == 0) {
+                notify($ERRORS{'DEBUG'}, 0, "service exists: $service_name");
+        }
+        elsif (defined($status)) {
+                notify($ERRORS{'WARNING'}, 0, "unable to determine if service 
exists: $service_name, exit status: $status, output:\n@{$output}");
+                return;
+        }
+        else {
+                notify($ERRORS{'WARNING'}, 0, "unable to run ssh command to 
determine if service exists");
+                return;
+        }
+
+        return 1;
+
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 check_connection
+
+ Parameters  : $port
+ Returns     : (connected|conn_wrong_ip|timeout|failed)
+ Description : uses netstat to see if any thing is connected to the provided 
port
+
+=cut
+
+sub check_connection_on_port {
+       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;
+        }
+
+        my $management_node_keys       = 
$self->data->get_management_node_keys();
+        my $computer_node_name         = $self->data->get_computer_node_name();
+       my $remote_ip                   = 
$self->data->get_reservation_remote_ip();
+       my $computer_ip_address         = 
$self->data->get_computer_ip_address();
+       my $request_state_name          = $self->data->get_request_state_name();
+
+        my $port = shift;
+        if (!$port) {
+                notify($ERRORS{'WARNING'}, 0, "port variable was not passed as 
an argument");
+                return "failed";
+        }
+       
+       my $ret_val = "no";     
+       my $command = "netstat -an";
+       my ($status, $output) = run_ssh_command($computer_node_name, 
$management_node_keys, $command, '', '', 1);
+       notify($ERRORS{'DEBUG'}, 0, "checking connections on node 
$computer_node_name on port $port");
+       foreach my $line (@{$output}) {
+               if ($line =~ /Connection refused|Permission denied/) {
+                    chomp($line);
+                    notify($ERRORS{'WARNING'}, 0, "$line");
+                    if ($request_state_name =~ /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($computer_ip_address:$port)\s+([.0-9]*):([0-9]*)(.*)(ESTABLISHED)/)
 {
+                     if ($4 eq $remote_ip) {
+                         $ret_val = "connected";
+                         return $ret_val;
+                     }
+                     else {
+                         #this isn't the remoteIP
+                          $ret_val = "conn_wrong_ip";
+                         return $ret_val;
+                     }
+                 }    # tcp check
+       }
+       return $ret_val;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 get_cpu_core_count
 
  Parameters  : none

Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm?rev=1164572&r1=1164571&r2=1164572&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm 
(original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm Fri 
Sep  2 15:09:54 2011
@@ -336,6 +336,90 @@ sub get_current_image_name {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 check_connection_on_port
+
+ Parameters  : $port
+ Returns     : (connected|conn_wrong_ip|timeout|failed)
+ Description : uses netstat to see if any thing is connected to the provided 
port
+ 
+=cut
+
+sub check_connection_on_port {
+        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 $management_node_keys        = 
$self->data->get_management_node_keys();
+        my $computer_node_name          = 
$self->data->get_computer_node_name();
+        my $remote_ip                   = 
$self->data->get_reservation_remote_ip();
+        my $computer_ip_address         = 
$self->data->get_computer_ip_address();
+        my $request_state_name          = 
$self->data->get_request_state_name();
+
+        my $port = shift;
+        if (!$port) {
+                notify($ERRORS{'WARNING'}, 0, "port variable was not passed as 
an argument");
+                return "failed";
+        }
+
+        my $ret_val = "no";
+        my $command = "netstat -an";
+        my ($status, $output) = run_ssh_command($computer_node_name, 
$management_node_keys, $command, 'vclstaff', 24, 1);
+        notify($ERRORS{'DEBUG'}, 0, "checking connections on node 
$computer_node_name on port $port");
+        foreach my $line (@{$output}) {
+                if ($line =~ /Connection refused|Permission denied/) {
+                    chomp($line);
+                    notify($ERRORS{'WARNING'}, 0, "$line");
+                    if ($request_state_name =~ /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($computer_ip_address:$port)\s+([.0-9]*):([0-9]*)(.*)(ESTABLISHED)/)
 {
+                     if ($4 eq $remote_ip) {
+                         $ret_val = "connected";
+                         return $ret_val;
+                     }
+                     else {
+                          #this isn't the remoteIP
+                          $ret_val = "conn_wrong_ip";
+                          return $ret_val;
+                     }
+                 }    # Linux
+                if ($line =~ 
/tcp\s+([0-9]*)\s+([0-9]*)\s::ffff:($computer_ip_address:$port)\s+::ffff:([.0-9]*):([0-9]*)(.*)(ESTABLISHED)
 /) {
+                     if ($4 eq $remote_ip) {
+                         $ret_val = "connected";
+                         return $ret_val;
+                     }
+                     else {
+                       #this isn't the remoteIP
+                          $ret_val = "conn_wrong_ip";
+                          return $ret_val;
+                     }
+                } ##
+               if ($line =~ 
/\s*($computer_ip_address\.$port)\s+([.0-9]*)\.([0-9]*)(.*)(ESTABLISHED)/) {
+                     if ($4 eq $remote_ip) {
+                         $ret_val = "connected";
+                         return $ret_val;                       
+                     }
+                     else {
+                       #this isn't the remoteIP
+                          $ret_val = "conn_wrong_ip";
+                          return $ret_val;
+                     }
+                } ##   
+               
+               
+        }
+        return $ret_val;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 1;
 __END__
 

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=1164572&r1=1164571&r2=1164572&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Fri Sep  2 
15:09:54 2011
@@ -954,6 +954,10 @@ sub grant_access {
 
        # Set the $remote_ip_range variable to the string 'all' if it isn't 
already set (for display purposes)
        $remote_ip_range = 'all' if !$remote_ip_range;
+       
+       if($self->process_connect_methods('start') ){
+                notify($ERRORS{'OK'}, 0, "processed connection methods on 
$computer_node_name");
+        }
 
        # Allow RDP connections
        if ($self->firewall_enable_rdp($remote_ip_range)) {
@@ -10015,6 +10019,66 @@ sub get_environment_variable_value {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 check_connection
+
+ Parameters  : $port
+ Returns     : (connected|conn_wrong_ip|timeout|failed)
+ Description : uses netstat to see if any thing is connected to the provided 
port
+
+=cut
+
+sub check_connection_on_port {
+        my $self = shift;
+        if (ref($self) !~ /windows/i) {
+                notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+                return;
+        }
+
+        my $management_node_keys       = 
$self->data->get_management_node_keys();
+        my $computer_node_name         = $self->data->get_computer_node_name();
+        my $remote_ip                  = 
$self->data->get_reservation_remote_ip();
+        my $computer_ip_address        = 
$self->data->get_computer_ip_address();
+       my $request_state_name          = $self->data->get_request_state_name();
+
+        my $port = shift;
+        if (!$port) {
+                notify($ERRORS{'WARNING'}, 0, "port variable was not passed as 
an argument");
+                return "failed";
+        }
+       
+       my $ret_val = "no";
+        my $command = "netstat -an";
+        my ($status, $output) = run_ssh_command($computer_node_name, 
$management_node_keys, $command, '', '', 1);
+        notify($ERRORS{'DEBUG'}, 0, "checking connections on node 
$computer_node_name on port $port");
+        foreach my $line (@{$output}) {
+                if ($line =~ /Connection refused|Permission denied/) {
+                    chomp($line);
+                    notify($ERRORS{'WARNING'}, 0, "$line");
+                    if ($request_state_name =~ /reserved/) {
+                        $ret_val = "failed";
+                    }
+                    else {
+                         $ret_val = "timeout";
+                    }
+                    return $ret_val;
+                 } ## end if ($line =~ /Connection refused|Permission denied/)
+               if ($line =~ 
/\s+($computer_ip_address:$port)\s+([.0-9]*):([0-9]*)\s+(ESTABLISHED)/) {
+                     if ($2 eq $remote_ip) {
+                         $ret_val = "connected";
+                         return $ret_val;
+                     }
+                     else {
+                          #this isn't the remoteIP
+                          $ret_val = "conn_wrong_ip";
+                          return $ret_val;
+                     }
+                 }    # tcp check
+        }
+       return $ret_val;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 1;
 __END__
 

Modified: incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm?rev=1164572&r1=1164571&r2=1164572&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm Fri Sep  2 15:09:54 2011
@@ -124,6 +124,17 @@ sub process {
        my $identity_key          = $self->data->get_image_identity();
        my $request_state_name    = $self->data->get_request_state_name();
        
+       my $connect_info      = $self->data->get_connect_methods();
+        
+        foreach my $CMid (sort keys % {$connect_info}) {
+                notify($ERRORS{'OK'}, 0, "id= $$connect_info{$CMid}{id}") 
if(defined ($$connect_info{$CMid}{id}) );
+                notify($ERRORS{'OK'}, 0, "description= 
$$connect_info{$CMid}{description}") if(defined 
($$connect_info{$CMid}{description}) );
+                notify($ERRORS{'OK'}, 0, "port== $$connect_info{$CMid}{port}") 
if(defined ($$connect_info{$CMid}{port}) );
+                notify($ERRORS{'OK'}, 0, "servicename= 
$$connect_info{$CMid}{servicename}") if(defined 
($$connect_info{$CMid}{servicename}) );
+                notify($ERRORS{'OK'}, 0, "startupscript= 
$$connect_info{$CMid}{startupscript}") if(defined 
($$connect_info{$CMid}{startupscript}) );
+                notify($ERRORS{'OK'}, 0, "autoprov= 
$$connect_info{$CMid}{autoprovisioned}") if(defined 
($$connect_info{$CMid}{autoprovisioned}) );
+          }
+       
        if ($request_state_name =~ /reboot|rebootsoft|reboothard/) {
                notify($ERRORS{'OK'}, 0, "this is a 'reboot' request");
                if ($self->os->can('reboot')) {
@@ -287,8 +298,17 @@ sub process {
                
                notify($ERRORS{'OK'}, 0, "end time not yet reached, polling 
machine for user connection");
                
-               # Check the user connection, this will loop until user connects 
or time limit is reached
-               my $check_connection = check_connection($computer_nodename, 
$computer_ip_address, $computer_type, $reservation_remoteip, 
$connect_timeout_limit, $image_os_name, 0, $request_id, 
$user_login_id,$image_os_type);
+               my $check_connection;
+               if($self->os->can("is_user_connected")) {
+
+                        #Use new code if it exists
+                        $check_connection = 
$self->os->is_user_connected($connect_timeout_limit);
+                }      
+               else {
+               
+                       # Check the user connection, this will loop until user 
connects or time limit is reached
+                       $check_connection = 
check_connection($computer_nodename, $computer_ip_address, $computer_type, 
$reservation_remoteip, $connect_timeout_limit, $image_os_name, 0, $request_id, 
$user_login_id,$image_os_type);
+               }
                
                #TESTING
                #$check_connection = 'timeout';

Modified: incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm?rev=1164572&r1=1164571&r2=1164572&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/reserved.pm Fri Sep  2 15:09:54 
2011
@@ -310,7 +310,16 @@ sub process {
        }
        else {
                notify($ERRORS{'OK'}, 0, "checkuser flag=1 imageosname is 
$image_os_name, checking for user connection by $user_unityid");
-               $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);
+
+               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);
+               }
        } ## end else [ if (!$imagemeta_checkuser)
 
        RETVALCONN:

Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1164572&r1=1164571&r2=1164572&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Fri Sep  2 15:09:54 2011
@@ -4644,6 +4644,9 @@ sub get_request_info {
                my $computer_id = 
$request_info{reservation}{$reservation_id}{computerid};
                my $computer_info = get_computer_info($computer_id, 1);
                $request_info{reservation}{$reservation_id}{computer} = 
$computer_info;
+
+               my $connect_methods = get_connect_methods($image_id, 
$imagerevision_id);
+               $request_info{reservation}{$reservation_id}{connect_methods} = 
$connect_methods;
                
        }    # Close loop through selected rows
        
@@ -10664,6 +10667,87 @@ sub kill_child_processes {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 get_connect_method
+
+ Parameters  : reservationid
+ Returns     : hash reference
+ Description : Returns the contents of connect method for reservationid.
+
+=cut
+
+sub get_connect_methods {
+
+        my ($imageid, $imagerevisionid) = @_;
+        my ($calling_package, $calling_filename, $calling_line, $calling_sub) 
= caller(0);
+
+        if (!defined($imagerevisionid)) {
+                notify($ERRORS{'WARNING'}, 0, "$calling_sub $calling_package 
missing mandatory variable: imagerevisionid ");
+                return 0;
+        }
+        
+        if (!defined($imageid)) {
+                notify($ERRORS{'WARNING'}, 0, "$calling_sub $calling_package 
missing mandatory variable: imageid ");
+                return 0;
+        }
+
+        my $select_statement = "
+        SELECT DISTINCT
+        c.id AS CM_id,
+        c.description AS CM_description,
+        c.port AS CM_port,
+        c.servicename AS CM_servicename,
+        c.startupscript AS CM_startupscript,
+        cm.autoprovisioned AS CM_autoprovisioned,
+        cm.disabled AS CM_disabled
+        FROM
+        connectmethod c,
+        connectmethodmap cm,
+        image i
+        LEFT JOIN OS o ON (o.id = i.OSid)
+        LEFT JOIN OStype ot ON (ot.name = o.type)
+        WHERE 
+        i.id = $imageid AND
+        cm.connectmethodid = c.id AND
+        cm.autoprovisioned IS NULL AND
+        (cm.OStypeid = ot.id OR
+        cm.OSid = o.id OR 
+        cm.imagerevisionid = $imagerevisionid)
+        ORDER BY cm.disabled, c.description";
+
+        # Call the database select subroutine
+        # This will return an array of one or more rows based on the select 
statement
+        my @selected_rows = database_select($select_statement);
+
+        my @ret_array;
+        my %connect_info;
+       
+               # Check to make sure 1 or more rows were returned
+        if (scalar @selected_rows > 0) {
+                # It contains a hash
+                for (@selected_rows) {
+                        my %connectMethod = %{$_};
+                        next if($connectMethod{CM_disabled});
+                        my $CMid = $connectMethod{CM_id};
+                        $connect_info{$CMid}{"id"} = $CMid;
+                        $connect_info{$CMid}{"description"} = 
$connectMethod{CM_description};
+                        $connect_info{$CMid}{"port"} = $connectMethod{CM_port};
+                        $connect_info{$CMid}{"servicename"} = 
$connectMethod{CM_servicename};
+                        $connect_info{$CMid}{"startupscript"} = 
$connectMethod{CM_startupscript};
+                        $connect_info{$CMid}{"autoprovisioned"} = 
$connectMethod{CM_autoprovisioned};
+                       
+                       notify($ERRORS{'OK'}, 0, "CONNECT METHOD CMid= $CMid 
description= $connect_info{$CMid}{description}");
+        
+                }
+                
+                return \%connect_info;
+        }       
+        
+        return();       
+
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 1;
 __END__
 


Reply via email to