API and RedHat Network

If you use RedHat Enterprise Linux in a big environment, you probably
use RedHat Network (RHN) as well.

RHN has a very well documented API, which can be used for all tasks
you want to do.

Here is a small script I wrote to list out all of our systems and when
they last checked in:

#!/usr/bin/python

import xmlrpclib
import getpass
from sys import stderr
import sys

RHN_URL = “https://rhn.redhat.com/rpc/api”

# Using stderr so redirect of the script to a file still works for prompts:
stderr.write(‘Please input your RHN username: ‘)
stderr.flush()
u = raw_input().rstrip(‘n’)
p = getpass.getpass(stream=sys.stderr)

client = xmlrpclib.Server(RHN_URL, verbose=0)
key = client.auth.login(u, p)
list = client.system.listUserSystems(key)

for group in list:
sysname = group.get(‘name’)
sysid = group.get(‘id’)
last_checkin = group.get(‘last_checkin’)
print ‘{0} – {1} ‘ .format (sysname, last_checkin)

client.auth.logout(key)

Hope that might be useful for someone else.

For more info on RHN’s APIs:
https://access.redhat.com/knowledge/docs/Red_Hat_Network/API_Documentation/

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: