<commit_before>#!/bin/bash

get_orig_ips() {
    local br_name
    br_name=${1:-br-mgmt}
    echo $(fuel nodes --env-id $ORIG_ENV \
        | grep controller \
        | cut -d\| -f5  \
        | xargs -I{} ssh root@{} ip addr\
        | awk '/'$br_name':/ {getline; getline; print $2}' \
        | sed -re 's%([^/]+)/[0-9]{2}%\1%')
}

get_orig_vip() {
    local br_name
    local orig_vip
    br_name=$(echo ${1:-br-mgmt} \
        | awk '/br-ex/ {print "hapr-p"} \
        /br-mgmt/ {print "hapr-m"}')
    [ -n "$br_name" ] && echo $(fuel nodes --env-id 1 \
            | grep controller \
            | cut -d\| -f5  \
            | xargs -I{} ssh root@{} ip netns exec haproxy ip addr\
            | awk '/'$br_name':/ {getline; getline; print $2}' \
            | sed -re 's%([^/]+)/[0-9]{2}%\1%')
}

get_deployment_info() {
# Download deployment config from Fuel master for environment ENV to subdir in
# current directory. Skip download if the directory already exists.
    test -d ./deployment_${ENV} || fuel --env ${ENV} deployment default
}

get_new_ips() {
    local br_name
    br_name=${1:-br-mgmt}
    echo $(grep -A2 $br_name: ./deployment_${ENV}/*controller* \
        | sed -nre 's%.*- (([0-9]{1,3}\.){3}[0-9]{1,3})/[0-9]{1,2}.*%\1%p')
}

get_new_vip() {
    local br_name
    br_name=$(echo ${1:-br-mgmt} \
        | awk '/br-ex/ {print "public_vip:"} \
        /br-mgmt/ {print "management_vip:"}')
    [ -n $br_name ] && echo $(grep $br_name ./deployment_${ENV}/*controller* \
        | awk '{print $2}')
}

upload_deployment_info() {
# Upload deployment configration with modifications to Fuel master for
# environment ENV.
    test -d ./deployment_${ENV} && fuel --env ${ENV} deployment upload
}

replace_ip_addresses() {
# Replace IP addresses assigned to new env's controllers and VIPs with addresses
# of the original environment in deployment config dump.
    local dirname
    local br_name
    local orig_ips
    local orig_vip
    local new_ip
    br_name=$1
    shift
    dirname=deployment_${ENV}
    orig_ips=$(get_orig_ips $br_name)
    for orig_ip in $orig_ips
        do
            if [ -n "$*" ]
                then
                    new_ip=$1
                    sed -i "s%$new_ip%$orig_ip%" $dirname/*.yaml
                    shift
                fi
        done
    orig_vip=$(get_orig_vip $br_name)
    new_vip=$(get_new_vip $br_name)
    sed -i "s%$new_vip%$orig_vip%" $dirname/*.yaml
}

remove_patch_transformations() {
    python ../helpers/transformations.py deployment_${ENV}
}

prepare_deployment_info() {
# Prepare deployment configuration of Fuel environment.
    local br_name
    local discard_ips
    get_deployment_info
    discard_ips=$(get_new_ips)
    for br_name in br-ex br-mgmt
        do
            replace_ip_addresses $br_name $discard_ips
# TODO(ogelbukh): implement function to remove patch port create action from
# transformations section of deployment config. These actions must be stored
# somewhere to create those patch ports when lift isolation.
#            remove_patch_transformation $br_name
        done
    remove_patch_transformations
    upload_deployment_info
}

create_controllers_file() {
# This is the list of controller nodes for environment ENV. It is used to run
# parallel SSH commands on controllers.
    fuel node --env $ENV | grep controller | awk '{print "node-" $1}' \
        > controllers
}

prepare_static_files() {
# Prepare static configuration files for controllers, and the list of
# controllers in the environment.
    create_controllers_file
}

create_bridge() {
    local br_name
    br_name=$1
    $PSSH_RUN "ovs-vsctl add-br $br_name"
}

create_ovs_bridges() {<commit_msg>Select IPs to replace depending on bridge name<commit_after>#!/bin/bash

get_orig_ips() {
    local br_name
    br_name=${1:-br-mgmt}
    echo $(fuel nodes --env-id $ORIG_ENV \
        | grep controller \
        | cut -d\| -f5  \
        | xargs -I{} ssh root@{} ip addr\
        | awk '/'$br_name':/ {getline; getline; print $2}' \
        | sed -re 's%([^/]+)/[0-9]{2}%\1%')
}

get_orig_vip() {
    local br_name
    local orig_vip
    br_name=$(echo ${1:-br-mgmt} \
        | awk '/br-ex/ {print "hapr-p"} \
        /br-mgmt/ {print "hapr-m"}')
    [ -n "$br_name" ] && echo $(fuel nodes --env-id $ORIG_VIP \
            | grep controller \
            | cut -d\| -f5  \
            | xargs -I{} ssh root@{} ip netns exec haproxy ip addr\
            | awk '/'$br_name':/ {getline; getline; print $2}' \
            | sed -re 's%([^/]+)/[0-9]{2}%\1%')
}

get_deployment_info() {
# Download deployment config from Fuel master for environment ENV to subdir in
# current directory. Skip download if the directory already exists.
    test -d ./deployment_${ENV} || fuel --env ${ENV} deployment default
}

get_new_ips() {
    local br_name
    br_name=${1:-br-mgmt}
    echo $(grep -A2 $br_name: ./deployment_${ENV}/*controller* \
        | sed -nre 's%.*- (([0-9]{1,3}\.){3}[0-9]{1,3})/[0-9]{1,2}.*%\1%p')
}

get_new_vip() {
    local br_name
    br_name=$(echo ${1:-br-mgmt} \
        | awk '/br-ex/ {print "public_vip:"} \
        /br-mgmt/ {print "management_vip:"}')
    [ -n $br_name ] && echo $(grep $br_name ./deployment_${ENV}/*controller* \
        | awk '{print $2}')
}

upload_deployment_info() {
# Upload deployment configration with modifications to Fuel master for
# environment ENV.
    test -d ./deployment_${ENV} && fuel --env ${ENV} deployment upload
}

replace_ip_addresses() {
# Replace IP addresses assigned to new env's controllers and VIPs with addresses
# of the original environment in deployment config dump.
    local dirname
    local br_name
    local orig_ips
    local orig_vip
    local new_ip
    br_name=$1
    shift
    dirname=deployment_${ENV}
    orig_ips=$(get_orig_ips $br_name)
    for orig_ip in $orig_ips
        do
            if [ -n "$*" ]
                then
                    new_ip=$1
                    sed -i "s%$new_ip%$orig_ip%" $dirname/*.yaml
                    shift
                fi
        done
    orig_vip=$(get_orig_vip $br_name)
    new_vip=$(get_new_vip $br_name)
    sed -i "s%$new_vip%$orig_vip%" $dirname/*.yaml
}

remove_patch_transformations() {
    python ../helpers/transformations.py deployment_${ENV}
}

prepare_deployment_info() {
# Prepare deployment configuration of Fuel environment.
    local br_name
    local discard_ips
    get_deployment_info
    for br_name in br-ex br-mgmt
        do
            discard_ips=$(get_new_ips $br_name)
            replace_ip_addresses $br_name $discard_ips
        done
    remove_patch_transformations
    upload_deployment_info
}

create_controllers_file() {
# This is the list of controller nodes for environment ENV. It is used to run
# parallel SSH commands on controllers.
    fuel node --env $ENV | grep controller | awk '{print "node-" $1}' \
        > controllers
}

prepare_static_files() {
# Prepare static configuration files for controllers, and the list of
# controllers in the environment.
    create_controllers_file
}

create_bridge() {
    local br_name
    br_name=$1
    $PSSH_RUN "ovs-vsctl add-br $br_name"
}

create_ovs_bridges() {
{'fraction_non_alphanumeric': 0.1363699874248987, 'fraction_numerical': 0.01019980438731312, 'mean_word_length': 2.493411420204978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3385618', 'n_tokens_mistral': 2519, 'n_tokens_neox': 2432, 'n_words': 649}