Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get a list of patches contained in a Patch Policy in HPSA -- I can get what I need via the Twister web interface (under PatchPolicy.getPatches(), give it an ID, and it happily returns a list of patches contained.) -- I'm having a hard time getting this to work via the Pytwist interface, though... I haven't used the Pytwist interface for much besides some very basic Device manipulation, and Python is.. not my forte. I create the TwistServer object, then a PatchPolicy object from that (which I think is working..), but can't figure out how/where to call the getPatches() method from in Python-land.

If there's a way to dig this out of the database itself, that would work, too, but I can't seem to find much in there along these lines besides the vendor-recommended patching stuff, and we use custom policies.

share|improve this question

the full Twister documentation is available in javadoc form at http://<sa.core.address>:1032/twister

If you have some sample PyTwist scripts, modifying one to meet these demands should be pretty straight-forward :)

Can you post the code you have, and perhaps we can work with you to make some headway?

share|improve this answer

Should be as simple as: service = ts.this should be the Package from the web interface that you found getPatches()

vo = service.getPatches(ref)
share|improve this answer

I stripped down a '' script we created awhile back, there may be a few extra not needed lines in this script, but it works to print patch information of patches in a patch policy:


import sys
import types

from pytwist import *

TWISTHOST = "localhost"
patchPolicyName = 'IAVA Patch Policy for 2008 R2 Servers (64bit)'

def fetchAttr(objectZed, strAttr):
    listFilterStrings = ["|", "\r", "\n"]
    if "." in strAttr:
            (parentAttr, childAttr) = strAttr.split(".", 1)
            parentReturn = getattr(objectZed, parentAttr)
            attrReturn = fetchAttr(parentReturn, childAttr)
            if objectZed:
                    attrReturn = getattr(objectZed, strAttr)
                    attrReturn = objectZed
    if attrReturn is None:
        attrReturn = ''
    if attrReturn is True:
        attrReturn = 'True'
    if attrReturn is False:
        attrReturn = 'False'
    if type(attrReturn) == types.InstanceType and dir(attrReturn) != []:
            if "id" and "idAsLong" and "name" in dir(attrReturn):
                    attrReturn =
    if type(attrReturn) == types.StringType:
            for filterStr in listFilterStrings:
                    attrReturn = attrReturn.replace(filterStr, "")
    return str(attrReturn)

def walkAttrs(objectZed, listAttrs):
    used to return a list with the results for a list of given attributes
    return [fetchAttr(objectZed, strAttr) for strAttr in listAttrs]

def getPatchesFromPatchPolicy(policyName=None):
    used to fetch list of VO's for every patch attached to a given patch policy
    myFilter =
    if policyName:
        myFilter.expression = '{ = "%s"}' % (policyName)
    ppservice = ts.swmgmt.PatchPolicyService
    listPatchPolicyRefs = ppservice.findPatchPolicyRefs(myFilter)

    if len(listPatchPolicyRefs) == 0:
            print "Policy '%s' not found in HP SA!" % (policyName)

    if len(listPatchPolicyRefs) > 1:
            print "Duplicate patch policy '%s' in HP SA!" % (policyName)
    patchPolicyVO = ppservice.getPatchPolicyVO(listPatchPolicyRefs[0])
    listPatchRefs = ppservice.getPatches(listPatchPolicyRefs)
    listPatchVOs = ts.pkg.UnitService.getUnitVOs(listPatchRefs)

    return (patchPolicyVO, listPatchVOs)

def getHotfixInfo(listHotfixVOs):
    listHotfixes = []
    for hotfixVO in listHotfixVOs:
        dictHotfixInfo = walkAttrs(hotfixVO, listPatchAttrs)
        if (dictHotfixInfo in listHotfixes) and warnDupes:
            print "!!!DUPLICATE FOUND: %s" % (dictHotfixInfo)

    return listHotfixes

ts = twistserver.TwistServer(TWISTHOST)

listPatchAttrs = [
    "name", "platform", "softwareRelease", "version", "updateId",
    "location", "downloadUrl", "fileName", "metadataSource",
    "createdBy", "checksum", "patchStatus"]

    (patchPolicyVO, listHotfixVOs) = getPatchesFromPatchPolicy(patchPolicyName)
    listHotfixes = getHotfixInfo(listHotfixVOs)
    for entry in listHotfixes:
        print entry
    print "Something Didn't Work"

Sample Output:

['Q2679255', 'Windows Server 2008 R2 x64', '7382edbe-0388-40a1-ab7d-9d05cddf309e', '2', 'com.hp.hpln.mps.ba19383f1c49358d0fedc18fcdcf7841', '/packages/any/nt/6.1-X64/Windows6.1-KB2679255-v2-x64.msu', '', 'Windows6.1-KB2679255-v2-x64.msu', 'OPSWWPDB-2012.4.10', 'opswpatch import', 'bebd9119d6887e045856564452d97957155e3588', 'AVAILABLE']
['Q2703157', 'Windows Server 2008 R2 x64', 'fe9db004-9d38-4a7c-9658-f606a1ec149b', '2', 'com.hp.hpln.mps.cc00efa894ba1504262cf961e126713f', '/packages/any/nt/6.1-X64/Windows6.1-KB2703157-x64.msu', '', 'Windows6.1-KB2703157-x64.msu', 'OPSWWPDB-2012.6.12', 'opswpatch import', '4ac0ca0bb05b86cd7aac155598a05a003132fad6', 'AVAILABLE']
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.