-
Notifications
You must be signed in to change notification settings - Fork 0
/
1cloud_create_vps.py
33 lines (24 loc) · 1.13 KB
/
1cloud_create_vps.py
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
31
32
33
import requests, json, time, os, subprocess, sys
api_key = str(sys.argv[1])
url = "https://api.1cloud.ru/server/"
server_id = str()
headers = {"Content-Type":"application/json", "Authorization": "Bearer " + api_key}
server_config = json.load(open("./configs/vps_config.json"))
def create_server():
create_server = requests.post(url, headers = headers, json = server_config)
server_id = create_server.json()["ID"]
print("Server", server_id, "start to create.")
time.sleep(10)
check_server_status = requests.get(url + str(server_id), headers = headers)
check_server_status.json()
while check_server_status.json()['State'] == "New":
time.sleep(45)
check_server_status = requests.get(url + str(server_id), headers = headers)
check_server_status.json()
print("Server", server_id, "creating...")
server_ip = str(check_server_status.json()["PrimaryNetworkIp"])
os.system(f'echo VPS={server_ip} >> $GITHUB_ENV')
result = "Server" + str(server_id) + "is created successful. " + "IP:" + str(server_ip)
return result
if __name__ == "__main__":
print(create_server())