#!/usr/bin/python import os import sys import re import xmlrpclib import getpass rhnUrl='https://rhn.redhat.com/rpc/api' server=xmlrpclib.Server(rhnUrl) login=False password=False rhnSession=False def detect_sid(): systemidFile="/etc/sysconfig/rhn/systemid" if(not os.path.isfile(systemidFile)): print "no such systemid file",systemidFile sys.exit() f=open(systemidFile,'r') output=False for l in f.readlines(): reg=re.compile("ID-(\d+)") if reg.search(l): output=reg.search(l).group(1) f.close() if not output: print "Cannot get sid" sys.exit() return output def rhnlogin(login,password): print "let s log on rhn" try: rhnSession=server.auth.login(login,password) except xmlrpclib.Fault, fault: if fault.faultCode==-20: print "session expired" rhnlogin(login,password) else: print "Trouble at login",fault raise return rhnSession def get_subscribed_childs(rhnSession,sid): try: output=server.system.list_child_channels(rhnSession,sid) except xmlrpclib.Fault, fault: if fault.faultCode==-20: print "session expired" rhnlogin(login,password) return get_subscribed_childs(rhnSession,sid) else: raise return output def subscribeMe(rhnSession,sid,cid): output=False try: output=server.system.set_child_channels(rhnSession,sid,cid) except xmlrpclib.Fault, fault: if fault.faultCode==-20: print "session expired" rhnlogin(login,password) return subscribeMe(rhnSession,sid,cid) else: raise return output login=raw_input("What is your rhn login ?: ") #password=raw_input("What is your rhn password ?: ") password=getpass.getpass("What is your rhn password ?: ") sid=detect_sid() print "sid=",sid rhnSession=rhnlogin(login,password) for p in get_subscribed_childs(rhnSession,sid): name=p['LABEL'] cid=p['ID'] reg=re.compile("fastrack") if reg.search(name): if not subscribeMe(rhnSession,sid,cid): print "problem subscribing to ",name else: print "subscribed to "+name