X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=python%2Fovh_helper.py;h=19834ae2004508da78c2928f80f03872e2b5476c;hb=dad86ebc278becc47b67c2ce29acd4147b3317d5;hp=a49a245ae7233e93a500bdbd844906de2f18599b;hpb=ec1096d8c0d897ebd1ea445d9c5404a13c33ce2e;p=perso%2FImmae%2FProjets%2FPuppet.git diff --git a/python/ovh_helper.py b/python/ovh_helper.py index a49a245..19834ae 100644 --- a/python/ovh_helper.py +++ b/python/ovh_helper.py @@ -1,4 +1,5 @@ import time +import sys def show_progress(client, vps, task_type): running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0] @@ -17,3 +18,19 @@ def show_progress(client, vps, task_type): time.sleep(3) print("\rFinished") + +def find_cloud_instance(client, instance_id): + projects_list = client.get('/cloud/project/') + instances_list = [] + for project in projects_list: + instances_list += list(map(lambda x: [project, x], + client.get('/cloud/project/{}/instance'.format(project)))) + instances = dict(map(lambda x: (x[1]["id"], x), instances_list)) + if instance_id in instances: + project_instance = instances[instance_id] + else: + print("Instance not in list:") + for instance in instances_list: + print("{}: {}".format(instance[1]["name"], instance[1]["id"])) + sys.exit(1) + return project_instance