Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Absent Member.. IS-WST-Deploy Absent Member..
Absent Member..
317 views

Learning how to use the API better

Jump to solution

In my environment I have to work with hundreds of servers at a time and have been trying to figure out how to utilize the OGFS/Web APIs better.    The documentation does not explain this philosphy well to learn how to search for a given patch policy or attach a given policy to this subset of servers that you have to remediate them.   The API has been very difficult to understand and follow to start solving the problems we have.

 

Where can I go to find more information/examples and explaination to develop what we need to have HPSA do?

 

We are using 10.01 as of today.

0 Likes
1 Solution

Accepted Solutions
A-M-2010 Absent Member.
Absent Member.

Re: Learning how to use the API better

Jump to solution

Hi. I am the doc representative for today's expert day. I will check with the other writers and see if we can provide you more information. If not, I will follow up with you to see if we can add a procedure to address your questions. Thanks!

0 Likes
6 Replies
Absent Member.. molinabro1 Absent Member..
Absent Member..

Re: Learning how to use the API better

Jump to solution
Hello! As a support person I need to ask the obvious to get it out o the way, have you checked over our SA developer guide? There is a ton of info in there for the kind of things you want to do.


Ed Molina
HP Cloud Solution Support Engineer

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution. Also, if you liked this post please consider providing Kudos on the left side.
0 Likes
Highlighted
Absent Member.. IS-WST-Deploy Absent Member..
Absent Member..

Re: Learning how to use the API better

Jump to solution

I have.   It is pretty sparse in explaining this.  It covers higher level things such as "We work on Services" yet nothing about how to make a call to that service in a consistent manner.   It is a bit obtuse.  I'd love to find more examples and perhaps something to explain between what a VO is versus not in a filter for example.   What is the difference and how do I know when to use SoftwarePolicyVO versus softwarePolicy as another example?

 

I'd like to find somwhere I can get more discussions and examples ideally.  

A-M-2010 Absent Member.
Absent Member.

Re: Learning how to use the API better

Jump to solution

Hi. I am the doc representative for today's expert day. I will check with the other writers and see if we can provide you more information. If not, I will follow up with you to see if we can add a procedure to address your questions. Thanks!

0 Likes
Absent Member.. IS-WST-Deploy Absent Member..
Absent Member..

Re: Learning how to use the API better

Jump to solution

Excellent.  I look forward to hearing from  you.  

0 Likes
Honored Contributor.. Dimiter Todorov Honored Contributor..
Honored Contributor..

Re: Learning how to use the API better

Jump to solution

I have found that playing around with the twister was extremely helpful in helping me understand how the API works.

 

 https://core:1032/twist/

 

Here is a sample script that attaches a Patch policy to a list of device groups.

This can either be executed in OGSH (Preferred)

Or executed on a server with an agent.

To execute on a server with agent, some ENV variables need to be set.

Normally, I run this for windows.

setlocal

set PATH=%SystemDrive%\Program Files\Opsware\agent\lcpython15;%SystemDrive%\Program Files\Opsware\agent\bin;%PATH%
set PYTHONPATH=%SystemDrive%\Program Files\Opsware\agent\pylibs

 

# Attach Patch Policies

import os
import re
import subprocess
import os
import sys
import getopt
import csv

from optparse import OptionParser


if (sys.platform == 'win32'):
    pytwist_dir = (os.environ['SystemDrive'] + '\\Program Files\\Opsware\\smopylibs2')
    pylibs_dir = (os.environ['SystemDrive'] + '\\Program Files\\Opsware\\agent\\pylibs')
    if os.path.isdir(pylibs_dir):
        pylibs_dir = (os.environ['SystemDrive'] + '\\Program Files\\Loudcloud\\Blackshadow')
        if os.path.isdir(pylibs_dir):
            raise 'The Opsware pylibs modules cannot be located'
else:
    pytwist_dir = '/opt/opsware/pylibs2'
    pylibs_dir = '/opt/opsware/agent/pylibs'
    if os.path.isdir(pylibs_dir):
        pylibs_dir = '/lc/blackshadow/coglib'
        if os.path.isdir(pylibs_dir):
            raise 'The Opsware pylibs modules cannot be located'
sys.path.append(pylibs_dir)
sys.path.append(pytwist_dir)
from pytwist import *
from pytwist.com.opsware.search import Filter
from pytwist.com.opsware.server import *
from pytwist.com.opsware.device import *
from pytwist.com.opsware.swmgmt import *
ts = twistserver.TwistServer()

if (__name__ == '__main__'):
    parser = OptionParser(description=__doc__, version="0.0.1",
                          usage='%prog [--user username --password password]')
    parser.add_option("-u", "--user", action="store", dest="username", metavar="username", default="",
                      help="User Name")
    parser.add_option("-p", "--password", action="store", dest="password", metavar="password", default="",
                      help="Password")

    try:
        (opts, args) = parser.parse_args(sys.argv[1:])
    except getopt.GetoptError:
        parser.print_help()
        sys.exit(2)
    if opts.username and opts.password:
        ts.authenticate(opts.username,opts.password)
    else:
        print "Username and Password not provided. Script may fail unless running in OGSH"


    device_groups="98410001 218340001 97420001 98390001 186750001 186710001 186700001 191200001 186730001 186740001 186720001 191210001 186770001 98380001 96980001 98370001 97370001 96990001".split()
    patch_policy_filter="Update Rollup January 2014"
    out_dict=[]
    count = 0
    for device_group in device_groups:
        policy_filter=Filter()
        policy_filter.objectType="patch_policy"
        policy_filter.expression="(PatchPolicyVO.name CONTAINS \"%s\")" % patch_policy_filter
        policy_refs=ts.swmgmt.WindowsPatchPolicyService.findWindowsPatchPolicyRefs(policy_filter)
        dgref=DeviceGroupRef(device_group)
        ts.swmgmt.WindowsPatchPolicyService.attachToPolicies(policy_refs,[dgref])


 

 

0 Likes
A-M-2010 Absent Member.
Absent Member.

Re: Learning how to use the API better

Jump to solution

Hi.

You can use the following URL to access API documentation:

 https://<SA_core_host>/twister  

where  <SA_core_host> is the IP address or host name of the SA core server running the Command Center component.

Once you access this URL, you will see basic descriptions of API calls and how to use them. You can also enter parameters, and conduct test runs to see the results of the call.

 

You can also check page 21 of the SA 10.0 Platform Developers Guide, "API Documentation and the Twister.”

 

The SA IE (Documentation) team hopes this information answers your API questions. I am still working on the answers to the software-management questions, and will get back to you as soon as I can. Please do not hesitate to contact us with more documentation questions, or documentation feedback, at:  sa-docs@hp.com.

 

If you would like to participate in our customer survey, or help us put together customer FAQs, please contact us.

 

Thank you! Talk to you soon.

SA IE (Documentation) Team

 

p.s. I just noticed someone has sent a similar answer. Hopefully both answers will address your question.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.