Code

update: opsi server integration
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 4 Aug 2008 15:34:45 +0000 (15:34 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 4 Aug 2008 15:34:45 +0000 (15:34 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12145 594d385d-05f5-0310-b6e9-bd551577e9d8

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

index 82bf4f88d60b3ed6204391b67ed361d05066359f..0b5e91032e094033b6aa5c14e52d7a5b8cfea6a3 100644 (file)
@@ -65,12 +65,13 @@ my %cfg_defaults = (
    "password" => [\$opsi_password, "secret"],
    },
 );
-&read_configfile($main::cfg_file, %cfg_defaults);
+&GOSA::GosaSupportDaemon::read_configfile($main::cfg_file, %cfg_defaults);
 
 # Assemble opsi URL
 my $opsi_url= "https://".$opsi_admin.":".$opsi_password."@".$opsi_server.":4447/rpc";
 my $client = new JSON::RPC::Client;
 
+
 sub check_res {
   my $res= shift;
   # TODO: We need to return the outhash!?
@@ -92,28 +93,6 @@ sub check_res {
 }
 
 
-sub read_configfile {
-    my ($cfg_file, %cfg_defaults) = @_;
-    my $cfg;
-
-    if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
-        if( -r $cfg_file ) {
-            $cfg = Config::IniFiles->new( -file => $cfg_file );
-        } else {
-            &main::daemon_log("ERROR: opsi.pm couldn't read config file!", 1);
-        }
-    } else {
-        $cfg = Config::IniFiles->new() ;
-    }
-    foreach my $section (keys %cfg_defaults) {
-        foreach my $param (keys %{$cfg_defaults{ $section }}) {
-            my $pinfo = $cfg_defaults{ $section }{ $param };
-            ${@$pinfo[0]} = $cfg->val( $section, $param, @$pinfo[1] );
-        }
-    }
-}
-
-
 sub get_events { return \@events; }
 
 
index dc72ee5b1d09f8462f1f4f7728d73f9fb44bfa57..cba9f598792a8bca994c45a628c090612ccf63d5 100755 (executable)
@@ -145,33 +145,6 @@ sub check_cmdline_param () {
 }
 
 
-#===  FUNCTION  ================================================================
-#         NAME:  read_configfile
-#   PARAMETERS:  cfg_file - string - 
-#      RETURNS:  
-#  DESCRIPTION: 
-#===============================================================================
-sub read_configfile {
-    my ($cfg_file, %cfg_defaults) = @_ ;
-    my $cfg;
-    if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
-        if( -r $cfg_file ) {
-            $cfg = Config::IniFiles->new( -file => $cfg_file );
-        } else {
-            print STDERR "Couldn't read config file!";
-        }
-    } else {
-        $cfg = Config::IniFiles->new() ;
-    }
-    foreach my $section (keys %cfg_defaults) {
-        foreach my $param (keys %{$cfg_defaults{ $section }}) {
-            my $pinfo = $cfg_defaults{ $section }{ $param };
-           ${@$pinfo[ 0 ]} = $cfg->val( $section, $param, @$pinfo[ 1 ] );
-        }
-    }
-}
-
-
 #===  FUNCTION  ================================================================
 #         NAME: check_pid
 #   PARAMETERS:
index 1a79a57830bfb44b6138d1da1a439bcf9d7800b8..e273e9e0c04ef50dc78e664131fba949c20a25f2 100755 (executable)
@@ -204,6 +204,10 @@ my @msgs_to_decrypt = qw();
 my $max_children = 2;
 
 
+# loop delay for job queue to look for opsi jobs
+my $job_queue_opsi_delay = 2;
+
+
 %cfg_defaults = (
 "general" => {
     "log-file" => [\$log_file, "/var/run/".$prg.".log"],
@@ -854,7 +858,7 @@ sub get_local_ip_for_remote_ip {
                        }
                }
        } else {
-               daemon_log("get_local_ip_for_remote_ip was called with a non-ip parameter: $remote_ip", 1);
+               daemon_log("0 WARNING: get_local_ip_for_remote_ip() was called with a non-ip parameter: '$remote_ip'", 1);
        }
        return $result;
 }
@@ -1441,6 +1445,7 @@ sub session_start {
        $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
        $kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay); 
     $kernel->delay_set('watch_for_modified_jobs', $modified_jobs_loop_delay); 
+    $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay); 
        $kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay);
     $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay);
        $kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay);
@@ -1467,6 +1472,69 @@ sub watch_for_done_jobs {
 }
 
 
