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