RHN XMLRPC API

James_Martin at ao.uscourts.gov James_Martin at ao.uscourts.gov
Thu Dec 8 15:51:38 UTC 2005


I found it much easier to use python than perl against the RHN xmlrpc 
interface.. here's some simple code that queries your RHN account for 
systems subscribed, and also lets you delete machines.. I made it because 
I hate having to go through the GUI to remove a machine from RHN.

here's an example use:

rhn_tool.py -q -s    ---- queries all your subscribed systems
rhn_tool.py -s -d -h HOSTNAME  --- will delete machine machine HOSTNAME 
from RHN



I've used it successfully many times, but it's not production code, so USE 
AT YOUR OWN RISK.  (In fact the RHN API is not even supported according to 
Red Hat's documents, so this goes without saying).


#! /usr/bin/python

import xmlrpclib
from optparse import OptionParser



def GetOptions():
 
        parser=OptionParser()
 
        parser.add_option("-d", "--delete",
        action="store_true", dest="delete", default=False,
        help = "Deletes system, group, or channel")
 
        parser.add_option("-s", "--system",
                action="store_true", dest="system", default=False,
                help="Used when performing operations to machines 
subscribe to RHN.")
 
        parser.add_option("-q", "--query",
                action="store_true", dest="query", default=False,
                help="Used in conjuction with -s to show subscribed 
systems.")
 
 
        parser.add_option("-n", "--name",dest="hostname",
                help="hostname of machine to perform operation on.", 
metavar=" hostname")
 

        global options 
        (options,args) = parser.parse_args()
 

 
 
        return options.delete, options.system, options.hostname

def getSystemIds():

  systems = server.system.list_user_systems(session)


  return systems

 
def deleteSystem(sid):
 
 
 
  try:
 
    print "attempting to remove SID %s... with hostname of %s" % 
(sid,options.hostname)
 
    delete = server.system.delete_systems(session,sid)
 
    print "Deletion of %s successfull." % (options.hostname)
 
  except:
 
    print "Deletion of %s unsuccessfull." % (options.hostname)
 


 
 
host = 'xmlrpc.rhn.redhat.com'
username='YOURRHNUSERNAME'
password = 'YOURRHNPASSWORD'
protocol = 'https'
url = "%s://%s/rpc/api" %(protocol,host)


server = xmlrpclib.ServerProxy(url)

session = server.auth.login(username,password)



GetOptions()

if options.system:
 
  systems = getSystemIds()

  if options.query:
 
 
    if len(systems) == 0:
 
      print "No systems are subscribed to RHN."
 
    else:
 
      print "These machines are subscribed to RHN\n\n"
 
      print "Name: \t\tcheckin: \t\t\tsid: " 
 
      for vals in systems:
 
        print "%s\t\t%s\t\t%s" % 
(vals['name'],vals['last_checkin'],vals['id'])
 

  if options.delete:
 
    for vals in systems:
      if vals['name'] == options.hostname:
        deleteSystem(vals['id'])




If you are looking into getting errata information, check out these API 
calls: https://rhn.redhat.com/rpc/api/errata/

You might be able to return a hash/dictionary of released errata and parse 
through the ones you want.



James S. Martin, RHCE
Contractor
Administrative Office of the United States Courts
Washington, DC
(202) 502-2394

kickstart-list-bounces at redhat.com wrote on 12/07/2005 10:32:37 AM:

> On Mon, Nov 28, 2005 at 10:10:42AM +0100, Christian.
> Rohrmeier at SCHERING.DE wrote:
> > 
> > Hi Kickstarters,
> > 
> > my question relates tangentially to anaconda, so bear with me if you 
can.
> > Possibly nobody knows a thing about this, but maybe somebody knows 
somebody
> > else who does know.
> > 
> > I am trying to use the XMLRPC based RHN API to automate the sorting 
and
> > downloading of specific typs of updates (there is no other way to get 
a
> > list of the security updates, for example, because up2date only gives 
you
> > all updates of a particular channel, with security, bugfixes, and 
feature
> > enhancements alle mixed together.) Described here:
> > http://www.redhat.com/docs/manuals/RHNetwork/ref-guide/4.0/ap-rhn-
> api-access.html
> > 
> > This relates to my installs, because I would like to have Kickstart 
apply
> > all current security updates during a new installation. I realize its 
not a
> > Kickstart question, but you guys have such a wealth of knowledge, I'm
> > hoping somebody out there has experience interfcaing with RHN via the 
API.
> > 
> > Many thanks in advance.
> > 
> > Christian
> > 
> > PS. I'm trying to use the Frontier XMLRPC module for Perl, as it is
> > described in the sample code:
> > http://www.redhat.com/docs/manuals/RHNetwork/ref-guide/4.0/s1-rhn-
> api-script.html
> > which I can't get to work.
> 
> Hi Christian,
> 
> I have the example script provided by redhat working against our
> satellite.
> 
> However, I'm a little underwhelmed by the API. It only provides access
> to a small subset of the info available in the db.
> 
> There isn't much info on this so I'm trying to get beyond the RHN pdfs.
> 
> I've subscribed to rhn-users and rhn-satellite-users so that should be a
> start.
> 
> If anyone knows of other detailed sites please do let me know.
> 
> I'm willing to roll my sleeves up and hack the API to get new methods
> that do more, if required.
> 
> Thanks,
> 
> Ben.
> 
> -- 
> Registered Linux user number 339435
> 
> _______________________________________________
> Kickstart-list mailing list
> Kickstart-list at redhat.com
> https://www.redhat.com/mailman/listinfo/kickstart-list




More information about the Kickstart-list mailing list