summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ff359b6)
raw | patch | inline | side by side (parent: ff359b6)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Aug 2008 09:59:42 +0000 (09:59 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Aug 2008 09:59:42 +0000 (09:59 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12148 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index ba12f2b97eb5cb673db23ee2826ed06d947f7ec2..9f97a8a79043c69f69cf982d7920ef9d09d1f09c 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
while (my ($id, $hit) = each %$res ) {
- # Ask OPSI for an update of the running jobs
+ # Determine current parameters of the job
my $hostId = $hit->{'plainname'};
-print STDERR "\n\n$hostId\n";
+ my $macaddress = $hit->{'macaddress'};
+ my $progress = $hit->{'progress'};
+
+ # Ask OPSI for an update of the running jobs
+#print STDERR "\n\n$hostId\n";
my $result= {};
# For hosts, only return the products that are or get installed
$result->{'progress'}= int($installed * 100 / $products);
}
- #return $result;
-print STDERR Dumper($result);
+#print STDERR Dumper($result);
# Set updates to job queue
+ if ($progress ne $result->{'progress'}) {
+ my $update_statement = "UPDATE $job_queue_tn SET progress='".$result->{'progress'}."', modified='1' WHERE macaddress='$macaddress'";
+ my $update_res = $job_db->update_dbentry($update_statement);
+ }
}
index fb3a7048f062460bdfab460bb56002dbb04b8d3d..cd0716f2b8ecce71b3c6daf8f6b927de1fe11859 100644 (file)
$header =~ s/job_//;
my $target = @{$msg_hash->{'target'}}[0];
- # if no timestamp is specified, use 19700101000000
+ # If no timestamp is specified, use 19700101000000
my $timestamp = "19700101000000";
if( exists $msg_hash->{'timestamp'} ) {
$timestamp = @{$msg_hash->{'timestamp'}}[0];
}
- #if no macaddress is specified, raise error
+ # If no macaddress is specified, raise error
my $macaddress;
if( exists $msg_hash->{'macaddress'} ) {
$macaddress = @{$msg_hash->{'macaddress'}}[0];
"</xml>";
}
- # if mac address is already known in ldap, set plain_name to 'cn'
+ # Determine plain_name for host
my $plain_name;
- my $ldap_handle = &main::get_ldap_handle($session_id);
- if( not defined $ldap_handle ) {
- &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
- $plain_name = "none";
-
- # try to fetch a 'real name'
- } else {
- my $mesg = $ldap_handle->search(
- base => $main::ldap_base,
- scope => 'sub',
- attrs => ['cn'],
- filter => "(macAddress=$macaddress)");
- if($mesg->code) {
- &main::daemon_log($mesg->error, 1);
- $plain_name = "none";
- } else {
- my $entry= $mesg->entry(0);
- $plain_name = $entry->get_value("cn");
- }
- }
+ if ($header eq "opsi_install_client") { # Opsi installing clients use hostId as plain_name
+ if (not exists $msg_hash->{'hostId'}) {
+ $error++;
+ &daemon_log("$session_id ERROR: opsi_install_client-message has no xml-tag 'hostID', job was not created: $msg", 1);
+ } else {
+ $plain_name = $msg_hash->{'hostId'}[0];
+ }
+ } else { # Try to determine plain_name via ladp search
+ my $ldap_handle = &main::get_ldap_handle($session_id);
+ if( not defined $ldap_handle ) {
+ &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
+ $plain_name = "none";
+ } else {
+ my $mesg = $ldap_handle->search(
+ base => $main::ldap_base,
+ scope => 'sub',
+ attrs => ['cn'],
+ filter => "(macAddress=$macaddress)");
+ if($mesg->code) {
+ &main::daemon_log($mesg->error, 1);
+ $plain_name = "none";
+ } else {
+ my $entry= $mesg->entry(0);
+ $plain_name = $entry->get_value("cn");
+ }
+ }
+ }
+
+ # Add job to job queue
if( $error == 0 ) {
- # add job to job queue
my $func_dic = {table=>$main::job_queue_tn,
primkey=>['macaddress', 'headertag'],
timestamp=>$timestamp,
index 5b934ccfc1b45941c2b91bdb46c30f9a2b1700bd..a7076b13779e20fefaf76a746040b0d90d6f4af7 100644 (file)
my @events = (
"get_events",
"opsi_install_client",
- #"opsi_get_netboot_products",
- #"opsi_get_local_products",
- #"opsi_get_client_hardware",
- #"opsi_get_client_software",
- #"opsi_get_product_properties",
- #"opsi_set_product_properties",
- #"opsi_list_clients",
- #"opsi_del_client",
- #"opsi_install_client",
+ "opsi_get_netboot_products",
+ "opsi_get_local_products",
+ "opsi_get_client_hardware",
+ "opsi_get_client_software",
+ "opsi_get_product_properties",
+ "opsi_set_product_properties",
+ "opsi_list_clients",
+ "opsi_del_client",
+ "opsi_install_client",
);
@EXPORT = @events;
use warnings;
use GOSA::GosaSupportDaemon;
use Data::Dumper;
+use XML::Quote qw(:all);
BEGIN {}
# @param msg - STRING - xml message with tags macaddress and hostId
# @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 {
- my ($msg, $msg_hash, $session_id) = @_ ;
- my $error = 0;
- my $out_msg;
- my $out_hash;
-
- # Prepare incoming message
- $msg =~ s/<header>gosa_/<header>/;
- $msg_hash->{'header'}[0] =~ s/gosa_//;
-
-
- # Assign variables
- my $header = @{$msg_hash->{'header'}}[0];
- my $source = @{$msg_hash->{'source'}}[0];
- my $target = @{$msg_hash->{'target'}}[0];
-
-
- # If no timestamp is specified in incoming message, use 19700101000000
- my $timestamp = "19700101000000";
- if( exists $msg_hash->{'timestamp'} ) {
- $timestamp = @{$msg_hash->{'timestamp'}}[0];
- }
-
-
- # 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 ++;
- $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>";
- }
-
-
- # Set hostID to plain_name
- my $plain_name;
- if (not $error) {
- if (exists $msg_hash->{'hostId'}) {
- $plain_name = $msg_hash->{'hostId'}[0];
- } else {
- $error++;
- $out_msg = "<xml>".
- "<header>answer</header>".
- "<source>$main::server_address</source>".
- "<target>GOSA</target>".
- "<answer1>1</answer1>".
- "<error_string>no hostId specified in hostId-tag</error_string>".
- "</xml>";
- }
- }
-
-
- # Add installation job to job queue
- if (not $error) {
- my $insert_dic = {table=>$main::job_queue_tn,
- primkey=>['macaddress', 'headertag'],
- timestamp=>&get_time(),
- status=>'processing',
- result=>'none',
- progress=>'none',
- headertag=>$header,
- targettag=>$target,
- xmlmessage=>$msg,
- macaddress=>$macaddress,
- plainname=>$plain_name,
- siserver=>"localhost",
- modified=>"1",
- };
- my $res = $main::job_db->add_dbentry($insert_dic);
- if (not $res == 0) {
- &main::daemon_log("$session_id ERROR: Cannot add opsi-job to job_queue: $msg", 1);
- } else {
- &main::daemon_log("$session_id INFO: '$header'-job successfully added to job queue", 5);
- }
- $out_msg = $msg; # forward GOsa message to client
- }
-
- return ($out_msg);
-}
+#sub opsi_install_client {
+# my ($msg, $msg_hash, $session_id) = @_ ;
+# my $error = 0;
+# my $out_msg;
+# my $out_hash;
+#
+# # Prepare incoming message
+# $msg =~ s/<header>gosa_/<header>/;
+# $msg_hash->{'header'}[0] =~ s/gosa_//;
+#
+#
+# # Assign variables
+# my $header = @{$msg_hash->{'header'}}[0];
+# my $source = @{$msg_hash->{'source'}}[0];
+# my $target = @{$msg_hash->{'target'}}[0];
+#
+#
+# # If no timestamp is specified in incoming message, use 19700101000000
+# my $timestamp = "19700101000000";
+# if( exists $msg_hash->{'timestamp'} ) {
+# $timestamp = @{$msg_hash->{'timestamp'}}[0];
+# }
+#
+#
+# # 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 ++;
+# $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>";
+# }
+#
+#
+# # Set hostID to plain_name
+# my $plain_name;
+# if (not $error) {
+# if (exists $msg_hash->{'hostId'}) {
+# $plain_name = $msg_hash->{'hostId'}[0];
+# } else {
+# $error++;
+# $out_msg = "<xml>".
+# "<header>answer</header>".
+# "<source>$main::server_address</source>".
+# "<target>GOSA</target>".
+# "<answer1>1</answer1>".
+# "<error_string>no hostId specified in hostId-tag</error_string>".
+# "</xml>";
+# }
+# }
+#
+#
+# # Add installation job to job queue
+# if (not $error) {
+# my $insert_dic = {table=>$main::job_queue_tn,
+# primkey=>['macaddress', 'headertag'],
+# timestamp=>&get_time(),
+# status=>'processing',
+# result=>'none',
+# progress=>'none',
+# headertag=>$header,
+# targettag=>$target,
+# xmlmessage=>$msg,
+# macaddress=>$macaddress,
+# plainname=>$plain_name,
+# siserver=>"localhost",
+# modified=>"1",
+# };
+# my $res = $main::job_db->add_dbentry($insert_dic);
+# if (not $res == 0) {
+# &main::daemon_log("$session_id ERROR: Cannot add opsi-job to job_queue: $msg", 1);
+# } else {
+# &main::daemon_log("$session_id INFO: '$header'-job successfully added to job queue", 5);
+# }
+# $out_msg = $msg; # forward GOsa message to client
+# }
+#
+# return ($out_msg);
+#}
## @method opsi_get_netboot_products
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- #&add_content2xml_hash($out_hash, "session_id", $session_id); ### possibly not needed, to be checked
if (defined $forward_to_gosa) {
&add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
}
my %r = ();
for (@{$res->result}) { $r{$_} = 1 }
- if (check_res($res)){
+ if (&main::check_opsi_res($res)){
if (defined $hostId){
$callobj = {
};
my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($hres)){
+ if (&main::check_opsi_res($hres)){
my $htmp= $hres->result->{$hostId};
# check state != not_installed or action == setup -> load and add
};
my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($sres)){
+ if (&main::check_opsi_res($sres)){
my $tres= $sres->result;
my $name= xml_quote($tres->{'name'});
};
my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($sres)){
+ if (&main::check_opsi_res($sres)){
my $tres= $sres->result;
my $name= xml_quote($tres->{'name'});
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- &add_content2xml_hash($out_hash, "session_id", $session_id);
# Get hostID if defined
if (defined @{$msg_hash->{'hostId'}}[0]){
id => 1,
};
my $res = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($res)){
+ if (&main::check_opsi_res($res)){
foreach my $action (@{$res->result}){
&add_content2xml_hash($out_hash, "action", $action);
}
$res = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($res)){
+ if (&main::check_opsi_res($res)){
my $r= $res->result;
foreach my $key (keys %{$r}) {
my $item= "<item>";
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- &add_content2xml_hash($out_hash, "session_id", $session_id);
&add_content2xml_hash($out_hash, "ProductId", $productId);
# Get hostID if defined
my $res = $main::opsi_client->call($main::opsi_url, $callobj);
- if (!check_res($res)){
+ if (!&main::check_opsi_res($res)){
&main::daemon_log("ERROR: no communication failed while setting '".$item->{'name'}[0]."': ".$res->error_message, 1);
&add_content2xml_hash($out_hash, "error", $res->error_message);
}
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- &add_content2xml_hash($out_hash, "session_id", $session_id);
if (defined $forward_to_gosa) {
&add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
};
my $res = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($res)){
+ if (&main::check_opsi_res($res)){
my $result= $res->result;
foreach my $r (keys %{$result}){
my $item= "<item><id>".xml_quote($r)."</id>";
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- &add_content2xml_hash($out_hash, "session_id", $session_id);
if (defined $forward_to_gosa) {
&add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
};
my $res = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($res)){
+ if (&main::check_opsi_res($res)){
foreach my $host (@{$res->result}){
my $item= "<item><name>".$host->{'hostId'}."</name>";
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- &add_content2xml_hash($out_hash, "session_id", $session_id);
if (defined $forward_to_gosa) {
&add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
};
my $res = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($res)){
+ if (&main::check_opsi_res($res)){
my $result= $res->result;
}
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- &add_content2xml_hash($out_hash, "session_id", $session_id);
# Get hostID if defined
if (defined @{$msg_hash->{'hostId'}}[0]){
my %r = ();
for (@{$res->result}) { $r{$_} = 1 }
- if (check_res($res)){
+ if (&main::check_opsi_res($res)){
if (defined $hostId){
$callobj = {
};
my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($hres)){
+ if (&main::check_opsi_res($hres)){
my $htmp= $hres->result->{$hostId};
# check state != not_installed or action == setup -> load and add
};
my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($sres)){
+ if (&main::check_opsi_res($sres)){
my $tres= $sres->result;
my $name= xml_quote($tres->{'name'});
};
my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($sres)){
+ if (&main::check_opsi_res($sres)){
my $tres= $sres->result;
my $name= xml_quote($tres->{'name'});
# };
#
# my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
-# if (check_res($hres)){
+# if (&main::check_opsi_res($hres)){
# my $htmp= $hres->result->{$hostId};
#
# # check state != not_installed or action == setup -> load and add
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- &add_content2xml_hash($out_hash, "session_id", $session_id);
if (defined $forward_to_gosa) {
&add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
# build return message with twisted target and source
my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
- &add_content2xml_hash($out_hash, "session_id", $session_id);
if (defined $forward_to_gosa) {
&add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
};
my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
- if (check_res($hres)){
+ if (&main::check_opsi_res($hres)){
my $htmp= $hres->result->{$hostId};
# check state != not_installed or action == setup -> load and add
id => 1,
};
my $res = $main::opsi_client->call($main::opsi_url, $callobj);
- if (!check_res($res)){
+ 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);
index ecc70afb106abe3119f84e77fe9190ffd807615d..b445c03944e46fb01441b3e7fa88f3ab70a286d1 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
# Opsi testing
# Get all netboot products
- #$data = "<xml> <header>gosa_opsi_get_netboot_products</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> </xml>";
+ #$data = "<xml> <header>gosa_opsi_get_netboot_products</header> <source>GOSA</source> <target>GOSA</target> </xml>";
# Get netboot product for specific host
- #$data = "<xml> <header>gosa_opsi_get_netboot_products</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId></xml>";
+ #$data = "<xml> <header>gosa_opsi_get_netboot_products</header> <source>GOSA</source> <target>GOSA</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId></xml>";
# Get all localboot products
- #$data = "<xml> <header>gosa_opsi_get_local_products</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> </xml>";
+ #$data = "<xml> <header>gosa_opsi_get_local_products</header> <source>GOSA</source> <target>GOSA</target> </xml>";
# Get localboot product for specific host
- #$data = "<xml> <header>gosa_opsi_get_local_products</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId></xml>";
+ #$data = "<xml> <header>gosa_opsi_get_local_products</header> <source>GOSA</source> <target>GOSA</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId></xml>";
# Get product properties - global
- #$data = "<xml> <header>gosa_opsi_get_product_properties</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <ProductId>winxppro</ProductId></xml>";
+ #$data = "<xml> <header>gosa_opsi_get_product_properties</header> <source>GOSA</source> <target>GOSA</target> <ProductId>winxppro</ProductId></xml>";
# Get product properties - per host
- #$data = "<xml> <header>gosa_opsi_get_product_properties</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <ProductId>firefox</ProductId> <hostId>limux-cl-2.intranet.gonicus.de</hostId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_get_product_properties</header> <source>GOSA</source> <target>GOSA</target> <ProductId>firefox</ProductId> <hostId>limux-cl-2.intranet.gonicus.de</hostId> </xml>";
# Set product properties - global
#$data = "<xml> <header>gosa_opsi_set_product_properties</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <ProductId>winxppro</ProductId> <item><name>askbeforeinst</name><value>false</value></item></xml>";
#$data = "<xml> <header>gosa_opsi_set_product_properties</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId> <ProductId>winxppro</ProductId> <item><name>askbeforeinst</name><value>false</value></item></xml>";
# Get hardware inventory
- #$data = "<xml> <header>gosa_opsi_get_client_hardware</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_get_client_hardware</header> <source>GOSA</source> <target>GOSA</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId> </xml>";
# Get software inventory
- #$data = "<xml> <header>gosa_opsi_get_client_software</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId> </xml>";
+ #$data = "<xml> <header>gosa_opsi_get_client_software</header> <source>GOSA</source> <target>GOSA</target> <hostId>limux-cl-2.intranet.gonicus.de</hostId> </xml>";
# List Opsi clients
- #$data = "<xml> <header>gosa_opsi_list_clients</header> <source>GOSA</source> <target>00:01:6c:9d:aa:16</target> </xml>";
+ #$data = "<xml> <header>gosa_opsi_list_clients</header> <source>GOSA</source> <target>GOSA</target> </xml>";
# Delete Opsi client
#$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>gosa_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>11:22:33:44:55:66</macaddress> </xml>";
#########################