martes, 13 de mayo de 2014

Unbreakable Linux Network APIs available

Unbreakable Linux Network APIs available
By wcoekaer on May 13, 2014
Wim Coekaerts Blog Oracle

Aside from the uln_channel tool that we recently released, we are now also supporting a number of webservices on ULN. A handful of useful APIs are available. Below is a little simple python example that works out of the box on Oracle Linux 6 (when you have an account on ULN) and a description of the currently available APIs. Note that the python code is very simplistic... I know no exception handling, wasn't the point ;)...

APIs :
client.auth.login(username,password) returns sessionKey 
client.errata.listCves(sessionKey, advisory) returns cveList
client.errata.applicableToChannels(sessionKey, advisory) returns channelList
client.channel.software.listLatestPackages(sessionKey, channelLabel) returns packageList
client.channel.software.listErrata(sessionKey, channelLabel) returns errataList
client.packages.listProvidingErrata(sessionKey, pid) returns errataList
client.channel.listSoftwareChannels(sessionKey) returns channelList
client.channel.software.listAllPackages(sessionKey, channelLabel) returns packageList
client.errata.listPackages(sessionKey, advisory) returns packageList
client.errata.getDetails(sessionKey, advisory) returns errataDetail
client.channel.software.getDetails(sessionKey, channelLabel) returns channelDetail
client.packages.getDetails(sessionKey, pid) returns packageDetail
client.auth.logout(sessionKey) returns retval
sample output of the code :
$ ./sample.py
Login : client.auth.login(username,password) returns sessionKey
Logged in...
List CVEs for a particular advisory : client.errata.listCves(sessionKey, advisory) returns cveList
Example : CVEs for advisory 'ELSA-2013-1100' : ['CVE-2013-2231']
List channels applicable to advisory : client.errata.applicableToChannels(sessionKey, advisory) returns channelList Example : Channels applicable to advisory 'ELSA-2013-1100' : [{'channel_name': 'Oracle Linux 6 Latest (i386)', 'channel_label': 'ol6_i386_latest', 'parent_channel_id': ' ', 'channel_id': 941}, {'channel_name': 'Oracle Linux 6 Latest (x86_64)', 'channel_label': 'ol6_x86_64_latest', 'parent_channel_id': ' ', 'channel_id': 944}, {'channel_name': 'Oracle Linux 6 Update 4 Patch (i386)', 'channel_label': 'ol6_u4_i386_patch', 'parent_channel_id': ' ', 'channel_id': 1642}, {'channel_name': 'Oracle Linux 6 Update 4 Patch (x86_64)', 'channel_label': 'ol6_u4_x86_64_patch', 'parent_channel_id': ' ', 'channel_id': 1644}]
List latest packages in a given channel : client.channel.software.listLatestPackages(sessionKey, channelLabel) returns packageList Example : Packages for channel 'ol6_x86_64_latest' returns 6801 packages
List errata in a given channel : client.channel.software.listErrata(sessionKey, channelLabel) returns errataList Example : Errata in channel 'ol6_x86_64_latest' returns 1403 errata
List errata for a given package : client.packages.listProvidingErrata(sessionKey, pid) returns errataList Example :
[{'errata_update_date': '2011-06-08 00:00:00', 'errata_advisory_type': 'Security Advisory', 'errata_synopsis': 'subversion security update', 'errata_advisory': 'ELSA-2011-0862', 'errata_last_modified_date': '2011-06-08 00:00:00', 'errata_issue_date': '2011-06-08 00:00:00'}]
List software channels available : client.channel.listSoftwareChannels(sessionKey) returns channelList Example : List of channels returns '253' channels
List all packages for a given channel : client.channel.software.listAllPackages(sessionKey, channelLabel) returns packageList Example : All packages for channel 'ol6_x86_64_latest' returns 25310 packages
List packages for a given advisory : client.errata.listPackages(sessionKey, advisory) returns packageList Example : Packages for advisory 'ELSA-2013-1100' returns 12 packages
Details for a specific advisory : client.errata.getDetails(sessionKey, advisory) returns errataDetail Example :
{'errata_update_date': '7/22/13', 'errata_topic': ' ', 'errata_type': 'Security Advisory', 'errata_severity': 'Important', 'errata_notes': ' ', 'errata_synopsis': 'qemu-kvm security update', 'errata_references': ' ', 'errata_last_modified_date': '2013-07-22 00:00:00', 'errata_issue_date': '7/22/13', 'errata_description': '[qemu-kvm-0.12.1.2-2.355.el6_4.6]\n- kvm-qga-cast-to-int-for-DWORD-type.patch [bz#980758]\n- kvm-qga-remove-undefined-behavior-in-ga_install_service.patch [bz#980758]\n- kvm-qga-diagnostic-output-should-go-to-stderr.patch [bz#980758]\n- kvm-qa_install_service-nest-error-paths-more-idiomatically.patch [bz#980758]\n- kvm-qga-escape-cmdline-args-when-registering-win32-service.patch [bz#980758]\n- Resolves: bz#980758\n (qemu-kvm: CVE-2013-2231 qemu: qemu-ga win32 service unquoted search path [rhel-6.4.z])'}
Details for a given channel : client.channel.software.getDetails(sessionKey, channelLabel) returns channelDetail Example :
{'channel_description': 'All packages released for Oracle Linux 6 (x86_64), including the very latest updated packages', 'channel_summary': 'Oracle Linux 6 Latest (x86_64)', 'channel_arch_name': 'x86_64', 'metadata_urls': {'group': [{'url': 'https://uln-qa.oracle.com/XMLRPC/GET-REQ/ol6_x86_64_latest/repodata/comps.xml', 'checksum': '08ec74da7552f56814bc7f94d60e6d1c3d8d9ff9', 'checksum_type': 'sha', 'file_name': 'repodata/comps.xml'}], 'filelists': [{'url': 'https://uln-qa.oracle.com/XMLRPC/GET-REQ/ol6_x86_64_latest/repodata/filelists.xml.gz', 'checksum': '2fb7fe60c7ee4dc948bbc083c18ab065384e990f', 'checksum_type': 'sha', 'file_name': 'repodata/filelists.xml.gz'}], 'updateinfo': [{'url': 'https://uln-qa.oracle.com/XMLRPC/GET-REQ/ol6_x86_64_latest/repodata/updateinfo.xml.gz', 'checksum': '15b889640ad35067d99b15973bb71aa1dc33ab00', 'checksum_type': 'sha', 'file_name': 'repodata/updateinfo.xml.gz'}], 'primary': [{'url': 'https://uln-qa.oracle.com/XMLRPC/GET-REQ/ol6_x86_64_latest/repodata/primary.xml.gz', 'checksum': '21f7115120c03a9dbaf25c6e1e9e3d6288bf664f', 'checksum_type': 'sha', 'file_name': 'repodata/primary.xml.gz'}], 'repomd': [{'url': 'https://uln-qa.oracle.com/XMLRPC/GET-REQ/ol6_x86_64_latest/repodata/repomd.xml', 'file_name': 'repodata/repomd.xml'}], 'other': [{'url': 'https://uln-qa.oracle.com/XMLRPC/GET-REQ/ol6_x86_64_latest/repodata/other.xml.gz', 'checksum': '30a176c8509677b588863bf21d7b196941e866af', 'checksum_type': 'sha', 'file_name': 'repodata/other.xml.gz'}]}}
Details for a given package : client.packages.getDetails(sessionKey, pid) returns packageDetail Example :
{'package_size': 5855337, 'package_arch_label': 'i686', 'package_cookie': '1307566435', 'package_md5sum': 'e74525b5bbaa9e637fe818f3f5777c02', 'package_name': 'subversion', 'package_summary': 'A Modern Concurrent Version Control System', 'package_epoch': ' ', 'package_checksums': [{'md5': 'e74525b5bbaa9e637fe818f3f5777c02'}], 'package_payload_size': 5857988, 'package_version': '1.6.11', 'package_license': 'ASL 1.1', 'package_vendor': 'Oracle America', 'package_release': '2.el6_1.4', 'package_last_modified_date': '2011-06-08 15:53:55', 'package_description': 'Subversion is a concurrent version control system which enables one\nor more users to collaborate in developing and maintaining a\nhierarchy of files and directories while keeping a history of all\nchanges. Subversion only stores the differences between versions,\ninstead of every complete file. Subversion is intended to be a\ncompelling replacement for CVS.', 'package_id': 2814035, 'providing_channels': ['ol6_x86_64_latest'], 'package_build_host': 'ca-build44.us.oracle.com', 'package_build_date': '2011-06-08 15:53:55', 'download_urls': ['https://uln-qa.oracle.com/XMLRPC/GET-REQ/ol6_x86_64_latest/subversion-1.6.11-2.el6_1.4.src.rpm'], 'package_file': 'subversion-1.6.11-2.el6_1.4.src.rpm'}
Logout : client.auth.logout(sessionKey) returns retval Logged out...

