This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
49 lines (38 loc) · 1.3 KB
/
util.py
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
from __future__ import print_function
import os
import sys
import requests
import json
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
#from tests.fake import fake, fake_post
#FAKE=True
FAKE=False
from dnac import get_auth_token, create_url, wait_on_task
def get_url(url):
if FAKE:
return fake[url]
url = create_url(path=url)
print(url)
token = get_auth_token()
headers = {'X-auth-token' : token['token']}
try:
response = requests.get(url, headers=headers, verify=False)
except requests.exceptions.RequestException as cerror:
print("Error processing request", cerror)
sys.exit(1)
return response.json()
def post_and_wait(url, data):
if FAKE:
return fake_post[url]
token = get_auth_token()
url = create_url(path=url)
headers= { 'x-auth-token': token['token'], 'content-type' : 'application/json'}
try:
response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
except requests.exceptions.RequestException as cerror:
print ("Error processing request", cerror)
sys.exit(1)
taskid = response.json()['response']['taskId']
print ("Waiting for Task %s" % taskid)
task_result = wait_on_task(taskid, token)
return task_result