-
Notifications
You must be signed in to change notification settings - Fork 3
/
tower_diagnose_job
executable file
·51 lines (40 loc) · 1.56 KB
/
tower_diagnose_job
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Import required python modules
import requests,json,getpass
import os
import ConfigParser
import re
#Disabling InsecureRequestWarnings in python requests module
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def tower_job(url, user, passwd, job_id):
"""This function returns the
api endpoint for a given job_id and store the output
in a text file"""
try:
req = requests.get(url + '/api/v2/jobs/' + job_id, auth=(user, passwd), verify=False)
res = req.json()
execution_node = res['execution_node']
u = re.sub(r'https://', '', url)
if execution_node != u:
link = 'https://' + execution_node
req = requests.get(link + '/api/v2/jobs/' + job_id, auth=(user, passwd), verify=False)
results = str(json.dumps(req.json(), sort_keys=True, indent=4))
write(results, job_id)
except Exception as error:
print('Unable to get job ' + job_id + ' due to error: {0}'.format(error))
def write(results, job_id):
f = open('job_' + job_id + '.txt','w')
f.write(results)
f.close()
if __name__ == '__main__':
#Read Config
config = ConfigParser.SafeConfigParser()
config.read('config.ini')
url = config.get('tower', 'url')
user = config.get('tower', 'username')
passwd = config.get('tower', 'password')
job_id = raw_input('Enter the job ID : ')
# calling tower_ping function
tower_job(url, user, passwd, job_id)