From 4f9fb77d50d82be53d6345c45fd5dc35d1d283a3 Mon Sep 17 00:00:00 2001 From: cajus Date: Mon, 16 Nov 2009 16:12:15 +0000 Subject: [PATCH] Updated opsi stuff to gain more speed git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14820 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/contrib/90_gosa.conf | 51 ++++++- gosa-si/server/events/opsi_com.pm | 226 +++++++++--------------------- 2 files changed, 113 insertions(+), 164 deletions(-) diff --git a/gosa-si/contrib/90_gosa.conf b/gosa-si/contrib/90_gosa.conf index cb957c94a..53beacdeb 100644 --- a/gosa-si/contrib/90_gosa.conf +++ b/gosa-si/contrib/90_gosa.conf @@ -1,6 +1,7 @@ -''' Override built in function to get clients ''' +''' Add a couple of additional functions to retrieve needed information with + just one call. ''' -def getClients_listOfHashes(self, serverId=None, depotIds=[], groupId=None, productId=None, installationStatus=None, actionRequest=None, productVersion=None, packageVersion=None): +def getClientsInformation_listOfHashes(self, serverId=None, depotIds=[], groupId=None, productId=None, installationStatus=None, actionRequest=None, productVersion=None, packageVersion=None): # Get backend instance and load client list bi= self.backends[self.clientManagingBackend]['instance'] @@ -11,3 +12,49 @@ def getClients_listOfHashes(self, serverId=None, depotIds=[], groupId=None, prod client['macAddress']= bi.getMacAddress(client['hostId']) return clients + + +def getProductHostInformation_list(self, objectId=None, installationStatus=None, type='localboot'): + result = [] + + # Generate a dictionary for faster lookup of product IDs + products= {} + productIds= self.getProductIds_list(type, objectId, installationStatus) + for productId in productIds: + products[productId]= 1 + + # Load product states + productStates= self.getProductStates_hash(objectId) + + # Extend every entry by name and description + for product in productStates[objectId]: + if not products.has_key(product['productId']): + continue + + # Add missing information to the productInfo + if product['installationStatus'] != "not_installed" or product['actionRequest'] == "setup": + productInfo= self.getProduct_hash(product['productId']) + productInfo['installationStatus']= product['installationStatus'] + productInfo['actionRequest']= product['actionRequest'] + productInfo['productId']= product['productId'] + result.append(productInfo) + + return result + + +def getProductInformation_list(self, installationStatus=None, type='localboot'): + result = [] + + # Generate a dictionary for faster lookup of product IDs + productIds= self.getProductIds_list(type, None, installationStatus) + + # Extend every entry by name and description + for productId in productIds: + + # Add missing information to the productInfo + productInfo= self.getProduct_hash(productId) + productInfo['productId']= productId + result.append(productInfo) + + return result + diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index caeb22c61..ae57cb9c2 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -417,20 +417,20 @@ sub opsi_modify_client { # @param session_id - INTEGER - POE session id of the processing of this message # @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_get_netboot_products { - my $startTime = Time::HiRes::time; + my $startTime = Time::HiRes::time; my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; my $hostId; - my $xml_msg; # Build return message with twisted target and source my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } + &add_content2xml_hash($out_hash, "xxx", ""); # Get hostId if defined if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1)) { @@ -438,96 +438,47 @@ sub opsi_get_netboot_products { &add_content2xml_hash($out_hash, "hostId", $hostId); } - &add_content2xml_hash($out_hash, "xxx", ""); - $xml_msg = &create_xml_string($out_hash); - # For hosts, only return the products that are or get installed + # Move to XML string + my $xml_msg= &create_xml_string($out_hash); + my $callobj; - $callobj = { - method => 'getNetBootProductIds_list', - params => [ ], - id => 1, - }; - &main::daemon_log("$session_id DEBUG: send callobj to opsi_client: ".&opsi_callobj2string($callobj), 7); - &main::daemon_log("$session_id DEBUG: opsi_url $main::opsi_url", 7); - &main::daemon_log("$session_id DEBUG: waiting for answer from opsi_client!", 7); - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - &main::daemon_log("$session_id DEBUG: get answer from opsi_client", 7); - my %r = (); - for (@{$res->result}) { $r{$_} = 1 } + # Check if we need to get host or global information + if (defined $hostId){ + $callobj = { + method => 'getProductHostInformation_list', + params => [ $hostId, undef, 'netboot'], + id => 1, + }; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); if (not &check_opsi_res($res)){ + foreach my $product (@{$res->result}){ + my $replace= "".xml_quote($product->{'productId'})."<\/productId>".xml_quote($product->{'name'})."<\/name>".xml_quote($product->{'description'})."<\/description>".xml_quote($product->{'installationStatus'})."".xml_quote($product->{'actionRequest'})."<\/item><\/xxx>"; + $xml_msg=~ s/<\/xxx>/\n$replace/; + } + } - if (defined $hostId){ - - $callobj = { - method => 'getProductStates_hash', - params => [ $hostId ], - id => 1, - }; - - my $hres = $main::opsi_client->call($main::opsi_url, $callobj); - if (not &check_opsi_res($hres)){ - my $htmp= $hres->result->{$hostId}; - - # check state != not_installed or action == setup -> load and add - foreach my $product (@{$htmp}){ - - if (!defined ($r{$product->{'productId'}})){ - next; - } - - # Now we've a couple of hashes... - if ($product->{'installationStatus'} ne "not_installed" or - $product->{'actionRequest'} eq "setup"){ - my $state= "".$product->{'installationStatus'}."".$product->{'actionRequest'}.""; - - $callobj = { - method => 'getProduct_hash', - params => [ $product->{'productId'} ], - id => 1, - }; - - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (not &check_opsi_res($sres)){ - my $tres= $sres->result; - - my $name= xml_quote($tres->{'name'}); - my $r= $product->{'productId'}; - my $description= xml_quote($tres->{'description'}); - $name=~ s/\//\\\//; - $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/\n$r<\/productId>$name<\/name>$description<\/description><\/item>$state<\/xxx>/; - } - } - } - - } + } else { - } else { - foreach my $r (@{$res->result}) { - $callobj = { - method => 'getProduct_hash', - params => [ $r ], - id => 1, - }; - - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (not &check_opsi_res($sres)){ - my $tres= $sres->result; - - my $name= xml_quote($tres->{'name'}); - my $description= xml_quote($tres->{'description'}); - $name=~ s/\//\\\//; - $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/\n$r<\/productId>$name<\/name>$description<\/description><\/item><\/xxx>/; - } - } + # For hosts, only return the products that are or get installed + $callobj = { + method => 'getProductInformation_list', + params => [ undef, 'netboot' ], + id => 1, + }; - } + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($res)){ + foreach my $product (@{$res->result}) { + my $replace= "".xml_quote($product->{'productId'})."<\/productId>".xml_quote($product->{'name'})."<\/name>".xml_quote($product->{'description'})."<\/description><\/item><\/xxx>"; + $xml_msg=~ s/<\/xxx>/\n$replace/; + } + } } + $xml_msg=~ s/<\/xxx>//; - # Return message + # Retrun Message &main::daemon_log("0 DEBUG: time to process gosa-si message '$header' : ".sprintf("%.4f", (Time::HiRes::time - $startTime))." seconds", 1034); return ( $xml_msg ); } @@ -866,7 +817,7 @@ sub opsi_list_clients { # JSON Query my $callobj = { - method => 'getClients_listOfHashes', + method => 'getClientsInformation_listOfHashes', params => [ ], id => 1, }; @@ -967,7 +918,7 @@ sub opsi_get_client_software { # @param session_id - INTEGER - POE session id of the processing of this message # @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_get_local_products { - my $startTime = Time::HiRes::time; + my $startTime = Time::HiRes::time; my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; @@ -991,88 +942,39 @@ sub opsi_get_local_products { # Move to XML string my $xml_msg= &create_xml_string($out_hash); - # For hosts, only return the products that are or get installed my $callobj; - $callobj = { - method => 'getLocalBootProductIds_list', - params => [ ], - id => 1, - }; - - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - my %r = (); - for (@{$res->result}) { $r{$_} = 1 } - - if (not &check_opsi_res($res)){ - - if (defined $hostId){ - $callobj = { - method => 'getProductStates_hash', - params => [ $hostId ], - id => 1, - }; - - my $hres = $main::opsi_client->call($main::opsi_url, $callobj); - if (not &check_opsi_res($hres)){ - my $htmp= $hres->result->{$hostId}; - - # Check state != not_installed or action == setup -> load and add - foreach my $product (@{$htmp}){ - - if (!defined ($r{$product->{'productId'}})){ - next; - } - - # Now we've a couple of hashes... - if ($product->{'installationStatus'} ne "not_installed" or - $product->{'actionRequest'} eq "setup"){ - my $state= "".$product->{'installationStatus'}."".$product->{'actionRequest'}.""; - - $callobj = { - method => 'getProduct_hash', - params => [ $product->{'productId'} ], - id => 1, - }; - - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (not &check_opsi_res($sres)){ - my $tres= $sres->result; - - my $name= xml_quote($tres->{'name'}); - my $r= $product->{'productId'}; - my $description= xml_quote($tres->{'description'}); - $name=~ s/\//\\\//; - $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/\n$r<\/productId>$name<\/name>$description<\/description><\/item>$state<\/xxx>/; - } - - } - } + # Check if we need to get host or global information + if (defined $hostId){ + $callobj = { + method => 'getProductHostInformation_list', + params => [ $hostId ], + id => 1, + }; - } + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($res)){ + foreach my $product (@{$res->result}){ + my $replace= "".xml_quote($product->{'productId'})."<\/productId>".xml_quote($product->{'name'})."<\/name>".xml_quote($product->{'description'})."<\/description>".xml_quote($product->{'installationStatus'})."".xml_quote($product->{'actionRequest'})."<\/item><\/xxx>"; + $xml_msg=~ s/<\/xxx>/\n$replace/; + } + } - } else { - foreach my $r (@{$res->result}) { - $callobj = { - method => 'getProduct_hash', - params => [ $r ], - id => 1, - }; - - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (not &check_opsi_res($sres)){ - my $tres= $sres->result; - - my $name= xml_quote($tres->{'name'}); - my $description= xml_quote($tres->{'description'}); - $name=~ s/\//\\\//; - $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/\n$r<\/productId>$name<\/name>$description<\/description><\/item><\/xxx>/; - } + } else { - } + # For hosts, only return the products that are or get installed + $callobj = { + method => 'getLocalBootProductInformation_list', + params => [ ], + id => 1, + }; - } + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($res)){ + foreach my $product (@{$res->result}) { + my $replace= "".xml_quote($product->{'productId'})."<\/productId>".xml_quote($product->{'name'})."<\/name>".xml_quote($product->{'description'})."<\/description><\/item><\/xxx>"; + $xml_msg=~ s/<\/xxx>/\n$replace/; + } + } } $xml_msg=~ s/<\/xxx>//; -- 2.30.2