-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
3,026 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
LXD_REMOTE=lxdcluster: | ||
OVNNETWORK=ovntest | ||
ROOTNAME=lxdcluster | ||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function echo_blue_bold() { | ||
# echo message in blue and bold | ||
echo -e "\x1B[90m= $(date '+%Y-%m-%d %T') \x1B[39m\x1B[1m\x1B[34m$@\x1B[0m\x1B[39m" | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function echo_blue_dot_title() { | ||
# echo message in blue and bold | ||
echo -n -e "\x1B[90m= $(date '+%Y-%m-%d %T') \x1B[39m\x1B[1m\x1B[34m$@\x1B[0m\x1B[39m" | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function echo_blue_dot() { | ||
echo -n -e "\x1B[90m\x1B[39m\x1B[1m\x1B[34m.\x1B[0m\x1B[39m" | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function launch_container() { | ||
local REMOTE=$1 | ||
local NAME=$2 | ||
local TARGET=$3 | ||
local CONTAINER_IP= | ||
|
||
echo_blue_bold "Create instance ${NAME}" | ||
|
||
lxc launch ubuntu:noble ${NAME} --network=ovntest | ||
|
||
lxc exec ${REMOTE}:${NAME} -- apt update | ||
lxc exec ${REMOTE}:${NAME} -- bash -c 'DEBIAN_FRONTEND=noninteractive apt upgrade -y' | ||
lxc exec ${REMOTE}:${NAME} -- apt install nginx -y | ||
|
||
echo_blue_dot_title "Wait ip instance ${REMOTE}:${NAME}" | ||
|
||
while [ -z "${CONTAINER_IP}" ]; do | ||
CONTAINER_IP=$(lxc list ${REMOTE}: name=${NAME} --format=json | jq -r '.[0].state.network|.eth0.addresses[]|select(.family == "inet")|.address') | ||
sleep 1 | ||
echo_blue_dot | ||
done | ||
echo | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function container_ip() { | ||
local REMOTE=$1 | ||
local NAME=$2 | ||
|
||
lxc list ${REMOTE}: name=${NAME} --format=json | jq -r '.[0].state.network|.eth0.addresses[]|select(.family == "inet")|.address' | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# CREATE CONTAINERS | ||
#=========================================================================================================================================== | ||
echo_blue_bold "Create all containers" | ||
|
||
for INDEX in $(seq 0 2) | ||
do | ||
CONTAINER_NAME=container-0${INDEX} | ||
launch_container ${ROOTNAME} ${CONTAINER_NAME} ${ROOTNAME}-0${INDEX} | ||
INSTANCE_IPS[${INDEX}]=$(container_ip ${ROOTNAME} ${CONTAINER_NAME}) | ||
done | ||
|
||
echo_blue_bold "Create instance u3" | ||
lxc launch ubuntu:noble ${ROOTNAME}:container-03 --network=lxdbr0 | ||
|
||
lxc ls ${ROOTNAME}: | ||
|
||
#=========================================================================================================================================== | ||
# CREATE OVN LOAD BALANCER | ||
#=========================================================================================================================================== | ||
NLB_VIP_ADDRESS=$(lxc network load-balancer create ${ROOTNAME}:ovntest --allocate=ipv4 | cut -d ' ' -f 4) | ||
|
||
echo_blue_bold "NLB_VIP_ADDRESS=${NLB_VIP_ADDRESS}" | ||
|
||
for INDEX in $(seq 0 2) | ||
do | ||
lxc network load-balancer backend add ${ROOTNAME}:ovntest ${NLB_VIP_ADDRESS} backend-0${INDEX} ${INSTANCE_IPS[${INDEX}]} 80,443 | ||
done | ||
|
||
lxc network load-balancer port add ovntest ${NLB_VIP_ADDRESS} tcp 80,443 backend-00,backend-01,backend-02 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
LXD_REMOTE=lxdcluster: | ||
OVNNETWORK=ovntest | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function echo_blue_bold() { | ||
# echo message in blue and bold | ||
echo -e "\x1B[90m= $(date '+%Y-%m-%d %T') \x1B[39m\x1B[1m\x1B[34m$@\x1B[0m\x1B[39m" | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function echo_blue_dot_title() { | ||
# echo message in blue and bold | ||
echo -n -e "\x1B[90m= $(date '+%Y-%m-%d %T') \x1B[39m\x1B[1m\x1B[34m$@\x1B[0m\x1B[39m" | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function echo_blue_dot() { | ||
echo -n -e "\x1B[90m\x1B[39m\x1B[1m\x1B[34m.\x1B[0m\x1B[39m" | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function launch_container() { | ||
local NAME=$1 | ||
local TARGET=$2 | ||
local CONTAINER_IP= | ||
|
||
echo_blue_bold "Create instance ${NAME}" | ||
|
||
lxc launch ubuntu:noble ${LXD_REMOTE}${NAME} --network=${OVNNETWORK} | ||
|
||
lxc exec ${LXD_REMOTE}${NAME} -- apt update | ||
lxc exec ${LXD_REMOTE}${NAME} -- bash -c 'DEBIAN_FRONTEND=noninteractive apt upgrade -y' | ||
lxc exec ${LXD_REMOTE}${NAME} -- apt install nginx -y | ||
|
||
echo_blue_dot_title "Wait ip instance ${LXD_REMOTE}${NAME}" | ||
|
||
while [ -z "${CONTAINER_IP}" ]; do | ||
CONTAINER_IP=$(lxc list ${LXD_REMOTE} name=${NAME} --format=json | jq -r '.[0].state.network|.eth0.addresses[]|select(.family == "inet")|.address') | ||
sleep 1 | ||
echo_blue_dot | ||
done | ||
echo | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# | ||
#=========================================================================================================================================== | ||
function container_ip() { | ||
local NAME=$1 | ||
|
||
lxc list ${LXD_REMOTE} name=${NAME} --format=json | jq -r '.[0].state.network|.eth0.addresses[]|select(.family == "inet")|.address' | ||
} | ||
|
||
#=========================================================================================================================================== | ||
# CREATE CONTAINERS | ||
#=========================================================================================================================================== | ||
|
||
launch_container u1 | ||
launch_container u2 | ||
|
||
U1_IP=$(container_ip u1) | ||
U2_IP=$(container_ip u2) | ||
|
||
#=========================================================================================================================================== | ||
# CREATE OVN LOAD BALANCER | ||
#=========================================================================================================================================== | ||
|
||
NLB_VIP_ADDRESS=$(lxc network load-balancer create ${LXD_REMOTE}${OVNNETWORK} --allocate=ipv4 | cut -d ' ' -f 4) | ||
|
||
echo_blue_bold "NLB_VIP_ADDRESS=${NLB_VIP_ADDRESS}" | ||
|
||
lxc network load-balancer backend add ${LXD_REMOTE}${OVNNETWORK} ${NLB_VIP_ADDRESS} u1 ${U1_IP} 80,443 | ||
lxc network load-balancer backend add ${LXD_REMOTE}${OVNNETWORK} ${NLB_VIP_ADDRESS} u2 ${U2_IP} 80,443 | ||
lxc network load-balancer port add ${LXD_REMOTE}${OVNNETWORK} ${NLB_VIP_ADDRESS} tcp 80,443 u1,u2 | ||
|
||
lxc ls | ||
|
||
curl http://${NLB_VIP_ADDRESS} | ||
|
Oops, something went wrong.