aboutsummaryrefslogtreecommitdiff
path: root/python/reboot_cloud_instance.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/reboot_cloud_instance.py')
-rw-r--r--python/reboot_cloud_instance.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/python/reboot_cloud_instance.py b/python/reboot_cloud_instance.py
new file mode 100644
index 0000000..b90f488
--- /dev/null
+++ b/python/reboot_cloud_instance.py
@@ -0,0 +1,39 @@
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
9
10# Credentials are stored in ~/.ovh.conf
11# See ovh/README.rst
12client = ovh.Client()
13
14projects_list = client.get('/cloud/project/')
15if len(projects_list) > 1:
16 print("More than one project is not supported, taking the first one")
17project = projects_list[0]
18instances_list = client.get('/cloud/project/{}/instance'.format(project))
19instances = dict(map(lambda x: (x["id"], x), instances_list))
20if sys.argv[-1] in instances:
21 instance = instances[sys.argv[-1]]
22else:
23 print("Instance not in list:")
24 for instance in instances_list:
25 print("{}: {}".format(instance["name"], instance["id"]))
26 sys.exit(1)
27
28if "--rescue" in sys.argv:
29 netboot_mode="rescue"
30elif "--local" in sys.argv:
31 netboot_mode="local"
32else:
33 netboot_mode=None
34
35if netboot_mode is not None:
36 result = client.post("/cloud/project/{}/instance/{}/rescueMode".format(project,
37 instance["id"]), imageId=instance["imageId"], rescue=(netboot_mode == "rescue"))
38 print(result)
39