#!/bin/bash set -eu cd "$(dirname "$0")" # This script is meant to be executed on the management machine. # it reaches out to an SSH endpoint and provisions that machine # to use LXD. DATA_PLANE_MACVLAN_INTERFACE= DISK_TO_USE=loop # override the cluster name. CLUSTER_NAME="${1:-}" if [ -z "$CLUSTER_NAME" ]; then echo "ERROR: The cluster name was not provided." exit 1 fi #shellcheck disable=SC1091 source ./defaults.sh export CLUSTER_PATH="$CLUSTERS_DIR/$CLUSTER_NAME" CLUSTER_DEFINITION="$CLUSTER_PATH/cluster_definition" export CLUSTER_DEFINITION="$CLUSTER_DEFINITION" mkdir -p "$CLUSTER_PATH" if [ ! -f "$CLUSTER_DEFINITION" ]; then # stub out a cluster_definition. cat >"$CLUSTER_DEFINITION" </dev/null 2>&1; then if lxc profile list --format csv | grep -q sovereign-stack; then lxc profile delete sovereign-stack sleep 1 fi if lxc network list --format csv | grep -q lxdbrSS; then lxc network delete lxdbrSS sleep 1 fi fi ssh -t "ubuntu@$FQDN" " # set host firewall policy. # allow LXD API from management network. # sudo ufw allow from ${IP_OF_MGMT_MACHINE}/32 proto tcp to $MGMT_PLANE_IP port 8443 # enable it. # if sudo ufw status | grep -q 'Status: inactive'; then # sudo ufw enable # fi # install lxd as a snap if it's not installed. We only really use the LXC part of this package. if ! snap list | grep -q lxd; then sudo snap install lxd --candidate sleep 4 fi " # if the DATA_PLANE_MACVLAN_INTERFACE is not specified, then we 'll # just attach VMs to the network interface used for for the default route. if [ -z "$DATA_PLANE_MACVLAN_INTERFACE" ]; then DATA_PLANE_MACVLAN_INTERFACE="$(ssh -t ubuntu@"$FQDN" ip route | grep default | cut -d " " -f 5)" fi # stub out the lxd init file for the remote SSH endpoint. CLUSTER_MASTER_LXD_INIT="$CLUSTER_PATH/lxdinit_profile.yml" cat >"$CLUSTER_MASTER_LXD_INIT" <