+sub watch_for_opsi_jobs {
+    my ($kernel) = @_[KERNEL];
+
+    my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((headertag='opsi_install_client') AND (status='processing'))";
+       my $res = $job_db->select_dbentry( $sql_statement );
+
+    while (my ($id, $hit) = each %$res ) {
+
+        # Ask OPSI for an update of the running jobs
+        my $hostId = $hit->{'plainname'};
+        print STDERR "\n\n$hostId\n";
+#        my $result= {};
+#        
+#        # For hosts, only return the products that are or get installed
+#        my $callobj;
+#        $callobj = {
+#            method  => 'getProductStates_hash',
+#            params  => [ $hostId ],
+#            id  => 1,
+#        };
+#        
+#        my $hres = $client->call($opsi_url, $callobj);
+#        if (check_res($hres)){
+#            my $htmp= $hres->result->{$hostId};
+#        
+#        # check state != not_installed or action == setup -> load and add
+#            my $products= 0;
+#            my $installed= 0;
+#            my $error= 0;
+#            foreach my $product (@{$htmp}){
+#        
+#                if ($product->{'installationStatus'} ne "not_installed" or
+#                        $product->{'actionRequest'} eq "setup"){
+#        
+#        # Increase number of products for this host
+#                    $products++;
+#        
+#                    if ($product->{'installationStatus'} eq "failed"){
+#                        $result->{$product->{'productId'}}= "error";
+#                        $error++;
+#                    }
+#                    if ($product->{'installationStatus'} eq "installed"){
+#                        $result->{$product->{'productId'}}= "installed";
+#                        $installed++;
+#                    }
+#                    if ($product->{'installationStatus'} eq "installing"){
+#                        $result->{$product->{'productId'}}= "installing";
+#                    }
+#                }
+#            }
+#        
+#        # Estimate "rough" progress
+#            $result->{'progress'}= int($installed * 100 / $products);
+#}
+#
+#return $result;
+#
+    }
+
+    $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay);
+}
+
+
 # if a job got an update or was modified anyway, send to all other si-server an update message
 # of this jobs
 sub watch_for_modified_jobs {
@@ -1591,7 +1659,6 @@ sub watch_for_new_jobs {
 }
 
 
-
 sub watch_for_new_messages {
     my ($kernel,$heap) = @_[KERNEL, HEAP];
     my @coll_user_msg;   # collection list of outgoing messages
@@ -2531,6 +2598,7 @@ sub create_packages_list_db {
 
        close (CONFIG);
 
+
        find(\&cleanup_and_extract, keys( %repo_dirs ));
        &main::strip_packages_list_statements();
        unshift @packages_list_statements, "VACUUM";
@@ -2779,7 +2847,7 @@ sub cleanup_and_extract {
 
                if( -f "$dir/DEBIAN/templates" ) {
 
-                       daemon_log("DEBUG: Found debconf templates in '$package' - $newver", 5);
+                       daemon_log("DEBUG: Found debconf templates in '$package' - $newver", 7);
 
                        my $tmpl= "";
                        {
@@ -3050,6 +3118,7 @@ POE::Session->create(
                watch_for_new_jobs => \&watch_for_new_jobs,
         watch_for_modified_jobs => \&watch_for_modified_jobs,
         watch_for_done_jobs => \&watch_for_done_jobs,
+        watch_for_opsi_jobs => \&watch_for_opsi_jobs,
         watch_for_old_known_clients => \&watch_for_old_known_clients,
         create_packages_list_db => \&run_create_packages_list_db,
         create_fai_server_db => \&run_create_fai_server_db,
index f94db5dfec0b963af12194bc2b1ca5a062b1c45f..ecc70afb106abe3119f84e77fe9190ffd807615d 100755 (executable)
@@ -114,14 +114,13 @@ for($count = 1; $count <= $zahl; $count++)
 
     #$data = "<xml> <header>gosa_network_completition</header> <source>GOSA</source> <target>GOSA</target> <hostname>localhost</hostname> </xml>";
 
-    ########
+    ####################################################################
     # 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>";
 
     # 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>";
 
     # Get all localboot products
@@ -155,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>gosa_opsi_install_client</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_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>";
 
 
     #########################
@@ -173,7 +172,7 @@ for($count = 1; $count <= $zahl; $count++)
      
     ########################
     # DAK Debian Archive Kit
-    $data = "<xml> <header>gosa_get_dak_keyring</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> </xml>";
+    #$data = "<xml> <header>gosa_get_dak_keyring</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> </xml>";
     #$data = "<xml> <header>gosa_import_dak_key</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> </xml>";
     #$data = "<xml> <header>gosa_remove_dak_key</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> </xml>";