]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - python/reboot_vps_server.py
Add install scripts
[perso/Immae/Projets/Puppet.git] / python / reboot_vps_server.py
diff --git a/python/reboot_vps_server.py b/python/reboot_vps_server.py
new file mode 100644 (file)
index 0000000..7ea301a
--- /dev/null
@@ -0,0 +1,36 @@
+# -*- encoding: utf-8 -*-
+import json
+from ovh 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)