获取 HPSA 补丁策略中的补丁列表

获取 HPSA 补丁策略中的补丁列表

我正在尝试获取 HPSA 中补丁策略中包含的补丁列表 - 我可以通过 Twister Web 界面获取我需要的内容(在 PatchPolicy.getPatches() 下,给它一个 ID,它会很乐意返回包含的补丁列表。)- 但是,我很难通过 Pytwist 界面让它工作...除了一些非常基本的设备操作之外,我没有使用过 Pytwist 界面,而且 Python 不是我的强项。我创建了 TwistServer 对象,然后从中创建了一个 PatchPolicy 对象(我认为它正在工作......),但不知道如何/在哪里调用 getPatches() 方法在 Python 领域。

如果有办法从数据库本身中挖掘出它,那么它也可以起作用,但是除了供应商推荐的修补内容之外,我似乎找不到太多这样的内容,而且我们使用自定义策略。

答案1

完整的扭转者文档以 javadoc 形式提供于http://<sa.core.address>:1032/twister

如果你有一些 PyTwist 示例脚本,可以修改其中一个以满足这些要求应该非常直接:)

您能发布您拥有的代码吗?也许我们可以与您合作以取得一些进展?

答案2

应该简单如:service = ts。这应该是您在 Web 界面找到的包 getPatches()

vo = service.getPatches(ref)

答案3

我精简了我们之前创建的“PatchPolicy_2_CSV.py”脚本,这个脚本中可能有几行不需要的额外代码,但它可以打印补丁策略中补丁的补丁信息:

#!/opt/opsware/bin/python2
#####
# list_pp_contents.py
# http://www.augustschell.com
#####

import sys
import types

sys.path.append("/opt/opsware/pylibs2")
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)
    else:
            if objectZed:
                    attrReturn = getattr(objectZed, strAttr)
            else:
                    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 = attrReturn.name
    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 = com.opsware.search.Filter()
    if policyName:
        myFilter.expression = '{PatchPolicyVO.name = "%s"}' % (policyName)
    ppservice = ts.swmgmt.PatchPolicyService
    listPatchPolicyRefs = ppservice.findPatchPolicyRefs(myFilter)

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

    if len(listPatchPolicyRefs) > 1:
            print "Duplicate patch policy '%s' in HP SA!" % (policyName)
            sys.exit(4)
    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)
        listHotfixes.append(dictHotfixInfo)

    return listHotfixes


ts = twistserver.TwistServer(TWISTHOST)

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

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

示例输出:

['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', 'http://download.microsoft.com/download/6/6/B/66B6D917-1CF1-4F97-A13A-1FF9C7F4FBED/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', 'http://download.microsoft.com/download/6/E/1/6E1C23D9-45CF-42B3-AD4E-1E6A3E0CC32E/Windows6.1-KB2703157-x64.msu', 'Windows6.1-KB2703157-x64.msu', 'OPSWWPDB-2012.6.12', 'opswpatch import', '4ac0ca0bb05b86cd7aac155598a05a003132fad6', 'AVAILABLE']

相关内容