From df0c42af3366f013afa1ee13eed04307260beae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 11 Mar 2018 12:26:28 +0100 Subject: Add scripts for ovh cloud --- python/reboot_cloud_instance.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 python/reboot_cloud_instance.py (limited to 'python/reboot_cloud_instance.py') diff --git a/python/reboot_cloud_instance.py b/python/reboot_cloud_instance.py new file mode 100644 index 0000000..b90f488 --- /dev/null +++ b/python/reboot_cloud_instance.py @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +projects_list = client.get('/cloud/project/') +if len(projects_list) > 1: + print("More than one project is not supported, taking the first one") +project = projects_list[0] +instances_list = client.get('/cloud/project/{}/instance'.format(project)) +instances = dict(map(lambda x: (x["id"], x), instances_list)) +if sys.argv[-1] in instances: + instance = instances[sys.argv[-1]] +else: + print("Instance not in list:") + for instance in instances_list: + print("{}: {}".format(instance["name"], instance["id"])) + sys.exit(1) + +if "--rescue" in sys.argv: + netboot_mode="rescue" +elif "--local" in sys.argv: + netboot_mode="local" +else: + netboot_mode=None + +if netboot_mode is not None: + result = client.post("/cloud/project/{}/instance/{}/rescueMode".format(project, + instance["id"]), imageId=instance["imageId"], rescue=(netboot_mode == "rescue")) + print(result) + -- cgit v1.2.3