From 4e75a8d297f9ff9dd0c35c5de46e6fa0f3d6ff3f Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 5 Aug 2008 14:16:15 +0000 Subject: [PATCH] update: opsi_install_client messages additionally trigger wake on lan WOL git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12154 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 21 +++-- gosa-si/server/events/opsi_com.pm | 126 ++++++++++++++++++------------ gosa-si/tests/client.php | 2 +- 3 files changed, 90 insertions(+), 59 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index b0e4d92f7..1aeaeffdd 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -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); + } + + } } diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index f1e635094..604172c20 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -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 = "". + "
answer
". + "$main::server_address". + "GOSA". + "1". + "no mac address specified in macaddres-tag". + "
"; + 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; } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index b445c0394..62b0a6648 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -154,7 +154,7 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_opsi_del_client
GOSA 00:01:6c:9d:aa:16 sdfgsg.intranet.gonicus.de
"; # Install Opsi client - $data = "
job_opsi_install_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de 11:22:33:44:55:66
"; + $data = "
job_opsi_install_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de 00:11:25:4b:8c:e5
"; ######################### -- 2.30.2