Sample code :
#!/usr/bin/env python
try:
    import os
    import sys
    import getpass
    import datetime
    import xmlrpclib

except ImportError, e:
    raise ImportError (str(e) + ': Module  not found')

SERVER_URL = 'https://uln-qa.oracle.com/rpc/api'

USERNAME = 'myusername@company.com'
PASSWORD = 'mypassword'

client = xmlrpclib.Server(SERVER_URL)


# login
print "Login : client.auth.login(username,password) returns sessionKey "
sessionKey = client.auth.login(USERNAME,PASSWORD)
if len(sessionKey) != 43:
   print "Invalid %d sessionKey : '%s'" % sessionKey
   exit(1)

print "Logged in..."

print ""
print ""
print ""


# list CVEs for an advisory
print "List CVEs for a particular advisory : client.errata.listCves(sessionKey, advisory)\
 returns cveList"
advisory = "ELSA-2013-1100"
cveList = client.errata.listCves(sessionKey, advisory)
print "Example : CVEs for advisory '%s' : %s" % (advisory, cveList)


print ""
print ""
print ""

# list channels for CVE
print "List channels applicable to advisory : \
client.errata.applicableToChannels(sessionKey, advisory) returns channelList"
channelList = client.errata.applicableToChannels(sessionKey, advisory)
print "Example : Channels applicable to advisory '%s' : %s" % (advisory, channelList)


