-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python Scripts for Using Netbackup Access Hosts APIs #45
base: master
Are you sure you want to change the base?
Conversation
ismareth
commented
Oct 29, 2019
- Added 2 py files as python scripts for Access Hosts APIs
- Modified the Readme.md file accordingly to reflect the usage and the new additions.
#### Executing the script | ||
|
||
Pre-requisites: | ||
####Pre-requisites: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Missing space between '#' and 'Pre-requisites'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, prerequisites shouldn't be hyphenated. It's just an ordinary word.
####Usage | ||
|
||
#####NetBackup Hosts Configuration Management API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Missing space between '#' and the heading
Use the following command to run the script. The command should be run from the parent directory of this 'config' directory. | ||
|
||
`python -W ignore -m config.hosts_exclude_list -hostName <hostName> -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]` | ||
|
||
`Note: hostName is the name of the NetBackup host to set the exclude configuration. The exclude list is specified in the config/exclude_list file.` | ||
|
||
#####NetBackup Access Hosts API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Missing space between '#' and the heading
|
||
`python -W ignore -m config.access_hosts_api_usecases -hostName <hostName> -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]` | ||
|
||
`Note: hostName is the name of the VMware Access host to add/delete using the Access Host APIs.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why specifically mention VMware Access Host?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the comments.
Everything else looks good.
#### Executing the script | ||
|
||
Pre-requisites: | ||
####Pre-requisites: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, prerequisites shouldn't be hyphenated. It's just an ordinary word.
headers = {'Content-Type': content_type_header, 'Authorization': jwt} | ||
long_url = base_url + vmware_access_hosts_url + hostName | ||
response = requests.delete(long_url, headers=headers, verify=False) | ||
return response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include newlines at the ends of the text files.
def add_access_host(base_url, jwt, hostName): | ||
headers = {'Content-Type': content_type_header, 'Authorization': jwt} | ||
long_url = base_url + vmware_access_hosts_url | ||
data = {'data':{'type':'accessHostRequest', 'id':'vmware', 'attributes':{'hostname':hostName, 'validate': 'false'}}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the validate
field really supposed to have the string value "false"
and not the Boolean value False
?
#####NetBackup Access Hosts API | ||
Use the following command to run the script. The command should be run from the parent directory of this 'config' directory. | ||
|
||
`python -W ignore -m config.access_hosts_api_usecases -hostName <hostName> -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What warnings need to be ignored in this script? Why not fix the warnings?
print("-- This script requires Python3.5 or higher. --") | ||
print("-- The system where this script is run should have Python 3.5 or higher version installed. --") | ||
print("-------------------------------------------------------------------------------------------------") | ||
print("The script requires 'requests' library to make the API calls.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pointless to mention this at run time. If you have the module, then the command will run and you don't need to be reminded that you need a module you already have. If you don't have the module, then the script won't even run, so this line of code wouldn't run anyway.
hostName = "test_vmwareAccessHost123" | ||
|
||
def parse_access_host_response(response): | ||
global nbmaster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global
is only necessary when assigning to a variable from a different code block. This function only uses nbmaster
.
i = 0; | ||
for host in response.json()["data"]: | ||
i = i+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to keep track of i
separately. That's what enumerate
is for.
i = 0; | |
for host in response.json()["data"]: | |
i = i+1 | |
for i, host in enumerate(response.json()["data"], 1): |
print("-------------------------------------------------------------------------------------------------") | ||
|
||
def read_command_line_arguments(): | ||
if len(sys.argv)%2 == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use argparse
for processing command-line arguments.