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