summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aacf4b2)
raw | patch | inline | side by side (parent: aacf4b2)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 22 Sep 2009 13:26:21 +0000 (13:26 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 22 Sep 2009 13:26:21 +0000 (13:26 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14312 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/server/events/opsi_com.pm | patch | blob | history | |
gosa-si/tests/client.php | patch | blob | history |
index ab19391835874278b157ee85f5c29114607f24c0..d1b38625ec330d92a7d5b1b321cde4856365aeff 100644 (file)
sub _give_feedback {
my ($msg, $msg_hash, $session_id, $error) = @_;
&main::daemon_log("$session_id ERROR: $error: ".$msg, 1);
- my $out_hash = &main::create_xml_hash("error_".@{$msg_hash->{'header'}}[0], $main::server_address, @{$msg_hash->{'source'}}[0], $error);
+ my $out_hash = &main::create_xml_hash("error", $main::server_address, @{$msg_hash->{'source'}}[0], $error);
return &create_xml_string($out_hash);
}
&add_content2xml_hash($out_hash, "productId", $productId);
-#TODO : check the results for more than one entry which is currently installed
+# : check the results for more than one entry which is currently installed
#$callobj = {
# method => 'getProductDependencies_listOfHashes',
# params => [ $productId ],
$main::opsi_client->call($main::opsi_url, $callobj);
}
-# TODO
################################
#
# @brief Create a license pool at Opsi server.
map(&add_content2xml_hash($out_hash, "windowsSoftwareIds", "$_"), @{ $res->{'windowsSoftwareIds'} });
- # Call Opsi
- ($res, $err) = &_getSoftwareLicenses_listOfHashes();
- if ($err){
- return &_giveErrorFeedback($msg_hash, "cannot get software license information from Opsi server: ".$res, $session_id);
+ # 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);
+ }
+ my ($licenses_res, $licenses_err) = &_getSoftwareLicenses_listOfHashes();
+ if ($licenses_err){
+ return &_giveErrorFeedback($msg_hash, "cannot get software license information from Opsi server: ".$licenses_res, $session_id);
}
+
# Add data to outgoing hash
# Parse through all software licenses and select those associated to the pool
- my $res_hash = { 'softwareLicenseIds'=> [] };
- foreach my $license ( @$res) {
+ my $res_hash = { 'hit'=> [] };
+ foreach my $license ( @$licenses_res) {
# Each license hash has a list of licensePoolIds so go through this list and search for matching licensePoolIds
my $found = 0;
my @licensePoolIds_list = @{$license->{licensePoolIds}};
if ($lPI eq $licensePoolId) { $found++ }
}
if (not $found ) { next; };
- push( @{$res_hash->{softwareLicenseId}}, $license->{'softwareLicenseId'} );
+ # Found matching licensePoolId
+ my $license_hash = { 'softwareLicenseId' => [$license->{'softwareLicenseId'}],
+ 'licenseKeys' => {},
+ 'expirationDate' => [$license->{'expirationDate'}],
+ 'boundToHost' => [$license->{'boundToHost'}],
+ 'maxInstallations' => [$license->{'maxInstallations'}],
+ 'licenseType' => [$license->{'licenseType'}],
+ 'licenseContractId' => [$license->{'licenseContractId'}],
+ 'licensePoolIds' => [],
+ 'hostIds' => [],
+ };
+ foreach my $licensePoolId (@{ $license->{'licensePoolIds'}}) {
+ push( @{$license_hash->{'licensePooIds'}}, $licensePoolId);
+ $license_hash->{licenseKeys}->{$licensePoolId} = [ $license->{'licenseKeys'}->{$licensePoolId} ];
+ }
+ foreach my $usage (@$usages_res) {
+ # Search for hostIds with matching softwareLicenseId
+ if ($license->{'softwareLicenseId'} eq $usage->{'softwareLicenseId'}) {
+ push( @{ $license_hash->{hostIds}}, $usage->{hostId});
+ }
+ }
+
+ push( @{$res_hash->{hit}}, $license_hash );
}
$out_hash->{licenses} = [$res_hash];
return ();
}
+sub _giveErrorFeedback {
+ my ($msg_hash, $err_string, $session_id) = @_;
+ &main::daemon_log("$session_id ERROR: $err_string", 1);
+ my $out_hash = &main::create_xml_hash("error", $main::server_address, @{$msg_hash->{source}}[0], $err_string);
+ return ( &create_xml_string($out_hash) );
+}
+
sub _getLicensePool_hash {
my %arg = (
return ($res->result, 0);
}
-
sub _getSoftwareLicenses_listOfHashes {
# Fetch licenses associated to the given pool
my $callobj = {
return ($res->result, 0);
}
+sub _getSoftwareLicenseUsages_listOfHashes {
+ my %arg = (
+ 'hostId' => "",
+ 'licensePoolId' => "",
+ @_,
+ );
-sub _giveErrorFeedback {
- my ($msg_hash, $err_string, $session_id) = @_;
- &main::daemon_log("$session_id ERROR: $err_string", 1);
- my $out_hash = &main::create_xml_hash("error", $main::server_address, @{$msg_hash->{source}}[0], $err_string);
- return ( &create_xml_string($out_hash) );
+ # Fetch pool infos from Opsi server
+ my $callobj = {
+ method => 'getSoftwareLicenseUsages_listOfHashes',
+ params => [ $arg{hostId}, $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 ( $res_error_str, 1 ); }
+
+ return ($res->result, 0);
}
1;
index 3e0ff53de11abd1b95a899d55fd3b02d985f7c8d..900c9bf7becf859f7479c295d1f617f6b10d0ee6 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
#$data = "<xml><header>gosa_opsi_getLicensePools_listOfHashes</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target></xml>";
- #$data = "<xml><header>gosa_opsi_getLicensePool_hash</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><licensePoolId>Susi</licensePoolId></xml>";
+ #$data = "<xml><header>gosa_opsi_getLicensePool_hash</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><licensePoolId>LicensePool</licensePoolId></xml>";
#$data = "<xml><header>gosa_opsi_createLicensePool</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><licensePoolId>Harald</licensePoolId><description>Das 134te Schaaf</description><productIds>acrobat</productIds><productIds>winzip</productIds></xml>";
#$data = "<xml><header>gosa_opsi_getSoftwareLicenseUsages_listOfHashes</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><licensePoolId>Susi</licensePoolId></xml>";
#$data = "<xml><header>gosa_opsi_getSoftwareLicenseUsages_listOfHashes</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target></xml>";
- #$data = "<xml><header>gosa_opsi_getSoftwareLicense_hash</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><softwareLicenseId>l_2009-08-20_11:04:15_0</softwareLicenseId></xml>";
+ #$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>";
##############################