tips‎ > ‎

RHN Tricks

RHN LIST SERVERS

Getting a simple list of servers out of the RHN is a Pain

python+api to the rescue :
#!/usr/bin/python

import xmlrpclib

SATELLITE_URL = "https://rhn.redhat.com/rpc/api"
SATELLITE_LOGIN = "rhn-account"
SATELLITE_PASSWORD = "rhn-password"

client = xmlrpclib.Server(SATELLITE_URL, verbose=0)
key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)
list = client.system.listUserSystems(key)

for group in list:
    sysname = group.get('name')
    sysid =  group.get('id')
    print '{0} - {1} ' .format (sysname, sysid)


client.auth.logout(key)

This outputs a tab seperated list of system name and id  (the is is handy for batch erase)

RHN Delete servers

erasing servers is also too many clicks!

#!/usr/bin/python

import xmlrpclib
import sys

SATELLITE_URL = "https://rhn.redhat.com/rpc/api"
SATELLITE_LOGIN = "rhn-account"
SATELLITE_PASSWORD = "rhn-pass"


client = xmlrpclib.Server(SATELLITE_URL, verbose=0)
key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)

for system in sys.argv:
    # SKIP the first element of the args as it's always the script name
    if system == sys.argv[0]:
        continue
       
    print 'asking RHN to delete :{0}'.format (system)
    sysid = int(system)
    client.system.deleteSystems(key,sysid)

client.auth.logout(key)



Comments