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