Mohammed Naser | 62c4dd9 | 2025-02-16 13:18:14 -0500 | [diff] [blame] | 1 | From 6c2dac4c0bcd71d400c113b922ba862d7945a09e Mon Sep 17 00:00:00 2001 |
| 2 | From: Mohammed Naser <mnaser@vexxhost.com> |
| 3 | Date: Mon, 17 Feb 2025 11:00:30 -0500 |
| 4 | Subject: [PATCH] Switch OVN to ovsinit |
| 5 | |
| 6 | --- |
| 7 | ovn/templates/bin/_ovn-controller-init.sh.tpl | 55 +------------------ |
| 8 | 1 file changed, 2 insertions(+), 53 deletions(-) |
| 9 | |
| 10 | diff --git a/ovn/templates/bin/_ovn-controller-init.sh.tpl b/ovn/templates/bin/_ovn-controller-init.sh.tpl |
| 11 | index 357c069d..006582f9 100644 |
| 12 | --- a/ovn/templates/bin/_ovn-controller-init.sh.tpl |
| 13 | +++ b/ovn/templates/bin/_ovn-controller-init.sh.tpl |
| 14 | @@ -25,58 +25,6 @@ function get_ip_address_from_interface { |
| 15 | echo ${ip} |
| 16 | } |
| 17 | |
| 18 | -function get_ip_prefix_from_interface { |
| 19 | - local interface=$1 |
| 20 | - local prefix=$(ip -4 -o addr s "${interface}" | awk '{ print $4; exit }' | awk -F '/' 'NR==1 {print $2}') |
| 21 | - if [ -z "${prefix}" ] ; then |
| 22 | - exit 1 |
| 23 | - fi |
| 24 | - echo ${prefix} |
| 25 | -} |
| 26 | - |
| 27 | -function migrate_ip_from_nic { |
| 28 | - src_nic=$1 |
| 29 | - bridge_name=$2 |
| 30 | - |
| 31 | - # Enabling explicit error handling: We must avoid to lose the IP |
| 32 | - # address in the migration process. Hence, on every error, we |
| 33 | - # attempt to assign the IP back to the original NIC and exit. |
| 34 | - set +e |
| 35 | - |
| 36 | - ip=$(get_ip_address_from_interface ${src_nic}) |
| 37 | - prefix=$(get_ip_prefix_from_interface ${src_nic}) |
| 38 | - |
| 39 | - bridge_ip=$(get_ip_address_from_interface "${bridge_name}") |
| 40 | - bridge_prefix=$(get_ip_prefix_from_interface "${bridge_name}") |
| 41 | - |
| 42 | - ip link set ${bridge_name} up |
| 43 | - |
| 44 | - if [[ -n "${ip}" && -n "${prefix}" ]]; then |
| 45 | - ip addr flush dev ${src_nic} |
| 46 | - if [ $? -ne 0 ] ; then |
| 47 | - ip addr add ${ip}/${prefix} dev ${src_nic} |
| 48 | - echo "Error while flushing IP from ${src_nic}." |
| 49 | - exit 1 |
| 50 | - fi |
| 51 | - |
| 52 | - ip addr add ${ip}/${prefix} dev "${bridge_name}" |
| 53 | - if [ $? -ne 0 ] ; then |
| 54 | - echo "Error assigning IP to bridge "${bridge_name}"." |
| 55 | - ip addr add ${ip}/${prefix} dev ${src_nic} |
| 56 | - exit 1 |
| 57 | - fi |
| 58 | - elif [[ -n "${bridge_ip}" && -n "${bridge_prefix}" ]]; then |
| 59 | - echo "Bridge '${bridge_name}' already has IP assigned. Keeping the same:: IP:[${bridge_ip}]; Prefix:[${bridge_prefix}]..." |
| 60 | - elif [[ -z "${bridge_ip}" && -z "${ip}" ]]; then |
| 61 | - echo "Interface and bridge have no ips configured. Leaving as is." |
| 62 | - else |
| 63 | - echo "Interface ${src_nic} has invalid IP address. IP:[${ip}]; Prefix:[${prefix}]..." |
| 64 | - exit 1 |
| 65 | - fi |
| 66 | - |
| 67 | - set -e |
| 68 | -} |
| 69 | - |
| 70 | function get_current_system_id { |
| 71 | ovs-vsctl --if-exists get Open_vSwitch . external_ids:system-id | tr -d '"' |
| 72 | } |
| 73 | @@ -174,6 +122,7 @@ do |
| 74 | if [ -n "$iface" ] && [ "$iface" != "null" ] && ( ip link show $iface 1>/dev/null 2>&1 ); |
| 75 | then |
| 76 | ovs-vsctl --may-exist add-port $bridge $iface |
| 77 | - migrate_ip_from_nic $iface $bridge |
| 78 | fi |
| 79 | done |
| 80 | + |
| 81 | +/usr/local/bin/ovsinit /tmp/auto_bridge_add |
| 82 | -- |
| 83 | 2.47.0 |
| 84 | |