From 9a33579dcd5747fab3fc62f8de500548ef002841 Mon Sep 17 00:00:00 2001 From: janw Date: Thu, 6 Mar 2008 15:35:27 +0000 Subject: [PATCH] Checked in 'half-done' code for fai release db generation. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9399 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 143 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 14 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 3dcb9daf3..7c8fa0ee9 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -127,7 +127,7 @@ our $fai_server_tn = "fai_server"; my $fai_server_file_name; our @fai_server_col_names = ('timestamp', 'server', 'release', 'tag'); our $fai_release_tn = "fai_release"; -our @fai_release_col_names = ('timestamp', 'release', 'class'); +our @fai_release_col_names = ('timestamp', 'release', 'class', 'type'); # holds all packages available from different repositories our $packages_list_db; @@ -923,7 +923,7 @@ sub _start { my ($kernel) = $_[KERNEL]; &trigger_db_loop($kernel); $kernel->yield('create_fai_server_db', $fai_server_tn ); - $kernel->yield('create_fai_release_db', $fai_release_tn ); + #$kernel->yield('create_fai_release_db', $fai_release_tn ); #$kernel->yield('create_packages_list_db', $sources_list ); } @@ -1270,27 +1270,142 @@ sub create_fai_release_db { my $mesg= $ldap_handle->search( base => $main::ldap_base, scope => 'sub', - attrs => ['cn', 'FAIdebianRelease'], - filter => "(&(FAIdebianRelease=*)(objectClass=FAIclass))", + attrs => [], + filter => "(&(objectClass=organizationalUnit)(ou=fai))", ); if($mesg->{'resultCode'} == 0 && $mesg->count != 0) { - foreach my $entry (@{$mesg->{entries}}) { - if($entry->exists('FAIdebianRelease') && $entry->exists('cn')) { - $result= $fai_server_db->add_dbentry( { - table => $table_name, - primkey => ['release', 'class'], - release => $entry->get_value('FAIdebianRelease'), - class => $entry->get_value('cn'), - } ); + # Walk through all possible FAI container ou's + foreach my $ou (@{$mesg->{entries}}) { + my $tmp_classes= resolve_fai_classes($ou->dn); + #daemon_log(Dumper($tmp_classes),1); + last; + #$result= $fai_server_db->add_dbentry( { + # table => $table_name, + # primkey => ['release', 'class'], + # release => $tmp_release, + # class => $entry->get_value('cn'), + # } ); + } + + } + exit(0); + } + + return $result; +} + +sub resolve_fai_classes { + my $result; + my $fai_base= shift; + my $fai_hash= shift; + my @possible_fai_classes= ("FAIscript", "FAIhook", "FAIpartitionTable", "FAItemplate", "FAIvariable", "FAIprofile", "FAIpackageList"); + my $fai_filter= "(&(objectClass=FAIclass)(|(objectClass=".join(")(objectClass=", @possible_fai_classes).")))"; + my $fai_classes; + + #daemon_log("Searching in base $fai_base",6); + my $mesg= $ldap_handle->search( + base => $fai_base, + scope => 'sub', + attrs => ['cn','objectClass','FAIstate'], + filter => $fai_filter, + ); + + if($mesg->{'resultCode'} == 0 && + $mesg->count != 0) { + foreach my $entry (@{$mesg->{entries}}) { + if($entry->exists('cn') && (!($entry->get_value('cn') eq 'LAST')) ) { + my $tmp_dn= $entry->dn(); + + # Skip classname and ou dn parts for class + my $tmp_release = ($1) if $tmp_dn =~ /^[^,]+,[^,]+,(.*?),$fai_base$/; + + # Skip classes without releases + if((!defined($tmp_release)) || length($tmp_release)==0) { + next; + } + + my $tmp_cn= $entry->get_value('cn'); + my $tmp_state= $entry->get_value('FAIstate'); + + my $tmp_type; + # Get FAI type + for my $oclass(@{$entry->get_value('objectClass', asref => 1)}) { + if(grep $_ eq $oclass, @possible_fai_classes) { + $tmp_type= $oclass; + last; + } + } + + if($tmp_release =~ /^.*?,.*?$/ && (!($tmp_release =~ /^.*?\\,.*?$/))) { + # A Subrelease + my @sub_releases = split(/,/, $tmp_release); + + # Walk through subreleases and build hash tree + my $hash; + while(my $tmp_sub_release = pop @sub_releases) { + $hash .= "\{'$tmp_sub_release'\}->"; + } + eval('push @{$fai_classes->'.$hash.'{$tmp_cn}->{$tmp_type}}, (defined($tmp_state) && length($tmp_state)>0)?$tmp_state:"";'); + } else { + # A branch, no subrelease + push @{$fai_classes->{$tmp_release}->{$tmp_cn}->{$tmp_type}}, (defined($tmp_state) && length($tmp_state)>0)?$tmp_state:""; } } } - } - + + # The hash is complete, now we can honor the copy-on-write based missing entries + foreach my $release (keys %$fai_classes) { + # Prepare the classes + my $tmp_classes; + + # Get the classes from the branch + foreach my $class (keys %{$fai_classes->{$release}}) { + # Skip subreleases + if($class =~ /^ou=.*$/) { + next; + } else { + my $text = Data::Dumper->new([$fai_classes->{$release}->{$class}])->Purity(1)->Terse(1)->Deepcopy(1)->Dump(); + $tmp_classes->{$class => "nix"}; + eval "$tmp_classes->{$class}->$text;"; + daemon_log("eval $tmp_classes->{$class}->$text;",1); + daemon_log(Dumper($tmp_classes),1); + exit(1); + } + } + + if(ref $fai_classes->{$release} eq 'HASH') { + foreach my $sub_release (keys %{$fai_classes->{$release}}) { + if($sub_release =~ /^ou=.*$/) { + + } + } + } + } + + $result= $fai_classes; + } + return $result; } +sub get_fai_classes { + my $result; + my $fai_release = shift || return; + my $fai_classes = shift || return; + + #daemon_log("Searching classes for release $fai_release",1); + foreach my $class (keys %{$fai_classes->{$fai_release}}) { + # Skip subreleases + if($class =~ /^ou=.*$/) { + next; + } else { + $result->{$class}= $fai_classes->{$fai_release}->{$class}; + } + } + + return $result; +} sub create_packages_list_db { my ($sources_file) = $_[ARG0] ; -- 2.30.2