summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d70dbf6)
raw | patch | inline | side by side (parent: d70dbf6)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 22 Sep 2009 14:32:28 +0000 (14:32 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 22 Sep 2009 14:32:28 +0000 (14:32 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14315 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/server/events/opsi_com.pm | patch | blob | history | |
gosa-si/tests/client.php | patch | blob | history |
index d1b38625ec330d92a7d5b1b321cde4856365aeff..84d1d614353056fea17bdf86f4369a4105b4a65f 100644 (file)
"opsi_getLicensePools_listOfHashes",
"opsi_getLicenseInformationForProduct",
"opsi_getPool",
+ "opsi_removeLicense",
"opsi_test",
);
@EXPORT = @events;
# 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){
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];
# 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);
}
# 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);
}
# 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);
}
index 900c9bf7becf859f7479c295d1f617f6b10d0ee6..4b915457f7c08ced95f0c394dcce9f43c903e8af 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
#$data = "<xml><header>gosa_opsi_getSoftwareLicense_hash</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><softwareLicenseId>l_2009-09-22_09:50:58_0</softwareLicenseId></xml>";
- $data = "<xml><header>gosa_opsi_getPool</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><licensePoolId>LicensePool</licensePoolId></xml>";
+ #$data = "<xml><header>gosa_opsi_getPool</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><licensePoolId>LicensePool</licensePoolId></xml>";
+
+ $data = "<xml><header>gosa_opsi_removeLicense</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><licensePoolId>LicensePool</licensePoolId><softwareLicenseId>l_2009-09-22_09:50:58_0</softwareLicenseId></xml>";
##############################