Skip to content

Instantly share code, notes, and snippets.

@netmanchris
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netmanchris/e0c574b1d5ba37cc3a66 to your computer and use it in GitHub Desktop.
Save netmanchris/e0c574b1d5ba37cc3a66 to your computer and use it in GitHub Desktop.
def imc_creds():
''' This function prompts user for IMC server information and credentials and stores
values in url and auth global variables'''
global url, auth, r
imc_protocol = input(
"What protocol would you like to use to connect to the IMC server: \n Press 1 for HTTP: \n Press 2 for HTTPS:")
if imc_protocol == "1":
h_url = 'http://'
else:
h_url = 'https://'
imc_server = input("What is the ip address of the IMC server?")
imc_port = input("What is the port number of the IMC server?")
imc_user = input("What is the username of the IMC eAPI user?")
imc_pw = input('''What is the password of the IMC eAPI user?''')
url = h_url + imc_server + ":" + imc_port
auth = requests.auth.HTTPDigestAuth(imc_user, imc_pw)
test_url = '/imcrs'
f_url = url + test_url
try:
r = requests.get(f_url, auth=auth, headers=headers)
# checks for requests exceptions
except requests.exceptions.RequestException as e:
print("Error:\n" + str(e))
print("\n\nThe IMC server address is invalid. Please try again\n\n")
imc_creds()
if r.status_code != 200: # checks for valid IMC credentials
print("Error: \n You're credentials are invalid. Please try again\n\n")
imc_creds()
else:
print("You've successfully access the IMC eAPI")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment