Skip to content

Commit

Permalink
Merge pull request #152 from nicolasbock/ovn_octavia
Browse files Browse the repository at this point in the history
Make ovn provider non-optional
  • Loading branch information
nicolasbock authored Nov 10, 2023
2 parents 1ad9b0b + bf458d5 commit b3654ef
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 65 deletions.
46 changes: 21 additions & 25 deletions openstack/pipeline/02configure
Original file line number Diff line number Diff line change
Expand Up @@ -419,26 +419,24 @@ do
if has_opt --openstack-dashboard*; then
MOD_OVERLAYS+=( "openstack/octavia-dashboard.yaml" )
fi
# no amphora if using ovn provider
if ! has_opt --octavia-ovn-provider; then
MOD_PARAMS[__AMPHORA_SSH_PUB_KEY__]="`get_amphora_ssh_pub_key`"
# This equates to m1.large (rather than m1.medium) which should
# allow creating 1x ubunu vm + 1x amphora vm on the same host thus
# avoiding the need for > 1 compute host.
MOD_PARAMS[__NOVA_COMPUTE_UNIT_CONSTRAINTS__]="mem=8G"
if ! has_opt --no-octavia-diskimage-retrofit; then
# By default we let retrofit use images uploaded by the post-deploy configure script.
MOD_OVERLAYS+=( "openstack/octavia-diskimage-retrofit.yaml" )
MOD_PARAMS[__OCTAVIA_RETROFIT_UCA__]=`get_ost_release`
if ! has_opt --octavia-diskimage-retrofit-glance-simplestreams; then
MOD_OVERLAYS+=( "openstack/octavia-diskimage-retrofit-glance.yaml" )
fi
MOD_PARAMS[__AMPHORA_SSH_PUB_KEY__]="`get_amphora_ssh_pub_key`"
# This equates to m1.large (rather than m1.medium) which should
# allow creating 1x ubunu vm + 1x amphora vm on the same host thus
# avoiding the need for > 1 compute host.
MOD_PARAMS[__NOVA_COMPUTE_UNIT_CONSTRAINTS__]="mem=8G"
if ! has_opt --no-octavia-diskimage-retrofit; then
# By default we let retrofit use images uploaded by the
# post-deploy configure script.
MOD_OVERLAYS+=( "openstack/octavia-diskimage-retrofit.yaml" )
MOD_PARAMS[__OCTAVIA_RETROFIT_UCA__]=`get_ost_release`
if ! has_opt --octavia-diskimage-retrofit-glance-simplestreams; then
MOD_OVERLAYS+=( "openstack/octavia-diskimage-retrofit-glance.yaml" )
fi
MOD_MSGS[octavia.0]="you need to to create an amphora image before you can use Octavia"
MOD_MSGS[octavia.1]="this can be done in one of two ways:"
MOD_MSGS[octavia.2]="run ./tools/upload_octavia_amphora_image.sh --release $release to use a pre-created image (recommended)"
MOD_MSGS[octavia.3]="create a new image with 'juju $JUJU_RUN_CMD octavia-diskimage-retrofit/0 retrofit-image source-image=<uuid>' with id of image in Glance to use as base"
fi
MOD_MSGS[octavia.0]="you need to to create an amphora image before you can use Octavia"
MOD_MSGS[octavia.1]="this can be done in one of two ways:"
MOD_MSGS[octavia.2]="run ./tools/upload_octavia_amphora_image.sh --release $release to use a pre-created image (recommended)"
MOD_MSGS[octavia.3]="create a new image with 'juju $JUJU_RUN_CMD octavia-diskimage-retrofit/0 retrofit-image source-image=<uuid>' with id of image in Glance to use as base"
if has_opt --octavia-ipv4; then
MOD_MSGS[octavia.4]="run tools/create_ipv4_octavia.sh"
fi
Expand All @@ -449,13 +447,11 @@ do
MOD_MSGS[octavia.9]="create loadbalancer i.e. ./tools/create_octavia_lb.sh --member-vm <uuid from prev step>"
MOD_MSGS[octavia.10]="alternatively manually create loadbalancer"
MOD_MSGS[octavia.11]="openstack loadbalancer create --name lb2 --vip-network-id lb-mgmt"
;;
--octavia-ovn-provider)
MOD_OVERLAYS+=( "openstack/octavia-ovn-provider.yaml" )
assert_min_release victoria octavia-ovn-provider
# ensure octavia and ovn
set -- $@ --octavia && cache $@
set -- $@ --ml2-ovn && cache $@
if has_min_release victoria; then
if is_ml2_ovn; then
MOD_OVERLAYS+=( "openstack/octavia-ovn-provider.yaml" )
fi
fi
;;
--octavia-ha*)
get_units $1 __NUM_OCTAVIA_UNITS__ 3
Expand Down
110 changes: 70 additions & 40 deletions openstack/tools/create_octavia_lb.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash -eux

