From 69da835d04e741f4e85da3c473ba86c8801931fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 16 Mar 2018 19:14:29 +0100 Subject: Merge install scripts --- python/buy_ovh_vps_ssd.py | 63 ++++++++++++++++++++++ python/buy_vps_server.py | 63 ---------------------- python/get_initial_configuration.py | 37 ------------- python/get_initial_configuration_cloud_instance.py | 41 -------------- ...get_initial_configuration_ovh_cloud_instance.py | 30 +++++++++++ python/get_initial_configuration_ovh_vps_ssd.py | 37 +++++++++++++ python/list_servers.py | 13 ++++- python/ovh_helper.py | 17 ++++++ python/reboot_cloud_instance.py | 39 -------------- python/reboot_ovh_cloud_instance.py | 28 ++++++++++ python/reboot_ovh_vps_ssd.py | 40 ++++++++++++++ python/reboot_vps_server.py | 40 -------------- python/reinstall_cloud_instance.py | 57 -------------------- python/reinstall_ovh_cloud_instance.py | 46 ++++++++++++++++ python/reinstall_ovh_vps_ssd.py | 58 ++++++++++++++++++++ python/reinstall_vps_server.py | 58 -------------------- 16 files changed, 331 insertions(+), 336 deletions(-) create mode 100644 python/buy_ovh_vps_ssd.py delete mode 100644 python/buy_vps_server.py delete mode 100644 python/get_initial_configuration.py delete mode 100644 python/get_initial_configuration_cloud_instance.py create mode 100644 python/get_initial_configuration_ovh_cloud_instance.py create mode 100644 python/get_initial_configuration_ovh_vps_ssd.py delete mode 100644 python/reboot_cloud_instance.py create mode 100644 python/reboot_ovh_cloud_instance.py create mode 100644 python/reboot_ovh_vps_ssd.py delete mode 100644 python/reboot_vps_server.py delete mode 100644 python/reinstall_cloud_instance.py create mode 100644 python/reinstall_ovh_cloud_instance.py create mode 100644 python/reinstall_ovh_vps_ssd.py delete mode 100644 python/reinstall_vps_server.py (limited to 'python') diff --git a/python/buy_ovh_vps_ssd.py b/python/buy_ovh_vps_ssd.py new file mode 100644 index 0000000..44ae786 --- /dev/null +++ b/python/buy_ovh_vps_ssd.py @@ -0,0 +1,63 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys +import ovh_helper + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +# Create a cart +cart = client.post('/order/cart', ovhSubsidiary="FR") +cart_id = cart["cartId"] + +# Assign it to my user +client.post('/order/cart/{}/assign'.format(cart_id)) + +# list of vps: +# client.get('/order/cart/{}/vps'.format(cart_id)) +item = client.post('/order/cart/{}/vps'.format(cart_id), + duration="P1M", + planCode="vps_ssd_model1", + pricingMode="default", + quantity=1) +item_id = item["itemId"] + +# Datacenter, OS, auto-renew +client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), + label="vps_ssd_datacenter", + value="gra") +client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), + label="vps_ssd_os", + value="linux--archlinux--64--en") +client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), + label="AUTO_RENEW_VPS", + value=False) + +#summary = client.get('/order/cart/{}/summary'.format(cart_id)) +#checkout = client.get('/order/cart/{}/checkout'.format(cart_id)) + +# Checkout +order = client.post('/order/cart/{}/checkout'.format(cart_id), + waiveRetractationPeriod=True) +order_id = order["orderId"] +print(order_id) + +payment_mean = client.get('/me/order/{}/availableRegisteredPaymentMean'.format(order_id))[0]['paymentMean'] +payment_mean_id = client.get('/me/paymentMean/{}'.format(payment_mean))[0] + +payment_mean_status = client.get('/me/paymentMean/{}/{}'.format(payment_mean, payment_mean_id)) + +if payment_mean_status["state"] != "valid": + raise "Bouh" + +paid_order = client.post('/me/order/{}/payWithRegisteredPaymentMean'.format(order_id), + paymentMean=payment_mean, paymentMeanId=payment_mean_id) + +if 'paymentDate' in paid_order: + print("successful") diff --git a/python/buy_vps_server.py b/python/buy_vps_server.py deleted file mode 100644 index 44ae786..0000000 --- a/python/buy_vps_server.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- encoding: utf-8 -*- -import json -try: - from ovh import ovh -except ImportError: - # In case it's installed globally - import ovh -import sys -import ovh_helper - -# Credentials are stored in ~/.ovh.conf -# See ovh/README.rst -client = ovh.Client() - -# Create a cart -cart = client.post('/order/cart', ovhSubsidiary="FR") -cart_id = cart["cartId"] - -# Assign it to my user -client.post('/order/cart/{}/assign'.format(cart_id)) - -# list of vps: -# client.get('/order/cart/{}/vps'.format(cart_id)) -item = client.post('/order/cart/{}/vps'.format(cart_id), - duration="P1M", - planCode="vps_ssd_model1", - pricingMode="default", - quantity=1) -item_id = item["itemId"] - -# Datacenter, OS, auto-renew -client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), - label="vps_ssd_datacenter", - value="gra") -client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), - label="vps_ssd_os", - value="linux--archlinux--64--en") -client.post('/order/cart/{}/item/{}/configuration'.format(cart_id, item_id), - label="AUTO_RENEW_VPS", - value=False) - -#summary = client.get('/order/cart/{}/summary'.format(cart_id)) -#checkout = client.get('/order/cart/{}/checkout'.format(cart_id)) - -# Checkout -order = client.post('/order/cart/{}/checkout'.format(cart_id), - waiveRetractationPeriod=True) -order_id = order["orderId"] -print(order_id) - -payment_mean = client.get('/me/order/{}/availableRegisteredPaymentMean'.format(order_id))[0]['paymentMean'] -payment_mean_id = client.get('/me/paymentMean/{}'.format(payment_mean))[0] - -payment_mean_status = client.get('/me/paymentMean/{}/{}'.format(payment_mean, payment_mean_id)) - -if payment_mean_status["state"] != "valid": - raise "Bouh" - -paid_order = client.post('/me/order/{}/payWithRegisteredPaymentMean'.format(order_id), - paymentMean=payment_mean, paymentMeanId=payment_mean_id) - -if 'paymentDate' in paid_order: - print("successful") diff --git a/python/get_initial_configuration.py b/python/get_initial_configuration.py deleted file mode 100644 index 0c6f698..0000000 --- a/python/get_initial_configuration.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- encoding: utf-8 -*- -import json -try: - from ovh import ovh -except ImportError: - # In case it's installed globally - import ovh -import sys - -infos = {} - -# Credentials are stored in ~/.ovh.conf -# See ovh/README.rst -client = ovh.Client() - -vps_list = client.get('/vps/') -if sys.argv[-1] in vps_list: - vps = sys.argv[-1] -else: - print("VPS not in list:") - for vps in vps_list: - print(vps) - sys.exit(1) - -ips = client.get('/vps/{}/ips'.format(vps)) - -infos["ips"] = {} -for ip in ips: - ip_infos = client.get('/vps/{}/ips/{}'.format(vps, ip)) - - if ip_infos["version"] == "v4": - infos["ips"]["v4"] = ip_infos - else: - infos["ips"]["v6"] = ip_infos - infos["ips"]["v6"]["mask"] = 128 - -print(json.dumps(infos)) diff --git a/python/get_initial_configuration_cloud_instance.py b/python/get_initial_configuration_cloud_instance.py deleted file mode 100644 index 4157716..0000000 --- a/python/get_initial_configuration_cloud_instance.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- encoding: utf-8 -*- -import json -try: - from ovh import ovh -except ImportError: - # In case it's installed globally - import ovh -import sys - -infos = {} - -# Credentials are stored in ~/.ovh.conf -# See ovh/README.rst -client = ovh.Client() - -projects_list = client.get('/cloud/project/') -if len(projects_list) > 1: - print("More than one project is not supported, taking the first one") -project = projects_list[0] -instances_list = client.get('/cloud/project/{}/instance'.format(project)) -instances = dict(map(lambda x: (x["id"], x), instances_list)) -if sys.argv[-1] in instances: - instance = instances[sys.argv[-1]] -else: - print("Instance not in list:") - for instance in instances_list: - print("{}: {}".format(instance["name"], instance["id"])) - sys.exit(1) - -infos["ips"] = {} -for ip_infos in instance["ipAddresses"]: - ip_infos["ipAddress"] = ip_infos.pop("ip") - ip_infos["gateway"] = ip_infos.pop("gatewayIp") - - if ip_infos["version"] == 4: - infos["ips"]["v4"] = ip_infos - else: - infos["ips"]["v6"] = ip_infos - infos["ips"]["v6"]["mask"] = 128 - -print(json.dumps(infos)) diff --git a/python/get_initial_configuration_ovh_cloud_instance.py b/python/get_initial_configuration_ovh_cloud_instance.py new file mode 100644 index 0000000..844373c --- /dev/null +++ b/python/get_initial_configuration_ovh_cloud_instance.py @@ -0,0 +1,30 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys +from ovh_helper import find_cloud_instance + +infos = {} + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +_, instance = find_cloud_instance(client, sys.argv[-1]) + +infos["ips"] = {} +for ip_infos in instance["ipAddresses"]: + ip_infos["ipAddress"] = ip_infos.pop("ip") + ip_infos["gateway"] = ip_infos.pop("gatewayIp") + + if ip_infos["version"] == 4: + infos["ips"]["v4"] = ip_infos + else: + infos["ips"]["v6"] = ip_infos + infos["ips"]["v6"]["mask"] = 128 + +print(json.dumps(infos)) diff --git a/python/get_initial_configuration_ovh_vps_ssd.py b/python/get_initial_configuration_ovh_vps_ssd.py new file mode 100644 index 0000000..0c6f698 --- /dev/null +++ b/python/get_initial_configuration_ovh_vps_ssd.py @@ -0,0 +1,37 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys + +infos = {} + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +vps_list = client.get('/vps/') +if sys.argv[-1] in vps_list: + vps = sys.argv[-1] +else: + print("VPS not in list:") + for vps in vps_list: + print(vps) + sys.exit(1) + +ips = client.get('/vps/{}/ips'.format(vps)) + +infos["ips"] = {} +for ip in ips: + ip_infos = client.get('/vps/{}/ips/{}'.format(vps, ip)) + + if ip_infos["version"] == "v4": + infos["ips"]["v4"] = ip_infos + else: + infos["ips"]["v6"] = ip_infos + infos["ips"]["v6"]["mask"] = 128 + +print(json.dumps(infos)) 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: client = ovh.Client() +print("OVH cloud instances:") +projects_list = client.get('/cloud/project/') +for project_id in projects_list: + project = client.get('/cloud/project/{}'.format(project_id)) + print("\t{}:".format(project["description"])) + instances_list = client.get('/cloud/project/{}/instance'.format(project_id)) + for instance in instances_list: + print("\t\t{}: {}".format(instance["name"], instance["id"])) + vps_list = client.get('/vps/') +print("OVH VPS SSD servers:") for vps in vps_list: - print(vps) + print("\t{}".format(vps)) + 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 @@ import time +import sys def show_progress(client, vps, task_type): running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0] @@ -17,3 +18,19 @@ def show_progress(client, vps, task_type): time.sleep(3) print("\rFinished") + +def find_cloud_instance(client, instance_id): + projects_list = client.get('/cloud/project/') + instances_list = [] + for project in projects_list: + instances_list += list(map(lambda x: [project, x], + client.get('/cloud/project/{}/instance'.format(project)))) + instances = dict(map(lambda x: (x[1]["id"], x), instances_list)) + if instance_id in instances: + project_instance = instances[instance_id] + else: + print("Instance not in list:") + for instance in instances_list: + print("{}: {}".format(instance[1]["name"], instance[1]["id"])) + sys.exit(1) + return project_instance diff --git a/python/reboot_cloud_instance.py b/python/reboot_cloud_instance.py deleted file mode 100644 index b90f488..0000000 --- a/python/reboot_cloud_instance.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- encoding: utf-8 -*- -import json -try: - from ovh import ovh -except ImportError: - # In case it's installed globally - import ovh -import sys - -# Credentials are stored in ~/.ovh.conf -# See ovh/README.rst -client = ovh.Client() - -projects_list = client.get('/cloud/project/') -if len(projects_list) > 1: - print("More than one project is not supported, taking the first one") -project = projects_list[0] -instances_list = client.get('/cloud/project/{}/instance'.format(project)) -instances = dict(map(lambda x: (x["id"], x), instances_list)) -if sys.argv[-1] in instances: - instance = instances[sys.argv[-1]] -else: - print("Instance not in list:") - for instance in instances_list: - print("{}: {}".format(instance["name"], instance["id"])) - sys.exit(1) - -if "--rescue" in sys.argv: - netboot_mode="rescue" -elif "--local" in sys.argv: - netboot_mode="local" -else: - netboot_mode=None - -if netboot_mode is not None: - result = client.post("/cloud/project/{}/instance/{}/rescueMode".format(project, - instance["id"]), imageId=instance["imageId"], rescue=(netboot_mode == "rescue")) - print(result) - diff --git a/python/reboot_ovh_cloud_instance.py b/python/reboot_ovh_cloud_instance.py new file mode 100644 index 0000000..de20c07 --- /dev/null +++ b/python/reboot_ovh_cloud_instance.py @@ -0,0 +1,28 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys +from ovh_helper import find_cloud_instance + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +project, instance = find_cloud_instance(client, sys.argv[-1]) + +if "--rescue" in sys.argv: + netboot_mode="rescue" +elif "--local" in sys.argv: + netboot_mode="local" +else: + netboot_mode=None + +if netboot_mode is not None: + result = client.post("/cloud/project/{}/instance/{}/rescueMode".format(project, + instance["id"]), imageId=instance["imageId"], rescue=(netboot_mode == "rescue")) + print(result) + diff --git a/python/reboot_ovh_vps_ssd.py b/python/reboot_ovh_vps_ssd.py new file mode 100644 index 0000000..71c5227 --- /dev/null +++ b/python/reboot_ovh_vps_ssd.py @@ -0,0 +1,40 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys +import ovh_helper + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +vps_list = client.get('/vps/') +if sys.argv[-1] in vps_list: + vps = sys.argv[-1] +else: + print("VPS not in list:") + for vps in vps_list: + print(vps) + sys.exit(1) + +if "--rescue" in sys.argv: + netboot_mode="rescue" +elif "--local" in sys.argv: + netboot_mode="local" +else: + netboot_mode=None + +current_state=client.get("/vps/{}".format(vps))["netbootMode"] + +if netboot_mode is None or current_state == netboot_mode: + client.post("/vps/{}/reboot".format(vps)) + task_type="rebootVm" +else: + client.put("/vps/{}".format(vps), netbootMode=netboot_mode) + task_type="setNetboot" + +ovh_helper.show_progress(client, vps, task_type) diff --git a/python/reboot_vps_server.py b/python/reboot_vps_server.py deleted file mode 100644 index 71c5227..0000000 --- a/python/reboot_vps_server.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- encoding: utf-8 -*- -import json -try: - from ovh import ovh -except ImportError: - # In case it's installed globally - import ovh -import sys -import ovh_helper - -# Credentials are stored in ~/.ovh.conf -# See ovh/README.rst -client = ovh.Client() - -vps_list = client.get('/vps/') -if sys.argv[-1] in vps_list: - vps = sys.argv[-1] -else: - print("VPS not in list:") - for vps in vps_list: - print(vps) - sys.exit(1) - -if "--rescue" in sys.argv: - netboot_mode="rescue" -elif "--local" in sys.argv: - netboot_mode="local" -else: - netboot_mode=None - -current_state=client.get("/vps/{}".format(vps))["netbootMode"] - -if netboot_mode is None or current_state == netboot_mode: - client.post("/vps/{}/reboot".format(vps)) - task_type="rebootVm" -else: - client.put("/vps/{}".format(vps), netbootMode=netboot_mode) - task_type="setNetboot" - -ovh_helper.show_progress(client, vps, task_type) diff --git a/python/reinstall_cloud_instance.py b/python/reinstall_cloud_instance.py deleted file mode 100644 index c488fda..0000000 --- a/python/reinstall_cloud_instance.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- encoding: utf-8 -*- -import json -try: - from ovh import ovh -except ImportError: - # In case it's installed globally - import ovh -import sys - -# Credentials are stored in ~/.ovh.conf -# See ovh/README.rst -client = ovh.Client() - -projects_list = client.get('/cloud/project/') -if len(projects_list) > 1: - print("More than one project is not supported, taking the first one") -project = projects_list[0] -instances_list = client.get('/cloud/project/{}/instance'.format(project)) -instances = dict(map(lambda x: (x["id"], x), instances_list)) -if sys.argv[-1] in instances: - instance = instances[sys.argv[-1]] -else: - print("Instance not in list:") - for instance in instances_list: - print("{}: {}".format(instance["name"], instance["id"])) - sys.exit(1) - -current_image = instance["imageId"] -available_images = client.get('/cloud/project/{}/image'.format(project), - osType="linux", - region=instance["region"]) -available_images_ids = list(map(lambda x: x["id"], available_images)) - -def print_images(available_images): - for image in available_images: - print("{}: {}".format(image["name"], image["id"])) - -def reinstall(image_id): - return client.post('/cloud/project/{}/instance/{}/reinstall'.format(project, instance["id"]), - imageId=image_id) - -if "--get-state" in sys.argv: - print(instance["status"]) -elif "--use-current" in sys.argv: - if current_image in available_images_ids: - print("Current image still available, using it") - print(reinstall(current_image)) - else: - print("Current image no more available. Chose among:") - print_images(available_images) -elif sys.argv[-1] in available_templates: - print("Chosen image available, using it") - print(reinstall(current_image)) -else: - print("Chosen image not available. Chose among:") - print_images(available_images) - diff --git a/python/reinstall_ovh_cloud_instance.py b/python/reinstall_ovh_cloud_instance.py new file mode 100644 index 0000000..c0d2617 --- /dev/null +++ b/python/reinstall_ovh_cloud_instance.py @@ -0,0 +1,46 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys +from ovh_helper import find_cloud_instance + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +project, instance = find_cloud_instance(client, sys.argv[-1]) + +current_image = instance["imageId"] +available_images = client.get('/cloud/project/{}/image'.format(project), + osType="linux", + region=instance["region"]) +available_images_ids = list(map(lambda x: x["id"], available_images)) + +def print_images(available_images): + for image in available_images: + print("{}: {}".format(image["name"], image["id"])) + +def reinstall(image_id): + return client.post('/cloud/project/{}/instance/{}/reinstall'.format(project, instance["id"]), + imageId=image_id) + +if "--get-state" in sys.argv: + print(instance["status"]) +elif "--use-current" in sys.argv: + if current_image in available_images_ids: + print("Current image still available, using it") + print(reinstall(current_image)) + else: + print("Current image no more available. Chose among:") + print_images(available_images) +elif sys.argv[-1] in available_templates: + print("Chosen image available, using it") + print(reinstall(current_image)) +else: + print("Chosen image not available. Chose among:") + print_images(available_images) + 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 @@ +# -*- encoding: utf-8 -*- +import json +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh +import sys +import ovh_helper + +# Credentials are stored in ~/.ovh.conf +# See ovh/README.rst +client = ovh.Client() + +vps_list = client.get('/vps/') +if sys.argv[-1] in vps_list: + vps = sys.argv[-1] +else: + print("VPS not in list:") + for vps in vps_list: + print(vps) + sys.exit(1) + +current_distribution = client.get('/vps/{}/distribution'.format(vps)) + +available_templates = client.get('/vps/{}/templates'.format(vps)) + +def print_templates(client, vps, available_templates): + for tid in available_templates: + template = client.get('/vps/{}/templates/{}'.format(vps, tid)) + print("{}: {}".format(template["id"], template["distribution"])) + + +if "--get-state" in sys.argv: + print(client.get('/vps/{}'.format(vps))["state"]) +elif "--use-current" in sys.argv: + if current_distribution['id'] in available_templates: + print("Current template still available, using it") + result = client.post('/vps/{}/reinstall'.format(vps), templateId=current_distribution['id']) + print(result) + ovh_helper.show_progress(client, vps, "reinstallVm") + else: + print("Current template no more available. Chose among:") + print_templates(client, vps, available_templates) +elif sys.argv[-1] in available_templates: + print("Chosen template available, using it") + result = client.post('/vps/{}/reinstall'.format(vps), templateId=int(sys.argv[-1])) + print(result) + ovh_helper.show_progress(client, vps, "reinstallVm") +else: + print("Chosen template not available. Chose among:") + print_templates(client, vps, available_templates) + +# Reboot in rescue: +# PUT /vps/{serviceName} +# netbootMode "rescue" / "local" +# changer son nom: +# displayName: "..." diff --git a/python/reinstall_vps_server.py b/python/reinstall_vps_server.py deleted file mode 100644 index 9f535cc..0000000 --- a/python/reinstall_vps_server.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- encoding: utf-8 -*- -import json -try: - from ovh import ovh -except ImportError: - # In case it's installed globally - import ovh -import sys -import ovh_helper - -# Credentials are stored in ~/.ovh.conf -# See ovh/README.rst -client = ovh.Client() - -vps_list = client.get('/vps/') -if sys.argv[-1] in vps_list: - vps = sys.argv[-1] -else: - print("VPS not in list:") - for vps in vps_list: - print(vps) - sys.exit(1) - -current_distribution = client.get('/vps/{}/distribution'.format(vps)) - -available_templates = client.get('/vps/{}/templates'.format(vps)) - -def print_templates(client, vps, available_templates): - for tid in available_templates: - template = client.get('/vps/{}/templates/{}'.format(vps, tid)) - print("{}: {}".format(template["id"], template["distribution"])) - - -if "--get-state" in sys.argv: - print(client.get('/vps/{}'.format(vps))["state"]) -elif "--use-current" in sys.argv: - if current_distribution['id'] in available_templates: - print("Current template still available, using it") - result = client.post('/vps/{}/reinstall'.format(vps), templateId=current_distribution['id']) - print(result) - ovh_helper.show_progress(client, vps, "reinstallVm") - else: - print("Current template no more available. Chose among:") - print_templates(client, vps, available_templates) -elif sys.argv[-1] in available_templates: - print("Chosen template available, using it") - result = client.post('/vps/{}/reinstall'.format(vps), templateId=int(sys.argv[-1])) - print(result) - ovh_helper.show_progress(client, vps, "reinstallVm") -else: - print("Chosen template not available. Chose among:") - print_templates(client, vps, available_templates) - -# Reboot in rescue: -# PUT /vps/{serviceName} -# netbootMode "rescue" / "local" -# changer son nom: -# displayName: "..." -- cgit v1.2.3