-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathconfig.py
More file actions
74 lines (48 loc) · 2.86 KB
/
config.py
File metadata and controls
74 lines (48 loc) · 2.86 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import requests
content_type = "application/vnd.netbackup+json; version=4.0"
def perform_login(username, password, base_url, domain_name, domain_type):
url = base_url + "/login"
if domain_name != "" and domain_type != "":
req_body = {"userName": username, "password": password, "domainName": domain_name, "domainType": domain_type}
else:
req_body = {"userName": username, "password": password}
headers = {'Content-Type': content_type}
print("performing POST on {} for user '{}'\n".format(url, req_body['userName']))
resp = requests.post(url, headers=headers, json=req_body, verify=False)
if resp.status_code != 201:
raise Exception('Login API failed with status code {} and {}'.format(resp.status_code, resp.json()))
return resp.json()['token']
def get_trusted_master_server_by_name(jwt, base_url, trustedmasterservername):
url = base_url + "/config/servers/trusted-master-servers/" + trustedmasterservername
headers = {'Content-Type': content_type, 'Authorization': jwt}
query_params = {
# "page[limit]": 100, #This changes the default page size to 100
# "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs
}
print("performing GET on {}\n".format(url))
resp = requests.get(url, headers=headers, params=query_params, verify=False)
if resp.status_code != 200:
raise Exception('GET Trusted master server with specific name failed with status code {} and {}'.format(resp.status_code, resp.json()))
return resp.json()
def delete_trust(jwt, base_url, trustedmasterservername):
url = base_url + "/config/servers/trusted-master-servers/" +trustedmasterservername
headers = {'Content-Type': content_type, 'Authorization': jwt}
query_params = {
# "page[limit]": 100, #This changes the default page size to 100
# "filter": "jobType eq 'RESTORE'" #This adds a filter to only show RESTORE Jobs
}
print("performing DELETE on {}\n".format(url))
resp = requests.delete(url, headers=headers, verify=False)
if resp.status_code != 204:
raise Exception('DELETE trust with specific trusted master failed with status code {} and {}'.format(resp.status_code, resp.json()))
print("\nThe Trust is deleted with status code: {}\n".format(resp.status_code))
def create_trusted_master_server(jwt, base_url, file_name):
url = base_url + "/config/servers/trusted-master-servers"
headers = {'Content-Type': content_type, 'Authorization': jwt}
path = file_name
req_body = open(path, 'r').read()
print("performing POST on {}\n".format(url))
resp = requests.post(url, headers=headers, data=req_body, verify=False)
if resp.status_code != 201:
raise Exception('Create trust between master servers API failed with status code {} and {}'.format(resp.status_code, resp.json()))
return resp.json()