From b00158055ebfacac2d10ac7bfcd2c3e94c28f6c8 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 26 Aug 2009 09:35:54 +0000 Subject: [PATCH] plugin opsi_com gets more wrapper functions for license management git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14138 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/server/events/opsi_com.pm | 105 ++++++++++++++++++------------ gosa-si/tests/client.php | 2 + 2 files changed, 64 insertions(+), 43 deletions(-) diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index e1abfe770..f1df5a4b4 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -33,6 +33,7 @@ my @events = ( "opsi_getLicensePool_hash", "opsi_getSoftwareLicenseUsages_listOfHashes", "opsi_getLicensePools_listOfHashes", + "opsi_getLicenseInformationForProduct", "opsi_test", ); @EXPORT = @events; @@ -1914,49 +1915,67 @@ sub opsi_unassignAllSoftwareLicensesFromHost { # # @brief # -#sub opsi_getLicenses_list { -# my ($msg, $msg_hash, $session_id) = @_; -# my $header = @{$msg_hash->{'header'}}[0]; -# my $source = @{$msg_hash->{'source'}}[0]; -# my $hostId; -# my $licensePoolId; -# my $out_hash; -# -# # Check input sanity -# if (&_check_xml_tag_is_ok ($msg_hash, 'hostId')) { -# $hostId = @{$msg_hash->{'hostId'}}[0]; -# } else { -# return ( &_give_feedback($msg, $msg_hash, $session_id, $_) ); -# } -# if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) { -# $licensePoolId = @{$msg_hash->{'licensePoolId'}}[0]; -# } else { -# return ( &_give_feedback($msg, $msg_hash, $session_id, $_) ); -# } -# -# # Fetch infos from Opsi server -# my $callobj = { -# method => 'getLicensePoolIds_list', -# params => [ ], -# id => 1, -# }; -# my $res = $main::opsi_client->call($main::opsi_url, $callobj); -# -# # Check Opsi error -# my ($res_error, $res_error_str) = &check_opsi_res($res); -# if ($res_error){ -# # Create error message -# &main::daemon_log("$session_id ERROR: cannot get license pool ID list from Opsi server: ".$res_error_str, 1); -# $out_hash = &main::create_xml_hash("error_$header", $main::server_address, $source, $res_error_str); -# -# } else { -# # Create function result message -# $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); -# map(&add_content2xml_hash($out_hash, "licensePoolIds", "$_"), @{$res->result}); -# } -# -# return ( &create_xml_string($out_hash) ); -#} +sub opsi_getLicenseInformationForProduct { + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $productId; + my $out_hash; + + # Check input sanity + if (&_check_xml_tag_is_ok ($msg_hash, 'productId')) { + $productId = @{$msg_hash->{'productId'}}[0]; + } else { + return ( &_give_feedback($msg, $msg_hash, $session_id, $_) ); + } + + # Fetch infos from Opsi server + my $callobj = { + method => 'getLicensePoolId', + params => [ $productId ], + id => 1, + }; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + + # Check Opsi error + my ($res_error, $res_error_str) = &check_opsi_res($res); + if ($res_error){ + # Create error message + &main::daemon_log("$session_id ERROR: cannot get license pool for product '$productId' : ".$res_error_str, 1); + $out_hash = &main::create_xml_hash("error_$header", $main::server_address, $source, $res_error_str); + return ( &create_xml_string($out_hash) ); + } + + my $licensePoolId = $res->result; + + # Fetch statistic information for given pool ID + my $callobj = { + method => 'getLicenseStatistics_hash', + params => [ ], + id => 1, + }; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + + # Check Opsi error + my ($res_error, $res_error_str) = &check_opsi_res($res); + if ($res_error){ + # Create error message + &main::daemon_log("$session_id ERROR: cannot get statistic informations for license pools : ".$res_error_str, 1); + $out_hash = &main::create_xml_hash("error_$header", $main::server_address, $source, $res_error_str); + return ( &create_xml_string($out_hash) ); + } + + # Create function result message + $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); + &add_content2xml_hash($out_hash, "licensePoolId", $licensePoolId); + &add_content2xml_hash($out_hash, "licenses", $res->result->{$licensePoolId}->{'licenses'}); + &add_content2xml_hash($out_hash, "usageCount", $res->result->{$licensePoolId}->{'usageCount'}); + &add_content2xml_hash($out_hash, "maxInstallations", $res->result->{$licensePoolId}->{'maxInstallations'}); + &add_content2xml_hash($out_hash, "remainingInstallations", $res->result->{$licensePoolId}->{'remainingInstallations'}); + map(&add_content2xml_hash($out_hash, "usedBy", "$_"), @{ $res->result->{$licensePoolId}->{'usedBy'}}); + + return ( &create_xml_string($out_hash) ); +} sub opsi_test { my ($msg, $msg_hash, $session_id) = @_; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 86784ed5e..4c16e6cef 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -19,6 +19,8 @@ for($count = 1; $count <= $zahl; $count++) # Funktioniert noch nicht #$data = "
gosa_opsi_test
GOSA00:01:6C:9D:B9:FAacroread
"; + $data = "
gosa_opsi_getLicenseInformationForProduct
GOSA00:01:6C:9D:B9:FAacroread
"; + #$data = "
gosa_opsi_getLicensePools_listOfHashes
GOSA00:01:6C:9D:B9:FA
"; #$data = "
gosa_opsi_getLicensePool_hash
GOSA00:01:6C:9D:B9:FASusi
"; -- 2.30.2