Created
September 1, 2023 13:21
-
-
Save recklessop/e7f128d173c148f76119daf62d8e7f9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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