]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - python/ovh_helper.py
Set POST limit for uwsgi
[perso/Immae/Projets/Puppet.git] / python / ovh_helper.py
1 import time
2 import sys
3
4 def show_progress(client, vps, task_type):
5 running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0]
6
7 progress = 0
8 state = "todo"
9 print(" 0 %", end='')
10 while state != "done":
11 old_progress = progress
12 task = client.get("/vps/{}/tasks/{}".format(vps, running_task_id))
13 progress = task["progress"]
14 state = task["state"]
15
16 if progress != old_progress:
17 print("\r{:>3} %".format(progress), end="")
18 time.sleep(3)
19
20 print("\rFinished")
21
22 def find_cloud_instance(client, instance_id):
23 projects_list = client.get('/cloud/project/')
24 instances_list = []
25 for project in projects_list:
26 instances_list += list(map(lambda x: [project, x],
27 client.get('/cloud/project/{}/instance'.format(project))))
28 instances = dict(map(lambda x: (x[1]["id"], x), instances_list))
29 if instance_id in instances:
30 project_instance = instances[instance_id]
31 else:
32 print("Instance not in list:")
33 for instance in instances_list:
34 print("{}: {}".format(instance[1]["name"], instance[1]["id"]))
35 sys.exit(1)
36 return project_instance