|
| 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