티스토리 뷰

IA/System Admin

qumulo with python 2

kiostory 2023. 8. 21. 14:56
#first, Install the requests library if you haven't already:
pip install requests

#Import the necessary libraries:
import requests
import json

#Set up the Qumulo API endpoint and authentication:
api_endpoint = ["https://<qumulo_cluster_ip>/v1"]("https://<qumulo_cluster_ip>/v1")
username = "<username>"
password = "<password>"

#Define a function to make API requests:
def make_api_request(url, method="GET", data=None):
    headers = {"Content-Type": "application/json"}
    auth = (username, password)

    if method == "GET":
        response = requests.get(url, headers=headers, auth=auth)
    elif method == "POST":
        response = requests.post(url, headers=headers, auth=auth, data=json.dumps(data))
    elif method == "PUT":
        response = requests.put(url, headers=headers, auth=auth, data=json.dumps(data))
    elif method == "DELETE":
        response = requests.delete(url, headers=headers, auth=auth)

    return response.json()

#Use the make_api_request function to query Qumulo:
# Example: Get the list of all files in a directory
directory_id = "<directory_id>"
url = f"{api_endpoint}/directory/{directory_id}/entries"
response = make_api_request(url)

# Example: Get the capacity usage of the cluster
url = f"{api_endpoint}/cluster"
response = make_api_request(url)

# Example: Create a new directory
parent_directory_id = "<parent_directory_id>"
new_directory_name = "<new_directory_name>"
url = f"{api_endpoint}/directory/{parent_directory_id}/entries"
data = {"name": new_directory_name, "type": "directory"}
response = make_api_request(url, method="POST", data=data)

Note: Replace <qumulo_cluster_ip>, <username>, <password>, <directory_id>, <parent_directory_id>, and <new_directory_name> with the appropriate values for your Qumulo cluster and query.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함