aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/buy_ovh_vps_ssd.py (renamed from python/buy_vps_server.py)0
-rw-r--r--python/get_initial_configuration_ovh_cloud_instance.py (renamed from python/get_initial_configuration_cloud_instance.py)15
-rw-r--r--python/get_initial_configuration_ovh_vps_ssd.py (renamed from python/get_initial_configuration.py)0
-rw-r--r--python/list_servers.py13
-rw-r--r--python/ovh_helper.py17
-rw-r--r--python/reboot_ovh_cloud_instance.py (renamed from python/reboot_cloud_instance.py)15
-rw-r--r--python/reboot_ovh_vps_ssd.py (renamed from python/reboot_vps_server.py)0
-rw-r--r--python/reinstall_ovh_cloud_instance.py (renamed from python/reinstall_cloud_instance.py)15
-rw-r--r--python/reinstall_ovh_vps_ssd.py (renamed from python/reinstall_vps_server.py)0
9 files changed, 35 insertions, 40 deletions
diff --git a/python/buy_vps_server.py b/python/buy_ovh_vps_ssd.py
index 44ae786..44ae786 100644
--- a/python/buy_vps_server.py
+++ b/python/buy_ovh_vps_ssd.py
diff --git a/python/get_initial_configuration_cloud_instance.py b/python/get_initial_configuration_ovh_cloud_instance.py
index 4157716..844373c 100644
--- a/python/get_initial_configuration_cloud_instance.py
+++ b/python/get_initial_configuration_ovh_cloud_instance.py
@@ -6,6 +6,7 @@ except ImportError:
6 # In case it's installed globally 6 # In case it's installed globally
7 import ovh 7 import ovh
8import sys 8import sys
9from ovh_helper import find_cloud_instance
9 10
10infos = {} 11infos = {}
11 12
@@ -13,19 +14,7 @@ infos = {}
13# See ovh/README.rst 14# See ovh/README.rst
14client = ovh.Client() 15client = ovh.Client()
15 16
16projects_list = client.get('/cloud/project/') 17_, instance = find_cloud_instance(client, sys.argv[-1])
17if len(projects_list) > 1:
18 print("More than one project is not supported, taking the first one")
19project = projects_list[0]
20instances_list = client.get('/cloud/project/{}/instance'.format(project))
21instances = dict(map(lambda x: (x["id"], x), instances_list))
22if sys.argv[-1] in instances:
23 instance = instances[sys.argv[-1]]
24else:
25 print("Instance not in list:")
26 for instance in instances_list:
27 print("{}: {}".format(instance["name"], instance["id"]))
28 sys.exit(1)
29 18
30infos["ips"] = {} 19infos["ips"] = {}
31for ip_infos in instance["ipAddresses"]: 20for ip_infos in instance["ipAddresses"]:
diff --git a/python/get_initial_configuration.py b/python/get_initial_configuration_ovh_vps_ssd.py
index 0c6f698..0c6f698 100644
--- a/python/get_initial_configuration.py
+++ b/python/get_initial_configuration_ovh_vps_ssd.py
diff --git a/python/list_servers.py b/python/list_servers.py
index 9b8bc64..e7bd2af 100644
--- a/python/list_servers.py
+++ b/python/list_servers.py
@@ -6,7 +6,18 @@ except ImportError:
6 6
7client = ovh.Client() 7client = ovh.Client()
8 8
9print("OVH cloud instances:")
10projects_list = client.get('/cloud/project/')
11for project_id in projects_list:
12 project = client.get('/cloud/project/{}'.format(project_id))
13 print("\t{}:".format(project["description"]))
14 instances_list = client.get('/cloud/project/{}/instance'.format(project_id))
15 for instance in instances_list:
16 print("\t\t{}: {}".format(instance["name"], instance["id"]))
17
9vps_list = client.get('/vps/') 18vps_list = client.get('/vps/')
10 19
20print("OVH VPS SSD servers:")
11for vps in vps_list: 21for vps in vps_list:
12 print(vps) 22 print("\t{}".format(vps))
23
diff --git a/python/ovh_helper.py b/python/ovh_helper.py
index a49a245..19834ae 100644
--- a/python/ovh_helper.py
+++ b/python/ovh_helper.py
@@ -1,4 +1,5 @@
1import time 1import time
2import sys
2 3
3def show_progress(client, vps, task_type): 4def show_progress(client, vps, task_type):
4 running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0] 5 running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0]
@@ -17,3 +18,19 @@ def show_progress(client, vps, task_type):
17 time.sleep(3) 18 time.sleep(3)
18 19
19 print("\rFinished") 20 print("\rFinished")
21
22def find_cloud_instance(client, instance_id):
23 projects_list = client.get('/cloud/project/')
24 instances_list = []
25 for project in projects_list:
26 instances_list += list(map(lambda x: [project, x],
27 client.get('/cloud/project/{}/instance'.format(project))))
28 instances = dict(map(lambda x: (x[1]["id"], x), instances_list))
29 if instance_id in instances:
30 project_instance = instances[instance_id]
31 else:
32 print("Instance not in list:")
33 for instance in instances_list:
34 print("{}: {}".format(instance[1]["name"], instance[1]["id"]))
35 sys.exit(1)
36 return project_instance
diff --git a/python/reboot_cloud_instance.py b/python/reboot_ovh_cloud_instance.py
index b90f488..de20c07 100644
--- a/python/reboot_cloud_instance.py
+++ b/python/reboot_ovh_cloud_instance.py
@@ -6,24 +6,13 @@ except ImportError:
6 # In case it's installed globally 6 # In case it's installed globally
7 import ovh 7 import ovh
8import sys 8import sys
9from ovh_helper import find_cloud_instance
9 10
10# Credentials are stored in ~/.ovh.conf 11# Credentials are stored in ~/.ovh.conf
11# See ovh/README.rst 12# See ovh/README.rst
12client = ovh.Client() 13client = ovh.Client()
13 14
14projects_list = client.get('/cloud/project/') 15project, instance = find_cloud_instance(client, sys.argv[-1])
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 16
28if "--rescue" in sys.argv: 17if "--rescue" in sys.argv:
29 netboot_mode="rescue" 18 netboot_mode="rescue"
diff --git a/python/reboot_vps_server.py b/python/reboot_ovh_vps_ssd.py
index 71c5227..71c5227 100644
--- a/python/reboot_vps_server.py
+++ b/python/reboot_ovh_vps_ssd.py
diff --git a/python/reinstall_cloud_instance.py b/python/reinstall_ovh_cloud_instance.py
index c488fda..c0d2617 100644
--- a/python/reinstall_cloud_instance.py
+++ b/python/reinstall_ovh_cloud_instance.py
@@ -6,24 +6,13 @@ except ImportError:
6 # In case it's installed globally 6 # In case it's installed globally
7 import ovh 7 import ovh
8import sys 8import sys
9from ovh_helper import find_cloud_instance
9 10
10# Credentials are stored in ~/.ovh.conf 11# Credentials are stored in ~/.ovh.conf
11# See ovh/README.rst 12# See ovh/README.rst
12client = ovh.Client() 13client = ovh.Client()
13 14
14projects_list = client.get('/cloud/project/') 15project, instance = find_cloud_instance(client, sys.argv[-1])
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 16
28current_image = instance["imageId"] 17current_image = instance["imageId"]
29available_images = client.get('/cloud/project/{}/image'.format(project), 18available_images = client.get('/cloud/project/{}/image'.format(project),
diff --git a/python/reinstall_vps_server.py b/python/reinstall_ovh_vps_ssd.py
index 9f535cc..9f535cc 100644
--- a/python/reinstall_vps_server.py
+++ b/python/reinstall_ovh_vps_ssd.py