Skip to content

Instantly share code, notes, and snippets.

@recklessop
Created September 1, 2023 13:21
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 recklessop/e7f128d173c148f76119daf62d8e7f9e to your computer and use it in GitHub Desktop.
Save recklessop/e7f128d173c148f76119daf62d8e7f9e to your computer and use it in GitHub Desktop.
import requests
base_server = "192.168.50.60"
keycloak_base_url = f"https://{base_server}/auth" # Replace with your Keycloak server URL
zvm_api_url = f"https://{base_server}/v1"
realm = "zerto" # Replace with your Keycloak realm name
client_id = "zerto-client" # Replace with your Keycloak client ID
username = "admin"
password = "Zertodata987!"
token_url = f"{keycloak_base_url}/realms/{realm}/protocol/openid-connect/token"
# Define the data to be sent in the request
data = {
"grant_type": "password",
"client_id": client_id,
"username": username,
"password": password,
}
# Make a POST request to the token URL with the data
response = requests.post(token_url, data=data, verify=False)
# Check if the request was successful (HTTP status code 200)
if response.status_code == 200:
# Parse the response JSON to get the access token
access_token = response.json()["access_token"]
#print("Authentication successful. Access token:", access_token)
else:
print("Authentication failed. Status code:", response.status_code)
print("Error message:", response.text)
uri = zvm_api_url + "/vpgs"
headers = {
"Authorization": f"Bearer {access_token}",
"accept": "application/json"
}
# Make a POST request to the token URL with the data headers=headers,
response = requests.get(uri, headers=headers, verify=False)
# Check if the request was successful (HTTP status code 200)
if response.status_code == 200:
# Parse the response JSON to get the access token
print(response.text)
else:
print("Status code:", response.status_code)
print("Error message:", response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment