Skip to content

Commit 54b79fe

Browse files
authored
Merge pull request #15 from VeritasOS/feature/sample-api-policy-python
Feature/sample api policy python
2 parents 723c5a9 + 403e1bf commit 54b79fe

File tree

6 files changed

+946
-0
lines changed

6 files changed

+946
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@ These scripts are only meant to be used as a reference. Please do not use these
1010
The `snippets` folder contains code samples to invoke NetBackup REST API using different programming languages.
1111

1212
Pre-requisites:
13+
1314
- NetBackup 8.1.1 or higher
1415
- See the script's README for the corresponding requirements and usage
1516

17+
#### Executing the recipes in Python
18+
19+
Pre-requisites:
20+
- NetBackup 8.1.2 or higher
21+
- python 3.5 or higher
22+
- python modules: `requests`
23+
24+
Use the following commands to run the python samples.
25+
- `python -W ignore create_policy_step_by_step.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
26+
- `python -W ignore create_policy_in_one_step.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
27+
- `python -W ignore rbac_filtering_in_policy.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
28+
1629
#### Tools
1730
The `tools` folder contains utilities that have proven useful in the development of projects using
1831
NetBackup REST APIs, but do not provide any API usage examples. Again, these tools are not for
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import sys
2+
import policy_api_requests
3+
import json
4+
5+
protocol = "https"
6+
nbmaster = ""
7+
username = ""
8+
password = ""
9+
domainName = ""
10+
domainType = ""
11+
port = 1556
12+
13+
def print_disclaimer():
14+
print("-------------------------------------------------------------------------------------------------")
15+
print("-- This script requires Python3.5 or higher. --")
16+
print("-- If your current system does not have Python3.5 or higher installed, this will not work. --")
17+
print("-------------------------------------------------------------------------------------------------\n")
18+
print("Executing this library requires some additional python3.5 libraries like \n\t'requests'.\n\n")
19+
print("You will, however, require 'requests' library to make the API calls.\n")
20+
print("You can install the dependent libraries using the following commands: ")
21+
print("pip install requests")
22+
print("-------------------------------------------------------------------------------------------------\n\n\n")
23+
print("You can specify the 'nbmaster', 'username', 'password', 'domainName' and 'domainType' as command-line parameters\n")
24+
print_usage()
25+
26+
def print_usage():
27+
print("Example:")
28+
print("python -W ignore create_policy_in_one_step.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]\n\n\n")
29+
30+
def read_command_line_arguments():
31+
if len(sys.argv)%2 == 0:
32+
print_usage()
33+
exit()
34+
35+
global nbmaster
36+
global username
37+
global password
38+
global domainName
39+
global domainType
40+
41+
for i in range(1, len(sys.argv), 2):
42+
if sys.argv[i] == "-nbmaster":
43+
nbmaster = sys.argv[i + 1]
44+
elif sys.argv[i] == "-username":
45+
username = sys.argv[i + 1]
46+
elif sys.argv[i] == "-password":
47+
password = sys.argv[i + 1]
48+
elif sys.argv[i] == "-domainName":
49+
domainName = sys.argv[i + 1]
50+
elif sys.argv[i] == "-domainType":
51+
domainType = sys.argv[i + 1]
52+
else:
53+
print_usage()
54+
exit()
55+
56+
if nbmaster == "":
57+
print("Please provide the value for 'nbmaster'")
58+
exit()
59+
elif username == "":
60+
print("Please provide the value for 'username'")
61+
exit()
62+
elif password == "":
63+
print("Please provide the value for 'password'")
64+
exit()
65+
elif domainName == "":
66+
print("Please provide the value for 'domainName'")
67+
exit()
68+
elif domainType == "":
69+
print("Please provide the value for 'domainType'")
70+
exit()
71+
72+
print_disclaimer()
73+
74+
read_command_line_arguments()
75+
76+
base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup"
77+
78+
jwt = policy_api_requests.perform_login(username, password, domainName, domainType, base_url)
79+
80+
policy_api_requests.post_netbackup_VMwarePolicy(jwt, base_url)
81+
82+
policy_api_requests.get_netbackup_policies(jwt, base_url)
83+
84+
policy_api_requests.get_netbackup_policy(jwt, base_url)
85+
86+
policy_api_requests.put_netbackup_policy(jwt, base_url)
87+
88+
policy_api_requests.get_netbackup_policy(jwt, base_url)
89+
90+
policy_api_requests.delete_VMware_netbackup_policy(jwt, base_url)
91+
92+
policy_api_requests.get_netbackup_policies(jwt, base_url)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import sys
2+
import policy_api_requests
3+
import json
4+
5+
protocol = "https"
6+
nbmaster = ""
7+
username = ""
8+
password = ""
9+
domainName = ""
10+
domainType = ""
11+
port = 1556
12+
13+
def print_disclaimer():
14+
print("-------------------------------------------------------------------------------------------------")
15+
print("-- This script requires Python3.5 or higher. --")
16+
print("-- If your current system does not have Python3.5 or higher installed, this will not work. --")
17+
print("-------------------------------------------------------------------------------------------------\n")
18+
print("Executing this library requires some additional python3.5 libraries like \n\t'requests'.\n\n")
19+
print("You will, however, require 'requests' library to make the API calls.\n")
20+
print("You can install the dependent libraries using the following commands: ")
21+
print("pip install requests ")
22+
print("-------------------------------------------------------------------------------------------------\n\n\n")
23+
print("You can specify the 'nbmaster', 'username', 'password', 'domainName' and 'domainType' as command-line parameters\n")
24+
print_usage()
25+
26+
def print_usage():
27+
print("Example:")
28+
print("python -W ignore create_policy_step_by_step.py -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]\n\n\n")
29+
30+
def read_command_line_arguments():
31+
if len(sys.argv)%2 == 0:
32+
print_usage()
33+
exit()
34+
35+
global nbmaster
36+
global username
37+
global password
38+
global domainName
39+
global domainType
40+
41+
for i in range(1, len(sys.argv), 2):
42+
if sys.argv[i] == "-nbmaster":
43+
nbmaster = sys.argv[i + 1]
44+
elif sys.argv[i] == "-username":
45+
username = sys.argv[i + 1]
46+
elif sys.argv[i] == "-password":
47+
password = sys.argv[i + 1]
48+
elif sys.argv[i] == "-domainName":
49+
domainName = sys.argv[i + 1]
50+
elif sys.argv[i] == "-domainType":
51+
domainType = sys.argv[i + 1]
52+
else:
53+
print_usage()
54+
exit()
55+
56+
if nbmaster == "":
57+
print("Please provide the value for 'nbmaster'")
58+
exit()
59+
elif username == "":
60+
print("Please provide the value for 'username'")
61+
exit()
62+
elif password == "":
63+
print("Please provide the value for 'password'")
64+
exit()
65+
elif domainName == "":
66+
print("Please provide the value for 'domainName'")
67+
exit()
68+
elif domainType == "":
69+
print("Please provide the value for 'domainType'")
70+
exit()
71+
72+
print_disclaimer()
73+
74+
read_command_line_arguments()
75+
76+
base_url = protocol + "://" + nbmaster + ":" + str(port) + "/netbackup"
77+
78+
jwt = policy_api_requests.perform_login(username, password, domainName, domainType, base_url)
79+
80+
policy_api_requests.post_netbackup_VMwarePolicy_defaults(jwt, base_url)
81+
82+
policy_api_requests.get_netbackup_policies(jwt, base_url)
83+
84+
policy_api_requests.get_netbackup_policy(jwt, base_url)
85+
86+
policy_api_requests.put_netbackup_policy(jwt, base_url)
87+
88+
policy_api_requests.put_netbackup_client(jwt, base_url)
89+
90+
policy_api_requests.put_netbackup_backupselections(jwt, base_url)
91+
92+
policy_api_requests.put_netbackup_schedule(jwt, base_url)
93+
94+
policy_api_requests.get_netbackup_policy(jwt, base_url)
95+
96+
policy_api_requests.delete_netbackup_client(jwt, base_url)
97+
98+
policy_api_requests.delete_netbackup_schedule(jwt, base_url)
99+
100+
policy_api_requests.delete_VMware_netbackup_policy(jwt, base_url)
101+
102+
policy_api_requests.get_netbackup_policies(jwt, base_url)

0 commit comments

Comments
 (0)