usage() {
cat <<EOF
- $0 [options]
+$(basename $0) [options]
--help,-h This help
- --vps vps_name Name of the vps
- --password password Password of the vps (only useful in case of no reboot)
+
+ One of the following options is necessary:
+ --instance-id id Id of the cloud instance
+ --vps-id id Id of the vps
+
+ Optional arguments:
+ --password password Password of the host (only useful in case of no reboot and vps)
--reinstall-first Start with reinstalling the vps
- --host-user user Use another user (default: root)
+ --host-user user Use another user than the default one
--no-reboot Don't reboot
--no-reboot-start Don't reboot to rescue at the beginning
--no-reboot-end Don't reboot to normal at the end
- --git-branch Use another puppet branch (default: master)
- --environment Environment to use for the installl (default: production)
+ --git-branch branch Use another puppet branch (default: master)
+ --environment env Environment to use for the install (default: production)
EOF
}
set -e
-host_user=root
git_branch=master
environment=production
+host_user=""
+password=""
+T=""
while [ -n "$1" ]; do
case "$1" in
- --vps)
- vps_name="$2"
+ --instance-id)
+ host_id="$2"
+ if [ -z "$host_user" ]; then
+ host_user="arch"
+ fi
+ if [ -z "$password" ]; then
+ password="x"
+ fi
+ [ -n "$T" ] && usage && exit 1
+ T="ovh_cloud_instance"
shift
;;
- --reinstall-first)
- reinstall_first=1
+ --vps-id)
+ host_id="$2"
+ if [ -z "$host_user" ]; then
+ host_user="root"
+ fi
+ [ -n "$T" ] && usage && exit 1
+ T="ovh_vps_ssd"
+ shift
;;
--password)
password="$2"
shift
;;
+ --reinstall-first)
+ reinstall_first=1
+ ;;
--host-user)
host_user="$2"
shift
shift
done
+if [ -z "$T" -o -z "$host_id" ]; then
+ usage
+ exit 1
+fi
+
DIRECTORY=$(cd `dirname $0` && pwd)
PYTHON_DIRECTORY="$DIRECTORY/../python"
SCRIPTS="$DIRECTORY/../scripts"
-if [ -z "$vps_name" ]; then
- read -p "Nom du vps : " vps_name
-fi
-
if [ -n "$reinstall_first" ]; then
echo "Réinstallation du système"
- python $PYTHON_DIRECTORY/reinstall_vps_server.py --use-current "$vps_name"
+ python $PYTHON_DIRECTORY/reinstall_$T.py --use-current "$host_id"
read -p "Appuyer sur une touche quand le serveur est prêt" ready
fi
if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
echo "Patienter le temps du reboot"
- python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name"
+ python $PYTHON_DIRECTORY/reboot_$T.py --rescue "$host_id"
+
+ read -p "Appuyer sur une touche quand l'instance a redémarré" ready
fi
if [ -z "$password" ]; then
fi
ARCH_DIR=`mktemp -d`
-ARCH_HOST_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_script.sh"
-ARCH_CHROOT_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_chroot_script.sh"
+ARCH_HOST_SCRIPT="$SCRIPTS/$T/arch_host_script.sh"
+if [ -f "$SCRIPTS/$T/arch_chroot_script.sh" ]; then
+ ARCH_CHROOT_SCRIPT="$SCRIPTS/$T/arch_chroot_script.sh"
+else
+ ARCH_CHROOT_SCRIPT=""
+fi
ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
-ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_vps_ssd/arch_host_puppet_configuration_script.sh"
+ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh"
ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
trap "rm -rf $ARCH_DIR" EXIT
#### Base installation stage
-python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $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
### 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
+++ /dev/null
-#!/bin/bash
-
-usage() {
-cat <<EOF
- $0 [options]
- --help,-h This help
- --instance-id id Id of the instance
- --reinstall-first Start with reinstalling the vps
- --host-user user Use another user (default: arch)
- --no-reboot Don't reboot
- --no-reboot-start Don't reboot to rescue at the beginning
- --no-reboot-end Don't reboot to normal at the end
- --git-branch Use another puppet branch (default: master)
- --environment Environment to use for the installl (default: production)
-EOF
-}
-
-set -e
-
-host_user=arch
-git_branch=master
-environment=production
-
-while [ -n "$1" ]; do
- case "$1" in
- --instance-id)
- instance_id="$2"
- shift
- ;;
- --reinstall-first)
- reinstall_first=1
- ;;
- --host-user)
- host_user="$2"
- shift
- ;;
- --no-reboot)
- no_reboot=1
- ;;
- --no-reboot-start)
- no_reboot_start=1
- ;;
- --no-reboot-end)
- no_reboot_end=1
- ;;
- --git-branch)
- git_branch="$2"
- shift
- ;;
- --environment)
- environment="$2"
- shift
- ;;
- --help|-h)
- usage
- exit 0
- ;;
- esac
-
- shift
-done
-
-DIRECTORY=$(cd `dirname $0` && pwd)
-PYTHON_DIRECTORY="$DIRECTORY/../python"
-SCRIPTS="$DIRECTORY/../scripts"
-
-if [ -z "$instance_id" ]; then
- read -p "Id de l'instance : " instance_id
-fi
-
-if [ -n "$reinstall_first" ]; then
- echo "Réinstallation du système"
- python $PYTHON_DIRECTORY/reinstall_cloud_instance.py --use-current "$instance_id"
-
- read -p "Appuyer sur une touche quand le serveur est prêt" ready
-fi
-
-if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
- echo "Patienter le temps du reboot"
- python $PYTHON_DIRECTORY/reboot_cloud_instance.py --rescue "$instance_id"
-
- read -p "Appuyer sur une touche quand l'instance a redémarré" ready
-fi
-
-ARCH_DIR=`mktemp -d`
-ARCH_HOST_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_script.sh"
-ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
-ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/ovh_cloud_instance/arch_host_puppet_configuration_script.sh"
-ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
-ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
-
-trap "rm -rf $ARCH_DIR" EXIT
-
-#### Base installation stage
-python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $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
# In case it's installed globally
import ovh
import sys
+from ovh_helper import find_cloud_instance
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"]:
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))
+
import time
+import sys
def show_progress(client, vps, task_type):
running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0]
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
# 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"
# 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),
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
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