[Spacewalk-list] Duplicates and Reactivation (solved)

Sascha Bendix bendsa at idmt.fraunhofer.de
Wed May 12 11:17:24 UTC 2010


Hi,

inspired by the solution which was posted by Tom I took a closer look at
the xmlrpc interface.

To make long story short: The following cgi script returns a
reactivation key for the machine you are coming from. When registring
with this key the problem of duplicates is avoided.

<code|/var/www/cgi-bin/getreactivationkey.cgi>
#!/usr/bin/perl

use strict;
use RHNSession;

my $system_name = $ENV{'REMOTE_HOST'};

$system_name =~ s/\..*$//;

print 'Content-type: text/plain'."\n\n";

my ($client, $session) = RHNSession::Session;
my $systems = $client->call('system.list_user_systems', $session);

for my $system (@{$systems}) {
    if ($system->{'name'} eq $system_name) {
        print $client->call('system.obtainReactivationKey',
$session,$system->{'id'});
        last;
    }
}
</code>

Additionally you will need my variant of the RHNSession Module:

<code|/usr/lib/perl5/vendor_perl/5.8.8/RHNSession.pm>
package RHNSession;

use strict;
use Exporter;
use Frontier::Client;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

$VERSION     = 0.01;
@ISA         = qw(Exporter);
@EXPORT      = ();
@EXPORT_OK   = qw(Session);
%EXPORT_TAGS = ( DEFAULT => [qw(&Session)] );

sub Session {
  open(IN, "/etc/satellite_api.conf") or die "Couldn't open file for
reading: $!";
  $_ = <IN>;
  my ($HOST, $USER, $PASS) = (split);
  close(IN);

  my $client = new Frontier::Client(url => "https://$HOST/rpc/api");
  my $session = $client->call('auth.login', $USER, $PASS);

  return ($client, $session);
}

1;
</code>

the packages perl-IO-Socket-SSL and perl-Frontier-RPC and a file
/etc/satellite_api.conf with the following content:
<spacewalk-fqdn> <spacewalk-user> <spacewalk-userpassword>

To the developers: Thanks for the wunderful xmlrpc interface :-)

Regards,

Sascha




More information about the Spacewalk-list mailing list