summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1651ca9)
raw | patch | inline | side by side (parent: 1651ca9)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 16 Nov 2009 16:12:15 +0000 (16:12 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 16 Nov 2009 16:12:15 +0000 (16:12 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14820 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/contrib/90_gosa.conf | patch | blob | history | |
gosa-si/server/events/opsi_com.pm | patch | blob | history |
index cb957c94a98cc859d894f9dbf92916940aed8316..53beacdeba7b5a31901e93d2b0927dba35f5a5d7 100644 (file)
-''' 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']
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
+
index caeb22c614299f17dc99c8d18632a46b1e5d3aac..ae57cb9c28c19fbdaadffbc18027a1b2fc7e2af0 100644 (file)
# @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)) {
&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= "<item><productId>".xml_quote($product->{'productId'})."<\/productId><name>".xml_quote($product->{'name'})."<\/name><description>".xml_quote($product->{'description'})."<\/description><state>".xml_quote($product->{'installationStatus'})."</state><action>".xml_quote($product->{'actionRequest'})."</action><\/item><xxx><\/xxx>";
+ $xml_msg=~ s/<xxx><\/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= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
-
- $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><\/xxx>/\n<item><productId>$r<\/productId><name>$name<\/name><description>$description<\/description><\/item>$state<xxx><\/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><\/xxx>/\n<item><productId>$r<\/productId><name>$name<\/name><description>$description<\/description><\/item><xxx><\/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= "<item><productId>".xml_quote($product->{'productId'})."<\/productId><name>".xml_quote($product->{'name'})."<\/name><description>".xml_quote($product->{'description'})."<\/description><\/item><xxx><\/xxx>";
+ $xml_msg=~ s/<xxx><\/xxx>/\n$replace/;
+ }
+ }
}
+
$xml_msg=~ s/<xxx><\/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 );
}
# JSON Query
my $callobj = {
- method => 'getClients_listOfHashes',
+ method => 'getClientsInformation_listOfHashes',
params => [ ],
id => 1,
};
# @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];
# 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= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
-
- $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><\/xxx>/\n<item><productId>$r<\/productId><name>$name<\/name><description>$description<\/description><\/item>$state<xxx><\/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= "<item><productId>".xml_quote($product->{'productId'})."<\/productId><name>".xml_quote($product->{'name'})."<\/name><description>".xml_quote($product->{'description'})."<\/description><state>".xml_quote($product->{'installationStatus'})."</state><action>".xml_quote($product->{'actionRequest'})."</action><\/item><xxx><\/xxx>";
+ $xml_msg=~ s/<xxx><\/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><\/xxx>/\n<item><productId>$r<\/productId><name>$name<\/name><description>$description<\/description><\/item><xxx><\/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= "<item><productId>".xml_quote($product->{'productId'})."<\/productId><name>".xml_quote($product->{'name'})."<\/name><description>".xml_quote($product->{'description'})."<\/description><\/item><xxx><\/xxx>";
+ $xml_msg=~ s/<xxx><\/xxx>/\n$replace/;
+ }
+ }
}
$xml_msg=~ s/<xxx><\/xxx>//;