Unable to retrieve jobs through Rundeck API using Python -
i'm exploring rundeck api return list of jobs. manually creatd 2 jobs through ui. however, ended getting 0 jobs through api. i'm having hard time figure out what's going on in process.
below code example:
import urllib2 import logging import ssl rundeck_token = 'my_api_token' class rundeck(): def get_full_url(self): return 'https://rdurl:8443/rundeckpro/api/14/project/sandbox/jobs?authtoken=' + rundeck_token def make_api_call(self): context = ssl._create_unverified_context() opener = urllib2.build_opener(urllib2.httpshandler(context=context)) request = urllib2.request(self.get_full_url()) try: return opener.open(request, timeout=30) except urllib2.httperror err: if err.code == 409: return 'running' except exception e: logging.error('exception : %s', e) return false if __name__ == '__main__': jobs = rundeck() print jobs.get_full_url() print jobs.make_api_call().read()
the output is:
<jobs count='0' />
thanks helps.
your script works perfect fine me.
check rundeck acl, api key owner may not have read access jobs created.
test output:
tmp $ python test.py http://localhost:4440/api/14/project/testproject/jobs?authtoken=oyfxx1q4uzhtue7deouipjkkrunewzlo <jobs count='3'> <job id='63385df9-8898-48e9-ae8a-047b548915cd' href='http://localhost:4440/api/18/job/63385df9-8898-48e9-ae8a-047b548915cd' permalink='http://localhost:4440/project/testproject/job/show/63385df9-8898-48e9-ae8a-047b548915cd'> <name>test</name> <group /> <project>testproject</project> <description></description> </job> <job id='02a41aaa-eb50-4831-8762-80b798468cbe' href='http://localhost:4440/api/18/job/02a41aaa-eb50-4831-8762-80b798468cbe' permalink='http://localhost:4440/project/testproject/job/show/02a41aaa-eb50-4831-8762-80b798468cbe'> <name>testjob</name> <group /> <project>testproject</project> <description>testjob description</description> </job> <job id='9b2ac9e9-0350-4494-a463-b43ba1e458ab' href='http://localhost:4440/api/18/job/9b2ac9e9-0350-4494-a463-b43ba1e458ab' permalink='http://localhost:4440/project/testproject/job/show/9b2ac9e9-0350-4494-a463-b43ba1e458ab'> <name>testjob2</name> <group /> <project>testproject</project> <description></description> </job> </jobs>
Comments
Post a Comment