lb=lb1
member_vm=
declare -a member_vm=()
provider=amphora
protocol=HTTP
protocol_port=80
hm_protocol=
Expand All @@ -21,7 +22,15 @@ while (( $# > 0 )); do
echo "missing member VM"
exit 1
fi
member_vm=$2
member_vm+=( "$2" )
shift
;;
--provider)
if (( $# < 2 )); then
echo "missing provider"
exit 1
fi
provider=$2
shift
;;
--protocol)
Expand All @@ -40,7 +49,7 @@ while (( $# > 0 )); do
protocol_port=$2
shift
;;
--healthmonitor-protocol)
--healthmonitor-protocol)
if (( $# < 2 )); then
echo "missing protocol for healthmonitor"
exit 1
Expand All @@ -52,14 +61,15 @@ while (( $# > 0 )); do
cat <<EOF
Usage:
$(basename $0) [options]
$(basename "$0") [options]
--name NAME The loadbalancer name base, default = $lb (things
--name NAME The loadbalancer name base, default = ${lb} (things
such as listener and pool are named using this base)
--member-vm NAME The name of the member VM. If not provided
use the first VM running.
--protocol PROTOCOL TCP, HTTP, ..., default = $protocol
--protocol-port PORT Port to use, default = $protocol_port
--member-vm NAME The name of the member VM. Can be used multiple times.
If not provided use the first VM running.
--provider PROVIDER The Octavia provider {amphora, ovn}, default = ${provider}
--protocol PROTOCOL TCP, HTTP, ..., default = ${protocol}
--protocol-port PORT Port to use, default = ${protocol_port}
EOF
exit 0
;;
Expand All @@ -70,27 +80,34 @@ EOF
esac
shift
done
if [ -z "$hm_protocol" ]; then
if [[ -z "$hm_protocol" ]]; then
hm_protocol=$protocol
fi
url_path=
if [[ ${hm_protocol} == HTTP ]]; then
url_path="--url-path /"
fi

`openstack loadbalancer list --column name --format value | \
grep -q $lb` && { echo "ERROR: a loadbalancer called $lb already exists"; exit 1; }
if openstack loadbalancer show ${lb} > /dev/null; then
echo "ERROR: a loadbalancer called $lb already exists"
exit 1
fi

LB_ID=$(openstack loadbalancer create --name $lb \
--vip-subnet-id private_subnet --format value --column id)
LB_ID=$(openstack loadbalancer create \
--name ${lb} \
--vip-subnet-id private_subnet \
--provider ${provider} \
--format value \
--column id)

# Re-run the following until $lb shows ACTIVE and ONLINE status':
openstack loadbalancer show ${LB_ID}

# wait for lb to be ACTIVE
while true; do
[[ `openstack loadbalancer show ${LB_ID} --column provisioning_status --format value` = ACTIVE ]] \
&& break
if [[ $(openstack loadbalancer show ${LB_ID} --column provisioning_status --format value) == ACTIVE ]]; then
break
fi
echo "waiting for $lb"
done

Expand All @@ -99,18 +116,27 @@ LISTENER_ID=$(openstack loadbalancer listener create \
--format value --column id $lb)
# wait for listener to be ACTIVE
while true; do
[[ `openstack loadbalancer listener show ${LISTENER_ID} --column provisioning_status --format value` = ACTIVE ]] \
&& break
if [[ $(openstack loadbalancer listener show ${LISTENER_ID} --column provisioning_status --format value) == ACTIVE ]]; then
break
fi
echo "waiting for ${lb}-listener"
done

LB_ALGORITHM=ROUND_ROBIN
if [[ ${provider} == ovn ]]; then
LB_ALGORITHM=SOURCE_IP_PORT
fi
POOL_ID=$(openstack loadbalancer pool create \
--name ${lb}-pool --lb-algorithm ROUND_ROBIN --listener ${LISTENER_ID} --protocol ${protocol} \
--name ${lb}-pool \
--lb-algorithm ${LB_ALGORITHM} \
--listener ${LISTENER_ID} \
--protocol ${protocol} \
--format value --column id)
# wait for pool to be ACTIVE
while true; do
[[ `openstack loadbalancer pool show ${POOL_ID} --column provisioning_status --format value` = ACTIVE ]] \
&& break
if [[ $(openstack loadbalancer pool show ${POOL_ID} --column provisioning_status --format value) == ACTIVE ]]; then
break
fi
echo "waiting for ${lb}-pool"
done

Expand All @@ -120,13 +146,13 @@ HM_ID=$(openstack loadbalancer healthmonitor create \
openstack loadbalancer healthmonitor list

# Add vm(s) to pool
if [ -z "$member_vm" ]; then
if (( ${#member_vm[@]} == 0 )); then
readarray -t member_vm < <(openstack server list --column ID --format value)
(( ${#member_vm[@]} )) || { echo "ERROR: could not find a vm to add to lb pool"; exit 1; }
fi

for member in ${member_vm[@]}; do
netaddr=$(openstack port list --server $member --network private --column "Fixed IP Addresses" --format value | \
for member in "${member_vm[@]}"; do
netaddr=$(openstack port list --server ${member} --network private --column "Fixed IP Addresses" --format value | \
sed -rn -e "s/.+ip_address='([[:digit:]\.]+)',\s+.+/\1/" \
-e "s/.+ip_address':\s+'([[:digit:]\.]+)'}.+/\1/p")
member_id=$(openstack loadbalancer member create --subnet-id private_subnet \
Expand All @@ -141,11 +167,20 @@ done

openstack loadbalancer member list ${POOL_ID}

floating_ip=$(openstack floating ip create --format value --column floating_ip_address ext_net)
lb_vip_port_id=$(openstack loadbalancer show --format value --column vip_port_id ${LB_ID})
openstack floating ip set --port $lb_vip_port_id $floating_ip

if [[ ${hm_protocol} != HTTP ]]; then
exit
fi

L7_POLICY1_ID=$(openstack loadbalancer l7policy create --action REDIRECT_TO_POOL \
--redirect-pool ${POOL_ID} --name ${lb}-l7policy1 --format value --column id ${LISTENER_ID})
while true; do
[[ $(openstack loadbalancer l7policy show ${L7_POLICY1_ID} --format value --column provisioning_status) = ACTIVE ]] \
&& break
if [[ $(openstack loadbalancer l7policy show ${L7_POLICY1_ID} --format value --column provisioning_status) == ACTIVE ]]; then
break
fi
echo "waiting for ${lb}-l7policy1"
done

Expand All @@ -154,8 +189,9 @@ openstack loadbalancer l7policy show ${L7_POLICY1_ID}
L7_RULE1_ID=$(openstack loadbalancer l7rule create --compare-type STARTS_WITH --type PATH \
--value /js --format value --column id ${L7_POLICY1_ID})
while true; do
[[ $(openstack loadbalancer l7rule show --format value --column provisioning_status ${L7_POLICY1_ID} ${L7_RULE1_ID}) = ACTIVE ]] \
&& break
if [[ $(openstack loadbalancer l7rule show --format value --column provisioning_status ${L7_POLICY1_ID} ${L7_RULE1_ID}) == ACTIVE ]]; then
break
fi
echo "waiting for ${L7_RULE1_ID}"
done

Expand All @@ -164,8 +200,9 @@ openstack loadbalancer l7rule show ${L7_POLICY1_ID} ${L7_RULE1_ID}
L7_POLICY2_ID=$(openstack loadbalancer l7policy create --action REDIRECT_TO_POOL \
--redirect-pool ${lb}-pool --name ${lb}-l7policy2 --format value --column id ${lb}-listener)
while true; do
[[ $(openstack loadbalancer l7policy show ${L7_POLICY2_ID} --format value --column provisioning_status) = ACTIVE ]] \
&& break
if [[ $(openstack loadbalancer l7policy show ${L7_POLICY2_ID} --format value --column provisioning_status) == ACTIVE ]]; then
break
fi
echo "waiting for ${lb}-l7policy2"
done

Expand All @@ -174,17 +211,10 @@ openstack loadbalancer l7policy show ${L7_POLICY2_ID}
L7_RULE2_ID=$(openstack loadbalancer l7rule create --compare-type STARTS_WITH --type PATH \
--value /images --format value --column id ${L7_POLICY2_ID})
while true; do
[[ $(openstack loadbalancer l7rule show --format value --column provisioning_status ${L7_POLICY2_ID} ${L7_RULE2_ID}) = ACTIVE ]] \
&& break
if [[ $(openstack loadbalancer l7rule show --format value --column provisioning_status ${L7_POLICY2_ID} ${L7_RULE2_ID}) == ACTIVE ]]; then
break
fi
echo "waiting for ${L7_RULE2_ID}"
done

openstack loadbalancer l7rule show ${L7_POLICY2_ID} ${L7_RULE2_ID}

floating_ip=$(openstack floating ip create --format value --column floating_ip_address ext_net)
lb_vip_port_id=$(openstack loadbalancer show --format value --column vip_port_id ${LB_ID})
openstack floating ip set --port $lb_vip_port_id $floating_ip

# Local Variables:
# sh-basic-offset: 4
# End:

0 comments on commit b3654ef

Please sign in to comment.