Skip to content
Snippets Groups Projects
Commit 5dcc2fdf authored by Alex ubuntu vm's avatar Alex ubuntu vm
Browse files

repo: added new directory where utils scripts will be

Added as a complement two scripts:

- one configVxlans.sh takes the file from config/switchConfig.json and initiates the configuration in each switch in the cluster
- generateConfig.sh generates a sample file in switchConfig.sh, interconnecting all nodes with all
parent f4455081
No related branches found
No related tags found
1 merge request!2repo: added new directory where utils scripts will be
#!/bin/bash
# Path to the configuration file
configFilePath="./configs/switchConfig.json"
# Use kubectl to get pods and grep for those starting with 'l2sm-switch'
# Then, use awk to extract the pod name and node name by matching an IP pattern and taking the next column as the node
mapfile -t podInfo < <(kubectl get pods -o wide | grep 'l2sm-switch' | awk '{for (i=1; i<=NF; i++) { if ($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) { print $1 ":" $(i+1); break; } }}')
# Declare an associative array to store pod names and their respective nodes
declare -A pods
# Fill the associative array with pod names as keys and node names as values
for entry in "${podInfo[@]}"
do
podName="${entry%%:*}"
nodeName="${entry##*:}"
pods["$podName"]=$nodeName
done
# Loop through the array
for pod in "${!pods[@]}"
do
nodeName=${pods[$pod]}
# Copy the configuration file to the pod
echo "Copying config file to $pod..."
kubectl cp "$configFilePath" "$pod:/etc/l2sm/switchConfig.json"
# Execute the script inside the pod
echo "Executing configuration script on $pod..."
kubectl exec -it "$pod" -- /bin/bash -c "l2sm-vxlans --node_name=$nodeName /etc/l2sm/switchConfig.json"
done
echo "Configuration deployment completed."
#!/bin/bash
# Filename for the JSON config
jsonConfigPath="./configs/switchConfig.json"
# Use kubectl to get pods, grep for those starting with 'l2sm-switch', and parse with awk
mapfile -t podInfo < <(kubectl get pods -o wide | grep 'l2sm-switch' | awk '{for (i=1; i<=NF; i++) { if ($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) { print $(i+1) ":" $i; break; } }}')
# Associative array to store node names and their respective IPs
declare -A nodeIPs
# Fill the associative array with node names as keys and IPs as values
for entry in "${podInfo[@]}"
do
nodeName="${entry%%:*}"
nodeIP="${entry##*:}"
nodeIPs["$nodeName"]=$nodeIP
done
# Prepare Nodes array
nodesArray=()
for nodeName in "${!nodeIPs[@]}"
do
nodesArray+=("{\"name\": \"$nodeName\", \"nodeIP\": \"${nodeIPs[$nodeName]}\"}")
done
# Prepare Links array
linksArray=()
declare -A linkPairs
for srcNode in "${!nodeIPs[@]}"
do
for dstNode in "${!nodeIPs[@]}"
do
if [[ "$srcNode" != "$dstNode" && -z ${linkPairs["$srcNode:$dstNode"]} && -z ${linkPairs["$dstNode:$srcNode"]} ]]; then
linksArray+=("{\"endpointA\": \"$srcNode\", \"endpointB\": \"$dstNode\"}")
linkPairs["$srcNode:$dstNode"]=1
fi
done
done
# Generate JSON output
echo "{
\"Nodes\": [
$(IFS=,; echo "${nodesArray[*]}")
],
\"Links\": [
$(IFS=,; echo "${linksArray[*]}")
]
}" > $jsonConfigPath
echo "Network topology configuration has been generated at $jsonConfigPath."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment