LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-11-2012, 06:04 PM   #1
dcarrington
Member
 
Registered: Dec 2011
Distribution: RHEL, CentOS, Ubuntu
Posts: 61

Rep: Reputation: 2
Perl - RH Satellite APIs


Hello,

I'm trying to write a script to clean up my RH Satellite repositories so I can get rid of a lot of the old rpm's that are taking up space.

Most of the API's that I've been looking up are functioning as I would expect. However, some are not.

For example, I'm trying to identify what channel a package is in. There is an API called listProvidingChannels that seems like it might be useful, but when I use it, I can't seem to get any useful information out of it.

I've got an open session set up in the code already and I run the following line:

Quote:
my $channels = $client->call('packages.listProvidingChannels', $session, $packageid);
When I try to get information out of $channels, however, I can't get anything useful.

Any reference to $channels->{'name'} gives me the following errors:

Quote:
Pseudo-hashes are deprecated at ./cleansat.pl line 53, <> line 4.
Argument "\x{52}\x{65}..." isn't numeric in hash element at ./cleansat.pl line 53, <> line 4.
Bad index while coercing array into hash at ./cleansat.pl line 53, <> line 4.
If I simply do:

Quote:
print "$channels\n";
I get

Quote:
ARRAY(0x94ae35c)
Not sure where to find more information about these API's (this one specifically). Other API's that I use the same type of syntax for work as one would expect. For example, I have a line:

Quote:
my $latestpackages = $client->call('channel.software.listLatestPackages', $session, $chan);
If I reference $latestpackages->{'name'}, I get "acl" for example. If I reference $latestpackages->{'id'}, I get "54079" and so on.

Does anyone know more about this? Or know where I can find better, more detailed information?

Thanks!!!
 
Old 04-11-2012, 06:17 PM   #2
CTM
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 308

Rep: Reputation: 287Reputation: 287Reputation: 287
Use Data::Dumper (one of the Perl core modules) to recursively dump data structures:

Code:
print Dumper($channels), "\n";
If $channels is an object, it'll give you the class name so you can look up the code for that package and figure out what it represents.

Last edited by CTM; 04-11-2012 at 06:18 PM. Reason: Got tripped up by emoticons
 
Old 04-11-2012, 06:27 PM   #3
dcarrington
Member
 
Registered: Dec 2011
Distribution: RHEL, CentOS, Ubuntu
Posts: 61

Original Poster
Rep: Reputation: 2
CTM,

Awesome! I'll give that a try. Been banging my head on this one for the last three hours.
 
Old 04-11-2012, 06:32 PM   #4
dcarrington
Member
 
Registered: Dec 2011
Distribution: RHEL, CentOS, Ubuntu
Posts: 61

Original Poster
Rep: Reputation: 2
Nope. Unfortunately, that did not work:

Quote:
Undefined subroutine &main::Dumper called at ./cleansat.pl line 53, <> line 4.
 
Old 04-11-2012, 06:37 PM   #5
dcarrington
Member
 
Registered: Dec 2011
Distribution: RHEL, CentOS, Ubuntu
Posts: 61

Original Poster
Rep: Reputation: 2
Never mind....I missed the reference to 'Use Data:umper;' at the top of the post.

That did give me more info. Now to see if I can figure out why I can't get at it inside the code.
 
Old 04-11-2012, 06:46 PM   #6
CTM
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 308

Rep: Reputation: 287Reputation: 287Reputation: 287
The syntax that Data::Dumper uses in its output will give you some hints about how to use the data structure - although I don't use Red Hat myself, if you paste the output here I might be able to give you a push in the right direction
 
Old 04-11-2012, 06:55 PM   #7
dcarrington
Member
 
Registered: Dec 2011
Distribution: RHEL, CentOS, Ubuntu
Posts: 61

Original Poster
Rep: Reputation: 2
CTM,

I added a Dumper call with one of the other similar calls (the listLatestPackages one mentioned earlier) and the structure seems pretty much exactly the same...just different entries..but same format.

The one below is the one that's failing.

Quote:
$VAR1 = [
{
'parent_label' => ' ',
'name' => 'Red Hat Enterprise Linux Server (v. 6 for 64-bit x86_64)',
'label' => 'rhel-x86_64-server-6'
}
];

Pseudo-hashes are deprecated at ./cleansat.pl line 59, <> line 4.
Argument "\x{72}\x{68}..." isn't numeric in hash element at ./cleansat.pl line 59, <> line 4.
Bad index while coercing array into hash at ./cleansat.pl line 59, <> line 4.
 
Old 04-11-2012, 07:04 PM   #8
CTM
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 308

Rep: Reputation: 287Reputation: 287Reputation: 287
Okay, the data structure you dumped is an arrayref ([]) of hashrefs ({}), so I assume it represents a list of available channels (I don't know any RHEL-specific terminology so I'm not sure what a "channel" really is). You can iterate over the arrayref in the usual way, but remember to dereference the arrayref before operating on it as if it were an array:

Code:
foreach my $channel (@{$channels}) {
    print $channel->{name}, "\n";
}
 
Old 04-12-2012, 10:01 AM   #9
dcarrington
Member
 
Registered: Dec 2011
Distribution: RHEL, CentOS, Ubuntu
Posts: 61

Original Poster
Rep: Reputation: 2
CTM,

That's pretty much exactly the code I have...before removing anything I wanted to just print out each element to verify I was getting the right information. That exact code that you have there is what throws the errors I put in the original post. That's why I'm so confused about this. It seems like that should work. But it's not. :-(
 
Old 04-13-2012, 10:15 AM   #10
CTM
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 308

Rep: Reputation: 287Reputation: 287Reputation: 287
That's bizarre. Could you post your full source code?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] use bios from Toshiba Satellite 3000 on a Satellite 2800-202? coyotl Linux - Hardware 4 12-13-2011 03:44 AM
satellite internet + VoIP or satellite internet + satellite phone rblampain Linux - Networking 2 08-27-2010 08:05 AM
C++ APIs manolakis Programming 5 08-28-2007 03:34 PM
Creating APIs blackhock Programming 4 06-15-2006 03:34 PM
APIs elitecodex Programming 14 03-04-2004 04:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration