Code

update: opsi_install_client messages additionally trigger wake on lan WOL
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 5 Aug 2008 14:16:15 +0000 (14:16 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 5 Aug 2008 14:16:15 +0000 (14:16 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12154 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-server
gosa-si/server/events/opsi_com.pm
gosa-si/tests/client.php

index b0e4d92f7e3e26c56e34c77ad2dee622e389a474..1aeaeffdda0a3dfedeb975de47872cab45c695cb 100755 (executable)
@@ -1573,17 +1573,24 @@ sub watch_for_opsi_jobs {
                 $act_status = "error - ".join(", ", @error_list);
             }
             if ($progress ne $result->{'progress'} ) {
+                # Updating progress and result 
                 my $update_statement = "UPDATE $job_queue_tn SET modified='1', ";
-                if ($progress eq 100) { 
-                    if ($error) {
-                        $update_statement .= "status='error', ";
-                    } else {
-                        $update_statement .= "status='done', ";
-                    }
-                }
                 $update_statement .= "progress='".$result->{'progress'}."', result='$act_status' WHERE macaddress='$macaddress'";
                 my $update_res = $job_db->update_dbentry($update_statement);
             }
+            if ($progress eq 100) { 
+                # Updateing status
+                my $done_statement = "UPDATE $job_queue_tn SET modified='1', ";
+                if ($error) {
+                    $done_statement .= "status='error'";
+                } else {
+                    $done_statement .= "status='done'";
+                }
+                $done_statement .= " WHERE macaddress='$macaddress'";
+                my $done_res = $job_db->update_dbentry($done_statement);
+            }
+
+
         }
     }
 
index f1e6350941d99c854367c696d93fb2ca8d51d17d..604172c20ddba127bb71a3e694b2f9c617511bf2 100644 (file)
@@ -608,7 +608,7 @@ sub opsi_del_client {
 
 ## @method opsi_install_client
 # ???
-# @param msg - STRING - xml message with tag hostId
+# @param msg - STRING - xml message with tags hostId, macaddress
 # @param msg_hash - HASHREF - message information parsed into a hash
 # @param session_id - INTEGER - POE session id of the processing of this message
 sub opsi_install_client {
@@ -618,64 +618,88 @@ sub opsi_install_client {
     my $target = @{$msg_hash->{'target'}}[0];
     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
     my $hostId = @{$msg_hash->{'hostId'}}[0];
-
-    # build return message with twisted target and source
-    my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
-
-    if (defined $forward_to_gosa) {
-      &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
-    }
-    &add_content2xml_hash($out_hash, "hostId", "$hostId");
-
-    # Load all products for this host with status != "not_installed" or actionRequest != "none"
-    if (defined $hostId){
-      my $callobj = {
-        method  => 'getProductStates_hash',
-        params  => [ $hostId ],
-        id  => 1,
-      };
-
-      my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
-      if (&main::check_opsi_res($hres)){
-        my $htmp= $hres->result->{$hostId};
-
-        # check state != not_installed or action == setup -> load and add
-        foreach my $product (@{$htmp}){
-          # Now we've a couple of hashes...
-          if ($product->{'installationStatus'} ne "not_installed" or
-              $product->{'actionRequest'} ne "none"){
-
-            # Do an action request for all these -> "setup".
-            $callobj = {
-              method  => 'setProductActionRequest',
-              params  => [ $product->{'productId'}, $hostId, "setup" ],
-              id  => 1,
+    my $error = 0;
+    my @out_msg_l;
+
+    # If no macaddress is specified, raise error  
+    my $macaddress; 
+    if ((exists $msg_hash->{'macaddress'}) && 
+            ($msg_hash->{'macaddress'}[0] =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i)) {  
+        $macaddress = $1; 
+    } else { 
+        $error ++; 
+        my $out_msg = "<xml>". 
+            "<header>answer</header>". 
+            "<source>$main::server_address</source>". 
+            "<target>GOSA</target>". 
+            "<answer1>1</answer1>". 
+            "<error_string>no mac address specified in macaddres-tag</error_string>". 
+            "</xml>"; 
+        push(@out_msg_l, $out_msg);
+    } 
+
+    # Set parameters in opsi
+    if (not $error) {
+        # build return message with twisted target and source
+        my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
+
+        if (defined $forward_to_gosa) {
+            &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
+        }
+        &add_content2xml_hash($out_hash, "hostId", "$hostId");
+
+        # Load all products for this host with status != "not_installed" or actionRequest != "none"
+        if (defined $hostId){
+            my $callobj = {
+                method  => 'getProductStates_hash',
+                params  => [ $hostId ],
+                id  => 1,
             };
-            my $res = $main::opsi_client->call($main::opsi_url, $callobj);
-            if (!&main::check_opsi_res($res)){
-              &main::daemon_log("ERROR: cannot set product action request for $hostId!", 1);
-            } else {
-              &main::daemon_log("INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1);
-            }
 
-          }
+            my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
+            if (&main::check_opsi_res($hres)){
+                my $htmp= $hres->result->{$hostId};
+
+                # check state != not_installed or action == setup -> load and add
+                foreach my $product (@{$htmp}){
+                    # Now we've a couple of hashes...
+                    if ($product->{'installationStatus'} ne "not_installed" or
+                            $product->{'actionRequest'} ne "none"){
+
+                        # Do an action request for all these -> "setup".
+                        $callobj = {
+                            method  => 'setProductActionRequest',
+                            params  => [ $product->{'productId'}, $hostId, "setup" ],
+                            id  => 1,
+                        };
+                        my $res = $main::opsi_client->call($main::opsi_url, $callobj);
+                        if (!&main::check_opsi_res($res)){
+                            &main::daemon_log("ERROR: cannot set product action request for $hostId!", 1);
+                        } else {
+                            &main::daemon_log("INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1);
+                        }
+
+                    }
+                }
+            }
         }
-      }
+
+        push(@out_msg_l, &create_xml_string($out_hash));
     }
 
+    # Build wakeup message for client
+    if (not $error) {
+        my $wakeup_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER");
+        &add_content2xml_hash($wakeup_hash, 'macAddress', $macaddress);
+        my $wakeup_msg = &create_xml_string($wakeup_hash);
+        push(@out_msg_l, $wakeup_msg);
 
+        # invoke trigger wake for this gosa-si-server
+        &main::server_server_com::trigger_wake($wakeup_msg, $wakeup_hash, $session_id);
+    }
 
-#    # JSON Query
-#    my $callobj = {
-#      method  => 'deleteClient',
-#      params  => [ $hostId ],
-#      id  => 1,
-#    };
-#
-#    my $res = $main::opsi_client->call($main::opsi_url, $callobj);
 
-    my $xml_msg= &create_xml_string($out_hash);
-    return ($xml_msg);
+    return @out_msg_l;
 }
 
 
index b445c03944e46fb01441b3e7fa88f3ab70a286d1..62b0a6648ed2740fb64335dee7cb5892dc94efcb 100755 (executable)
@@ -154,7 +154,7 @@ for($count = 1; $count <= $zahl; $count++)
     #$data = "<xml> <header>gosa_opsi_del_client</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <hostId>sdfgsg.intranet.gonicus.de</hostId></xml>";
 
     # Install Opsi client
-    $data = "<xml> <header>job_opsi_install_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId> <macaddress>11:22:33:44:55:66</macaddress> </xml>";
+    $data = "<xml> <header>job_opsi_install_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId> <macaddress>00:11:25:4b:8c:e5</macaddress> </xml>";
 
 
     #########################