From 69da835d04e741f4e85da3c473ba86c8801931fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 16 Mar 2018 19:14:29 +0100 Subject: Merge install scripts --- python/reboot_ovh_vps_ssd.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 python/reboot_ovh_vps_ssd.py (limited to 'python/reboot_ovh_vps_ssd.py') diff --git a/python/reboot_ovh_vps_ssd.py b/python/reboot_ovh_vps_ssd.py new file mode 100644 index 0000000..71c5227 --- /dev/null +++ b/python/reboot_ovh_vps_ssd.py @@ -0,0 +1,40 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys +import ovh_helper + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +vps_list = client.get('/vps/') +if sys.argv[-1] in vps_list: + vps = sys.argv[-1] +else: + print("VPS not in list:") + for vps in vps_list: + print(vps) + sys.exit(1) + +if "--rescue" in sys.argv: + netboot_mode="rescue" +elif "--local" in sys.argv: + netboot_mode="local" +else: + netboot_mode=None + +current_state=client.get("/vps/{}".format(vps))["netbootMode"] + +if netboot_mode is None or current_state == netboot_mode: + client.post("/vps/{}/reboot".format(vps)) + task_type="rebootVm" +else: + client.put("/vps/{}".format(vps), netbootMode=netboot_mode) + task_type="setNetboot" + +ovh_helper.show_progress(client, vps, task_type) -- cgit v1.2.3