From cc0955fcf2bc8427fcc2e1fc386795cb106c1deb Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 22 Sep 2009 14:32:28 +0000 Subject: [PATCH] new functionality 'removeLicense' for plugin opsi_com.pm git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14315 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/server/events/opsi_com.pm | 111 +++++++++++++++++++++++++++--- gosa-si/tests/client.php | 4 +- 2 files changed, 106 insertions(+), 9 deletions(-) diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index d1b38625e..84d1d6143 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -33,6 +33,7 @@ my @events = ( "opsi_getLicensePools_listOfHashes", "opsi_getLicenseInformationForProduct", "opsi_getPool", + "opsi_removeLicense", "opsi_test", ); @EXPORT = @events; @@ -2014,7 +2015,7 @@ sub opsi_getPool { # Call Opsi two times my ($usages_res, $usages_err) = &_getSoftwareLicenseUsages_listOfHashes('licensePoolId'=>$licensePoolId); if ($usages_err){ - return &_giveErrorFeedback($msg_hash, "cannot get software license information from Opsi server: ".$usages_res, $session_id); + return &_giveErrorFeedback($msg_hash, "cannot get software license usage information from Opsi server: ".$usages_res, $session_id); } my ($licenses_res, $licenses_err) = &_getSoftwareLicenses_listOfHashes(); if ($licenses_err){ @@ -2061,6 +2062,50 @@ sub opsi_getPool { return ( &create_xml_string($out_hash) ); } + +################################ +# +# @brief Removes at first the software license from license pool and than deletes the software license. +# Attention, the software license has to exists otherwise it will lead to an Opsi internal server error. +# @param softwareLicenseId +# @param licensePoolId +# +sub opsi_removeLicense { + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + + # Check input sanity + my $softwareLicenseId; + if (&_check_xml_tag_is_ok ($msg_hash, 'softwareLicenseId')) { + $softwareLicenseId = @{$msg_hash->{'softwareLicenseId'}}[0]; + } else { + return ( &_give_feedback($msg, $msg_hash, $session_id, $_) ); + } + my $licensePoolId; + if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) { + $licensePoolId = @{$msg_hash->{'licensePoolId'}}[0]; + } else { + return ( &_give_feedback($msg, $msg_hash, $session_id, $_) ); + } + + # Call Opsi + my ($res, $err) = &_removeSoftwareLicenseFromLicensePool( 'licensePoolId' => $licensePoolId, 'softwareLicenseId' => $softwareLicenseId ); + if ($err){ + return &_giveErrorFeedback($msg_hash, "cannot delete software license from pool: ".$res, $session_id); + } + + # Call Opsi + ($res, $err) = &_deleteSoftwareLicense( 'softwareLicenseId'=>$softwareLicenseId ); + if ($err){ + return &_giveErrorFeedback($msg_hash, "cannot delete software license from Opsi server: ".$res, $session_id); + } + + # Create hash for the answer + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); + return ( &create_xml_string($out_hash) ); +} + sub opsi_test { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; @@ -2109,9 +2154,7 @@ sub _getLicensePool_hash { # Check Opsi error my ($res_error, $res_error_str) = &check_opsi_res($res); - if ($res_error){ - return ( $res_error_str, 1 ); - } + if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } return ($res->result, 0); } @@ -2127,9 +2170,7 @@ sub _getSoftwareLicenses_listOfHashes { # Check Opsi error my ($res_error, $res_error_str) = &check_opsi_res($res); - if ($res_error){ - return ( $res_error_str, 1 ); - } + if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } return ($res->result, 0); } @@ -2151,7 +2192,61 @@ sub _getSoftwareLicenseUsages_listOfHashes { # Check Opsi error my ($res_error, $res_error_str) = &check_opsi_res($res); - if ($res_error){ return ( $res_error_str, 1 ); } + if ($res_error){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } + + return ($res->result, 0); +} + +sub _removeSoftwareLicenseFromLicensePool { + my %arg = ( + 'softwareLicenseId' => undef, + 'licensePoolId' => undef, + @_, + ); + + if (not defined $arg{softwareLicenseId} ) { + return ("function requires softwareLicenseId as parameter", 1); + } + if (not defined $arg{licensePoolId} ) { + return ("function requires licensePoolId as parameter", 1); + } + + # Remove software license from license pool + my $callobj = { + method => 'removeSoftwareLicenseFromLicensePool', + params => [ $arg{softwareLicenseId}, $arg{licensePoolId} ], + 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){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } + + return ($res->result, 0); +} + +sub _deleteSoftwareLicense { + my %arg = ( + 'softwareLicenseId' => undef, + 'removeFromPools' => "", + ); + + if (not defined $arg{softwareLicenseId} ) { + return ("function requires softwareLicenseId as parameter", 1); + } + + # Fetch + my $callobj = { + method => 'deleteSoftwareLicense', + params => [ $arg{softwareLicenseId}, $arg{removeFromPools} ], + 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){ return ( (caller(0))[3]." : ".$res_error_str, 1 ); } return ($res->result, 0); } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 900c9bf7b..4b915457f 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -43,7 +43,9 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_opsi_getSoftwareLicense_hash
GOSA00:01:6C:9D:B9:FAl_2009-09-22_09:50:58_0
"; - $data = "
gosa_opsi_getPool
GOSA00:01:6C:9D:B9:FALicensePool
"; + #$data = "
gosa_opsi_getPool
GOSA00:01:6C:9D:B9:FALicensePool
"; + + $data = "
gosa_opsi_removeLicense
GOSA00:01:6C:9D:B9:FALicensePooll_2009-09-22_09:50:58_0
"; ############################## -- 2.30.2