]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame - python/reinstall_ovh_vps_ssd.py
Merge branch 'dev'
[perso/Immae/Projets/Puppet.git] / python / reinstall_ovh_vps_ssd.py
CommitLineData
ec1096d8
IB
1# -*- encoding: utf-8 -*-
2import json
54e54fe0
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
24current_distribution = client.get('/vps/{}/distribution'.format(vps))
25
26available_templates = client.get('/vps/{}/templates'.format(vps))
27
28def print_templates(client, vps, available_templates):
29 for tid in available_templates:
30 template = client.get('/vps/{}/templates/{}'.format(vps, tid))
31 print("{}: {}".format(template["id"], template["distribution"]))
32
33
34if "--get-state" in sys.argv:
35 print(client.get('/vps/{}'.format(vps))["state"])
36elif "--use-current" in sys.argv:
37 if current_distribution['id'] in available_templates:
38 print("Current template still available, using it")
39 result = client.post('/vps/{}/reinstall'.format(vps), templateId=current_distribution['id'])
40 print(result)
41 ovh_helper.show_progress(client, vps, "reinstallVm")
42 else:
43 print("Current template no more available. Chose among:")
44 print_templates(client, vps, available_templates)
45elif sys.argv[-1] in available_templates:
46 print("Chosen template available, using it")
47 result = client.post('/vps/{}/reinstall'.format(vps), templateId=int(sys.argv[-1]))
48 print(result)
49 ovh_helper.show_progress(client, vps, "reinstallVm")
50else:
51 print("Chosen template not available. Chose among:")
52 print_templates(client, vps, available_templates)
53
ec1096d8
IB
54# Reboot in rescue:
55# PUT /vps/{serviceName}
56# netbootMode "rescue" / "local"
57# changer son nom:
58# displayName: "..."