Difference between revisions of "SUSE Manager/ReRegisterPy"

From MicroFocusInternationalWiki
Jump to: navigation, search
(Undo revision 21540 by 137.65.227.74 (talk))
(Undo revision 21540 by 137.65.227.74 (talk))
 
(One intermediate revision by the same user not shown)
(No difference)

Latest revision as of 12:55, 16 March 2015

#!/usr/bin/python
#
# Tool to re-register a server against a SUSE Manager Proxy Server
# Usage: proxy_rereg.py user suman_proxy_dns
#
# Created by: SUSE Michael Brookhuis, August 29, 2013
#
import os, sys, subprocess, xmlrpclib, getpass

MANAGER_URL = "http://192.168.245.50/rpc/api"
MANAGER_LOGIN = sys.argv[1]
REG_SERVER = sys.argv[2]
SYSTEM_ID = "/etc/sysconfig/rhn/systemid"

# Looking up server ID
fin = open(SYSTEM_ID)
for i in fin:
    for k in i.split('>'):
        if k.startswith('ID-'):
           id = int(k.rsplit('-')[1].rsplit('<')[0])
fin.close

# Request password admin user
MANAGER_PASSWORD = getpass.getpass()

# Requesting re-activation key
client = xmlrpclib.Server(MANAGER_URL, verbose=0)
key = client.auth.login(MANAGER_LOGIN, MANAGER_PASSWORD)
rekey = client.system.obtainReactivationKey(key, id )
client.auth.logout(key)

# Re-Registering server
bcmd = "rhnreg_ks --activationkey="+str(rekey)+" --serverUrl=http://"+REG_SERVER+"/XMLRPC --force"
os.system(bcmd)