#!/usr/bin/python # This program sets the public_ip custom value in Satellite. # # 1. read file containing system name and public IP # 2. find systemid # 3. write custom info using systemid & public IP # # It could be improved by (among other things): # not depending on global variables # import xmlrpclib import os import sys import libxml2 from optparse import OptionParser client = xmlrpclib.Server(http://YOUR.SATELLITE.URL, verbose=0) key = client.auth.login(YOUR_SATELLITE_LOGIN, YOUR_SATELLITE_PASSWORD) def get_local_sysid(): # NOTE: This returns a string. To use it in conversing with the Satellite API, # you must convert it to an integer first (i.e. system_id = int(get_sysid.systemid)) # Also, I found this code on the web; it is not original. sysid_file = libxml2.parseDoc(file("/etc/sysconfig/rhn/systemid").read()) systemid = sysid_file.xpathEval('string(//member[*="system_id"]/value/string)').split('-')[1] return(systemid) def set_public_ip(sys_id,public_ip): # API call to set custominfo client.system.set_CustomValues(key,sys_id,{'public_ip': public_ip}) return # section 1 ip_file = open('/opt/pubip.txt','r') dataz = line.split(" ") short_name = dataz[0] print 'Processing', short_name, '...' public_ip = dataz[1] # section 2 system_id = get_local_sysid() #print 'After returning from loop, I have', short_name, 'matching', system_id set_public_ip(system_id,public_ip) ip_file.close() client.auth.logout(key)