diff options
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.py | 13 | ||||
-rw-r--r-- | python/ovh_helper.py | 17 | ||||
-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 |
8 | import sys | 8 | import sys |
9 | from ovh_helper import find_cloud_instance | ||
9 | 10 | ||
10 | infos = {} | 11 | infos = {} |
11 | 12 | ||
@@ -13,19 +14,7 @@ infos = {} | |||
13 | # See ovh/README.rst | 14 | # See ovh/README.rst |
14 | client = ovh.Client() | 15 | client = ovh.Client() |
15 | 16 | ||
16 | projects_list = client.get('/cloud/project/') | 17 | _, instance = find_cloud_instance(client, sys.argv[-1]) |
17 | if len(projects_list) > 1: | ||
18 | print("More than one project is not supported, taking the first one") | ||
19 | project = projects_list[0] | ||
20 | instances_list = client.get('/cloud/project/{}/instance'.format(project)) | ||
21 | instances = dict(map(lambda x: (x["id"], x), instances_list)) | ||
22 | if sys.argv[-1] in instances: | ||
23 | instance = instances[sys.argv[-1]] | ||
24 | else: | ||
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 | ||
30 | infos["ips"] = {} | 19 | infos["ips"] = {} |
31 | for ip_infos in instance["ipAddresses"]: | 20 | for 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 | ||
7 | client = ovh.Client() | 7 | client = ovh.Client() |
8 | 8 | ||
9 | print("OVH cloud instances:") | ||
10 | projects_list = client.get('/cloud/project/') | ||
11 | for 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 | |||
9 | vps_list = client.get('/vps/') | 18 | vps_list = client.get('/vps/') |
10 | 19 | ||
20 | print("OVH VPS SSD servers:") | ||
11 | for vps in vps_list: | 21 | for 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 @@ | |||
1 | import time | 1 | import time |
2 | import sys | ||
2 | 3 | ||
3 | def show_progress(client, vps, task_type): | 4 | def 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 | |||
22 | def 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 |
8 | import sys | 8 | import sys |
9 | from 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 |
12 | client = ovh.Client() | 13 | client = ovh.Client() |
13 | 14 | ||
14 | projects_list = client.get('/cloud/project/') | 15 | project, instance = find_cloud_instance(client, sys.argv[-1]) |
15 | if len(projects_list) > 1: | ||
16 | print("More than one project is not supported, taking the first one") | ||
17 | project = projects_list[0] | ||
18 | instances_list = client.get('/cloud/project/{}/instance'.format(project)) | ||
19 | instances = dict(map(lambda x: (x["id"], x), instances_list)) | ||
20 | if sys.argv[-1] in instances: | ||
21 | instance = instances[sys.argv[-1]] | ||
22 | else: | ||
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 | ||
28 | if "--rescue" in sys.argv: | 17 | if "--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 |
8 | import sys | 8 | import sys |
9 | from 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 |
12 | client = ovh.Client() | 13 | client = ovh.Client() |
13 | 14 | ||
14 | projects_list = client.get('/cloud/project/') | 15 | project, instance = find_cloud_instance(client, sys.argv[-1]) |
15 | if len(projects_list) > 1: | ||
16 | print("More than one project is not supported, taking the first one") | ||
17 | project = projects_list[0] | ||
18 | instances_list = client.get('/cloud/project/{}/instance'.format(project)) | ||
19 | instances = dict(map(lambda x: (x["id"], x), instances_list)) | ||
20 | if sys.argv[-1] in instances: | ||
21 | instance = instances[sys.argv[-1]] | ||
22 | else: | ||
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 | ||
28 | current_image = instance["imageId"] | 17 | current_image = instance["imageId"] |
29 | available_images = client.get('/cloud/project/{}/image'.format(project), | 18 | available_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 | |||