To write a Python program to query a Hitachi G5000 storage array and return allocated storage for each host, you'll need to use the Hitachi Command Suite (HCS) REST API, which allows you to interact with the storage system programmatically. Here's a basic example using the requests library to get you started:
Before you start, you'll need to install the requests library if you haven't already:
pip install requests
Now, you can create a Python script to query the storage array:
import requests
import json
# Replace these with your storage array's credentials and IP address
HCS_USERNAME = "your_username"
HCS_PASSWORD = "your_password"
HCS_IP_ADDRESS = "your_storage_array_ip"
# API endpoint for Hitachi G5000 storage array
BASE_URL = f"https://{HCS_IP_ADDRESS}/ConfigurationManager/v1"
# Function to authenticate and get API token
def authenticate(username, password):
url = f"{BASE_URL}/sessions"
headers = {
"Content-Type": "application/json"
}
data = {
"name": username,
"password": password
}
response = requests.post(url, headers=headers, json=data, verify=False)
if response.status_code == 201:
return response.json()["token"]
else:
raise Exception(f"Authentication failed with status code {response.status_code}")
# Function to get allocated storage for each host
def get_allocated_storage(token):
url = f"{BASE_URL}/hosts"
headers = {
"Content-Type": "application/json",
"Authorization": f"Basic {token}"
}
response = requests.get(url, headers=headers, verify=False)
if response.status_code == 200:
hosts = response.json()["data"]
for host in hosts:
print(f"Host ID: {host['hostID']}, Host Name: {host['name']}, Allocated Storage: {host['allocatedCapacity']}")
else:
raise Exception(f"Failed to retrieve hosts with status code {response.status_code}")
if __name__ == "__main__":
token = authenticate(HCS_USERNAME, HCS_PASSWORD)
get_allocated_storage(token)
Please note that this example disables SSL certificate verification (verify=False) for simplicity. In a production environment, you should properly configure SSL certificates and enable verification.
Replace the placeholders (your_username, your_password, and your_storage_array_ip) with your actual HCS credentials and storage array IP address. Running this script will authenticate against the HCS API and then retrieve and print the allocated storage for each host.