Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ansible/roles/test/files/helpers/change_mac.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash

for i in $(ifconfig | grep eth | cut -f 1 -d ' ')
do
prefix=$(ifconfig $i | grep HWaddr | cut -c39-53)
suffix=$( printf "%02x" ${i##eth})
mac=$prefix$suffix
echo $i $mac
ifconfig $i hw ether $mac
set -e

for INTF in $(ip -br link show | grep 'eth' | awk '{sub(/@.*/,"",$1); print $1}'); do
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using capital letters for a parameter name? i don't think this is the convention used in the different scripts.
Any reason why not keeping the names as before? prefix, suffix, mac, addr, etc.
Beside of that i agree we should not use ifconfig any more but only ip commands.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the codebase is currently inconsistent; you will find usage of both all-caps and all-lowercase variable names. I personally prefer all-caps for variable names in bash.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jleveque could you please merge this if no more concerns?

ADDR="$(ip -br link show dev ${INTF} | awk '{print $3}')"
PREFIX="$(cut -c1-15 <<< ${ADDR})"
SUFFIX="$(printf "%02x" ${INTF##eth})"
MAC="${PREFIX}${SUFFIX}"

echo "Update ${INTF} MAC address: ${ADDR}->$MAC"
ip link set dev ${INTF} address ${MAC}
done
5 changes: 3 additions & 2 deletions ansible/roles/test/files/helpers/remove_ip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -e

for i in `cat /proc/net/dev | grep eth | awk -F'eth|:' '{print $2}'`; do
ip address flush dev eth$i
for INTF in $(ip -br link show | grep 'eth' | awk '{sub(/@.*/,"",$1); print $1}'); do
echo "Flush ${INTF} IP address"
ip addr flush dev ${INTF}
done