From: Ismaël Bouya Date: Fri, 16 Mar 2018 18:14:29 +0000 (+0100) Subject: Merge install scripts X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=69da835d04e741f4e85da3c473ba86c8801931fd;p=perso%2FImmae%2FProjets%2FPuppet.git Merge install scripts --- diff --git a/bin/install_script_ovh_vps_ssd.sh b/bin/install_script.sh similarity index 55% rename from bin/install_script_ovh_vps_ssd.sh rename to bin/install_script.sh index b5b0efb..bd7f38b 100755 --- a/bin/install_script_ovh_vps_ssd.sh +++ b/bin/install_script.sh @@ -2,39 +2,63 @@ usage() { cat < $ARCH_PUPPET_INITIAL_CONFIGURATION +python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id > $ARCH_PUPPET_INITIAL_CONFIGURATION +host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id | jq -r '.ips.v4.ipAddress') -dest="$host_user@$vps_name" +dest="$host_user@$host_address" files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files @@ -119,5 +151,5 @@ $SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $file ### Installation finished if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then echo "Rebooting" - python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name" + python $PYTHON_DIRECTORY/reboot_$T.py --local "$host_id" fi diff --git a/bin/install_script_ovh_cloud_instance.sh b/bin/install_script_ovh_cloud_instance.sh deleted file mode 100755 index e1c8a54..0000000 --- a/bin/install_script_ovh_cloud_instance.sh +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash - -usage() { -cat < $ARCH_PUPPET_INITIAL_CONFIGURATION -host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress') - -dest="$host_user@$host_address" -files="$ARCH_HOST_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT" - -$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files - -### Role specific stage -read -p "Press key when LDAP is configured" i - -files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT" - -$SCRIPTS/send_and_run.tcl "$dest" "" "$git_branch" "$environment" $files - -### Installation finished -if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then - echo "Rebooting" - python $PYTHON_DIRECTORY/reboot_cloud_instance.py --local "$instance_id" -fi diff --git a/python/buy_vps_server.py b/python/buy_ovh_vps_ssd.py similarity index 100% rename from python/buy_vps_server.py rename to 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 similarity index 52% rename from python/get_initial_configuration_cloud_instance.py rename to 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: # In case it's installed globally import ovh import sys +from ovh_helper import find_cloud_instance infos = {} @@ -13,19 +14,7 @@ infos = {} # 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) +_, instance = find_cloud_instance(client, sys.argv[-1]) infos["ips"] = {} for ip_infos in instance["ipAddresses"]: diff --git a/python/get_initial_configuration.py b/python/get_initial_configuration_ovh_vps_ssd.py similarity index 100% rename from python/get_initial_configuration.py rename to 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: 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_ovh_cloud_instance.py similarity index 52% rename from python/reboot_cloud_instance.py rename to 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: # 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() -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) +project, instance = find_cloud_instance(client, sys.argv[-1]) if "--rescue" in sys.argv: netboot_mode="rescue" diff --git a/python/reboot_vps_server.py b/python/reboot_ovh_vps_ssd.py similarity index 100% rename from python/reboot_vps_server.py rename to python/reboot_ovh_vps_ssd.py diff --git a/python/reinstall_cloud_instance.py b/python/reinstall_ovh_cloud_instance.py similarity index 71% rename from python/reinstall_cloud_instance.py rename to 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: # 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() -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) +project, instance = find_cloud_instance(client, sys.argv[-1]) current_image = instance["imageId"] available_images = client.get('/cloud/project/{}/image'.format(project), diff --git a/python/reinstall_vps_server.py b/python/reinstall_ovh_vps_ssd.py similarity index 100% rename from python/reinstall_vps_server.py rename to python/reinstall_ovh_vps_ssd.py diff --git a/scripts/ovh_cloud_instance/arch_host_script.sh b/scripts/ovh_cloud_instance/arch_host_script.sh index c188514..3408563 100755 --- a/scripts/ovh_cloud_instance/arch_host_script.sh +++ b/scripts/ovh_cloud_instance/arch_host_script.sh @@ -29,7 +29,7 @@ sudo mount "$DEVICE" /mnt for i in /mnt/*; do if [ "$i" = "/mnt/boot" ]; then # keep /boot/grub - sudo rm -f $i/* + sudo rm -f $i/* || true else sudo rm -rf $i fi diff --git a/scripts/send_and_run.tcl b/scripts/send_and_run.tcl index a087a2d..42fae62 100755 --- a/scripts/send_and_run.tcl +++ b/scripts/send_and_run.tcl @@ -6,7 +6,7 @@ set environment [lindex $argv 3] set script [lindex $argv 4] set files [lrange $argv 4 end] -if {$password == ""} { +if {$password == "x"} { set ask_password 0 } else { set ask_password 1