print ""
print ""
print ""

# list latest packages in a channel
print "List latest packages in a given channel : \
client.channel.software.listLatestPackages(sessionKey, channelLabel) returns\
 packageList"
channelLabel= 'ol6_x86_64_latest'
packageList = client.channel.software.listLatestPackages(sessionKey, channelLabel)
print "Example : Packages for channel '%s' returns %d packages" %(channelLabel, 
 len(packageList))

print ""
print ""
print ""


# list errata in a channel
print "List errata in a given channel : \
client.channel.software.listErrata(sessionKey, channelLabel) returns errataList"
errataList = client.channel.software.listErrata(sessionKey, channelLabel)
print "Example : Errata in channel '%s' returns %d errata" %(channelLabel, len(errataList))

print ""
print ""
print ""

# list errata for a package with a specific id
print "List errata for a given package : client.packages.listProvidingErrata(sessionKey,
 pid) returns errataList"
pid = '2814035'
errataList = client.packages.listProvidingErrata(sessionKey, pid)
print "Example : \n%s\n" % errataList

print ""
print ""
print ""


# list software channels
print "List software channels available : client.channel.listSoftwareChannels(sessionKey)\
 returns channelList"
channelList = client.channel.listSoftwareChannels(sessionKey)
print "Example : List of channels returns '%d' channels" %(len(channelList))

print ""
print ""
print ""



# list all packages of a channel
print "List all packages for a given channel : \
client.channel.software.listAllPackages(sessionKey, channelLabel) returns packageList"
packageList = client.channel.software.listAllPackages(sessionKey, channelLabel)
print "Example : All packages for channel '%s' returns %d packages" %(channelLabel, 
len(packageList))

print ""
print ""
print ""


# list packages for an errata
print "List packages for a given advisory : client.errata.listPackages(sessionKey,
 advisory) returns packageList"
packageList = client.errata.listPackages(sessionKey, advisory)
print "Example : Packages for advisory '%s' returns %d packages" %(advisory, 
len(packageList))

print ""
print ""
print ""


# get errata details
print "Details for a specific advisory  : \
client.errata.getDetails(sessionKey, advisory) returns errataDetail"
errataDetail = client.errata.getDetails(sessionKey, advisory)
print "Example : \n%s\n" %errataDetail

print ""
print ""
print ""


# get channel details
print "Details for a given channel : \
client.channel.software.getDetails(sessionKey, channelLabel) returns channelDetail"
channelDetail = client.channel.software.getDetails(sessionKey, channelLabel)
print "Example : \n%s\n" % channelDetail

print ""
print ""
print ""


# get package details from package with an id
print "Details for a given package : client.packages.getDetails(sessionKey, pid) \
returns packageDetail"
packageDetail = client.packages.getDetails(sessionKey, pid)
print "Example : \n%s\n" % packageDetail

print ""
print ""
print ""


print "Logout : client.auth.logout(sessionKey) returns retval"
retval = client.auth.logout(sessionKey)
if retval == 1:
  print "Logged out..."
else:
  print "Failed to log out..."