Oracle Linux, virtualization , Enterprise and Cloud Management Cloud technology musings

  • May 15, 2014

Unbreakable Linux Network APIs example

I posted a short blog entry about the recently released ULN APIs the other day with a sample of how to call the different APIs. Here is a concrete example to use the API to find a package in a channel and download it.

$ ./ulnget.py kernel-headers.2.6.32-71.29 ol6_x86_64_latest
Searching for 'kernel-headers.2.6.32-71.29' in channel 'ol6_x86_64_latest'
Logging in...
Logged in...
Retrieving all packages...
Found kernel-headers.2.6.32-71.29.1.el6
Getting package details...
Downloading https://uln.oracle.com/XMLRPC/GET-REQ/ol6_x86_64_latest/
Logged out...

The code for the above is pasted below, this is just a very simplistic example...

import os
import sys
import getpass
import datetime
import xmlrpclib
except ImportError, e:
raise ImportError (str(e) + ': Module not found')
if len(sys.argv) != 3:
print "Usage : ulnget.py [packagename] [channelname]"
search = str(sys.argv[1])
channelLabel = str(sys.argv[2])
print "Searching for '%s' in channel '%s'" % (search, channelLabel)
SERVER_URL = 'https://linux-update.oracle.com/rpc/api'
USERNAME = 'username'
PASSWORD = 'password'
# channelLabel = 'ol6_x86_64_latest'
client = xmlrpclib.Server(SERVER_URL)
print ""
# login
print "Logging in..."
sessionKey = client.auth.login(USERNAME,PASSWORD)
if len(sessionKey) != 43:
print "Invalid %d sessionKey : '%s'" % sessionKey
print "Logged in..."
print "Retrieving all packages..."
packageList = client.channel.software.listAllPackages(sessionKey, channelLabel)
for package in packageList:
packageName = '%s.%s-%s' % (package['package_name'],package['package_version']
if search in packageName:
print "Found %s" % packageName
pid = package['package_id']
print "Getting package details..."
packageDetail = client.packages.getDetails(sessionKey, pid)
url = packageDetail['download_urls'][0]
import urllib2
req = urllib2.Request(url,headers={'X-ULN-API-User-Key': sessionKey})
print "Downloading %s..." %url
response = urllib2.urlopen(req)
contents = response.read()
except urllib2.HTTPError, e:
print "HTTP error code : %d" %e.code
except Exception, e:
print str(e)
print ""
retval = client.auth.logout(sessionKey)
if retval == 1:
print "Logged out..."
print "Failed to log out..."

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.