Created
October 8, 2017 09:03
-
-
Save sideangleside/4a8bfa100a6fa407df33b22a1a15f93d to your computer and use it in GitHub Desktop.
Check location awareness in RHN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import getpass | |
import os | |
import sys | |
import libxml2 | |
import xmlrpclib | |
from optparse import OptionParser | |
parser = OptionParser() | |
parser.add_option("-l", "--login", dest="login", help="Login user for RHN Satellite/Hosted", metavar="LOGIN") | |
parser.add_option("-p", "--password", dest="password", help="Password for specified user. Will prompt if omitted", metavar="PASSWORD") | |
parser.add_option("-s", "--server", dest="serverfqdn", help="FQDN of satellite server - omit https://", metavar="SERVERFQDN") | |
(options, args) = parser.parse_args() | |
if not ( options.login and options.serverfqdn): | |
print "Must specify login and server options. See usage:" | |
parser.print_help() | |
print "\nExample usage: ./location_aware.py -l admin -p password -s satellite.example.com" | |
sys.exit(1) | |
else: | |
login = options.login | |
password = options.password | |
serverfqdn = options.serverfqdn | |
if not password: password = getpass.getpass("%s's password:" % login) | |
SATELLITE_URL = "https://%s/rpc/api" % serverfqdn | |
SATELLITE_LOGIN = login | |
SATELLITE_PASSWORD = password | |
SYSTEMID_FILE = "/etc/sysconfig/rhn/systemid" | |
client = xmlrpclib.Server(SATELLITE_URL, verbose=0) | |
key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD) | |
# Check For root | |
# Have to be root to open the SYSTEMID_FILE which is chmod'd 0600 | |
if os.getuid() != 0: | |
print "This script requires root-level access to run." | |
sys.exit(1) | |
# Log into Satellite and get an authentication token | |
client = xmlrpclib.Server(SATELLITE_URL, verbose=0) | |
key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD) | |
# Parse /etc/sysconfig/rhn/systemid to ge the system ID | |
# Use the systemid and delete the systems RHN profile | |
parsed_file = libxml2.parseDoc(file(SYSTEMID_FILE).read()) | |
systemid = parsed_file.xpathEval('string(//member[* ="system_id"]/value/string)').split('-')[1] | |
print systemid | |
try: | |
details = client.system.getDetails(key,int(systemid)) | |
print details['location_aware_download'] | |
except xmlrpclib.Fault, e: | |
print "XMLRPC fault \n\t%s" % e | |
# Logout of Satellite | |
client.auth.logout(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment