]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - python/reboot_ovh_vps_ssd.py
Add monitoring for cryptoportfolio
[perso/Immae/Projets/Puppet.git] / python / reboot_ovh_vps_ssd.py
1 # -*- encoding: utf-8 -*-
2 import json
3 try:
4 from ovh import ovh
5 except ImportError:
6 # In case it's installed globally
7 import ovh
8 import sys
9 import ovh_helper
10
11 # Credentials are stored in ~/.ovh.conf
12 # See ovh/README.rst
13 client = ovh.Client()
14
15 vps_list = client.get('/vps/')
16 if sys.argv[-1] in vps_list:
17 vps = sys.argv[-1]
18 else:
19 print("VPS not in list:")
20 for vps in vps_list:
21 print(vps)
22 sys.exit(1)
23
24 if "--rescue" in sys.argv:
25 netboot_mode="rescue"
26 elif "--local" in sys.argv:
27 netboot_mode="local"
28 else:
29 netboot_mode=None
30
31 current_state=client.get("/vps/{}".format(vps))["netbootMode"]
32
33 if netboot_mode is None or current_state == netboot_mode:
34 client.post("/vps/{}/reboot".format(vps))
35 task_type="rebootVm"
36 else:
37 client.put("/vps/{}".format(vps), netbootMode=netboot_mode)
38 task_type="setNetboot"
39
40 ovh_helper.show_progress(client, vps, task_type)