aboutsummaryrefslogtreecommitdiff
path: root/python/reinstall_ovh_vps_ssd.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-16 19:14:29 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-16 20:13:46 +0100
commit69da835d04e741f4e85da3c473ba86c8801931fd (patch)
tree0cfb28cfd468a5b681f2b5af2b935c81d2221950 /python/reinstall_ovh_vps_ssd.py
parentc15f2234474ff8a8266e26856702b3c561050667 (diff)
downloadPuppet-69da835d04e741f4e85da3c473ba86c8801931fd.tar.gz
Puppet-69da835d04e741f4e85da3c473ba86c8801931fd.tar.zst
Puppet-69da835d04e741f4e85da3c473ba86c8801931fd.zip
Merge install scripts
Diffstat (limited to 'python/reinstall_ovh_vps_ssd.py')
-rw-r--r--python/reinstall_ovh_vps_ssd.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/python/reinstall_ovh_vps_ssd.py b/python/reinstall_ovh_vps_ssd.py
new file mode 100644
index 0000000..9f535cc
--- /dev/null
+++ b/python/reinstall_ovh_vps_ssd.py
@@ -0,0 +1,58 @@
1# -*- encoding: utf-8 -*-
2import json
3try:
4 from ovh import ovh
5except ImportError:
6 # In case it's installed globally
7 import ovh
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
54# Reboot in rescue:
55# PUT /vps/{serviceName}
56# netbootMode "rescue" / "local"
57# changer son nom:
58# displayName: "..."