RHN XMLRPC API

Christian.Rohrmeier at SCHERING.DE Christian.Rohrmeier at SCHERING.DE
Fri Dec 9 09:31:03 UTC 2005


Hi Martin,

I finally got XMLRPC working with the Frontier Perl module. The example
that
is provided by Red Hat has a few minor problems (specifically, you have to
use HTTPS and not HTTP... that was the trick). I'm a passable with Perl,
but
know nothing about Python. Although, Python doesn't look that hard. =)

The XMLRPC API is okay. It is decent enough... initially its good enough to
let me get a listing of all errata of type "security" for example. Which is
what I urgently need.

Maybe you can clue me in on the next problem that I have: having identified
the specific errata I wish to retrieve, how to I get up2date to download
packages/errata from channels that do not match the specific system that I
am running up2date from? Lets say my retrieval system is an RHEL 4 WS X86,
but I need to download packages/errata for RHEL 3 AS X86_64. Using up2date
--channel doesn't seem to work.

At the Linux World Expo in Frankfurt a few weeks ago I talked with a rep
from
RedHat that claimed that it should be possible to download packages for
any RHEL release regardless of what type of system the downloading system
has. My downloading system has an entitlement for RHEL AS, which means I
can
see channels for RHEL 2.1, 3, and 4, WS, ES, AS, X86 and X86_64 when I log
on
to RHN on the web. However, getting up2date to grab anything is difficult.

Is up2date the only way to download packages from RHN?

Thanks,

Christian

_________________
Christian Rohrmeier
Schering AG
Corporate IT - Infrastructure and Services
Computer Systems and Operations
System Administration - Research and Development
Tel +49 30 468 15794
Fax +49 30 468 95794


                                                                           
             James_Martin at ao.u                                             
             scourts.gov                                                   
             Sent by:                                                   To 
             kickstart-list-bo         Discussion list about Kickstart     
             unces at redhat.com          <kickstart-list at redhat.com>         
                                                                        cc 
                                                                           
             08.12.2005 16:51                                      Subject 
                                       Re: RHN XMLRPC API                  
                                                                           
             Please respond to                                             
              Discussion list                                              
              about Kickstart                                              
             <kickstart-list at r                                             
                edhat.com>                                                 
                                                                           
                                                                           




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

_______________________________________________
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