Last active
April 7, 2025 19:42
-
-
Save gpetrousov/6fb2d5835e96c9133c0533190d780a79 to your computer and use it in GitHub Desktop.
experimetal
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 | |
requests.packages.urllib3.disable_warnings() | |
# Node1 data | |
node1_hostname = "10.1.1.135" | |
node1_username = "root@pam" | |
node1_password = "toortoor" | |
node1_api_url = f"https://{node1_hostname}:8006/api2/json" | |
# Node2 data | |
node2_hostname = "10.1.1.136" | |
node2_username = "root@pam" | |
node2_password = "toortoor" | |
node2_api_url = f"https://{node2_hostname}:8006/api2/json" | |
# 0. Create ticket | |
node1_auth_data = { | |
'username': node1_username, | |
'password': node1_password | |
} | |
auth_response = requests.post(f'{node1_api_url}/access/ticket', json=node1_auth_data, verify=False) | |
auth_response.raise_for_status() | |
node1_ticket = auth_response.json()['data']['ticket'] | |
csrf_token = auth_response.json()['data']['CSRFPreventionToken'] | |
# 1. Create the cluster on node1 | |
node1_headers = { | |
'CSRFPreventionToken': csrf_token, | |
'Content-Type': 'application/x-www-form-urlencoded', | |
} | |
node1_cookies = {'PVEAuthCookie': node1_ticket} | |
cluster_data = { | |
'clustername': "Experimetal", | |
'link0': node1_hostname, | |
} | |
create_response = requests.post(f'{node1_api_url}/cluster/config/', headers=node1_headers, cookies=node1_cookies, data=cluster_data, verify=False) | |
# Check if cluster exists | |
# status_response = requests.get(f'{node1_api_url}/cluster/config/nodes/', headers=node1_headers, cookies=node1_cookies, verify=False) | |
# print(status_response.json()) | |
if create_response.reason == "cluster config '/etc/pve/corosync.conf' already exists": | |
print("Cluster exists") | |
else: | |
print(create_response.json()) | |
# 2. Get join information from node1 | |
print("Getting node1 cluster join info") | |
join_info_response = requests.get(f"{node1_api_url}/cluster/config/join", headers=node1_headers, cookies=node1_cookies, verify=False) | |
join_info_response.raise_for_status() | |
join_fingerprint = join_info_response.json()["data"]["nodelist"][0]["pve_fp"] | |
# 2.5 Craft request to join existing cluster | |
node2_auth_data = { | |
"username": node2_username, | |
"password": node2_password | |
} | |
auth_response_node2 = requests.post(f"{node2_api_url}/access/ticket", json=node2_auth_data, verify=False) | |
auth_response_node2.raise_for_status() | |
node2_ticket = auth_response_node2.json()["data"]["ticket"] | |
csrf_token_node2 = auth_response_node2.json()["data"]["CSRFPreventionToken"] | |
node2_headers = { | |
'CSRFPreventionToken': csrf_token_node2, | |
'Content-Type': 'application/x-www-form-urlencoded', | |
} | |
node2_data = { | |
"fingerprint": join_fingerprint, | |
"hostname": node1_hostname, | |
"password": node1_password, | |
"link0": node2_hostname | |
} | |
node2_cookies = {'PVEAuthCookie': node2_ticket} | |
# 3. Add node2 to the cluster | |
print("Attempting to join") | |
join_response = requests.post(f"{node2_api_url}/cluster/config/join", headers=node2_headers, data=node2_data, cookies=node2_cookies, verify=False) | |
join_response.raise_for_status() | |
print(join_response.json()) | |
print("Join done!!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment