Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add netplan config parding sh utility for ubuntu static ip #1026

Merged
merged 5 commits into from
Sep 11, 2024

Conversation

yaacov
Copy link
Member

@yaacov yaacov commented Sep 10, 2024

Add netplan config parding sh utility for ubuntu static ip

@yaacov yaacov marked this pull request as ready for review September 10, 2024 17:58
@yaacov yaacov requested a review from mnecas as a code owner September 10, 2024 17:58
@yaacov yaacov force-pushed the add-netplan-config-parsing branch from c36f80e to b0d181a Compare September 10, 2024 17:59
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@fa43dc5). Learn more about missing BASE report.
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1026   +/-   ##
=======================================
  Coverage        ?   16.47%           
=======================================
  Files           ?      107           
  Lines           ?    19645           
  Branches        ?        0           
=======================================
  Hits            ?     3237           
  Misses          ?    16117           
  Partials        ?      291           
Flag Coverage Δ
unittests 16.47% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@fabiand fabiand left a comment

Choose a reason for hiding this comment

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

GOLD for bash/dash yaml parsing.

But let's eval to use netplan generate or netplan get to avoid this parsing.

@fabiand
Copy link
Contributor

fabiand commented Sep 10, 2024

With the following script we loop over all configured interfaces and output the one for the given IP address

$ IP_TO_FIND=10.0.2.15
$ netplan get ethernets | grep -Eo "^[^[:space:]]+[^:]" | while read IFNAME  ; do netplan get ethernets.$IFNAME.addresses | grep -q $IP_TO_FIND && echo $IFNAME ; done

@yaacov yaacov force-pushed the add-netplan-config-parsing branch 4 times, most recently from 8fc6c77 to ec77001 Compare September 11, 2024 06:40
@yaacov yaacov force-pushed the add-netplan-config-parsing branch from ec77001 to c237860 Compare September 11, 2024 06:42
Comment on lines 36 to 38
while IFS= read -r line; do
echo "$line"
done < "$V2V_MAP_FILE"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is equal to cat $V2V_MAP_FILE as we just echo every line without modifications.

In the original code I was modifying the line to convert them into ENV_KEY=VALUE format to then export them iwth export

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks ! replaced ...

# Loop through all interfaces and check for the given IP address
netplan_get ethernets | grep -Eo "^[^[:space:]]+[^:]" | while read IFNAME; do
if netplan_get ethernets."$IFNAME".addresses | grep -q "$target_ip"; then
echo "$IFNAME"
Copy link
Contributor

Choose a reason for hiding this comment

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

either we should return here
or later we need to check that we only found one ifname

Copy link
Member Author

Choose a reason for hiding this comment

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

added return here


# If S_HW and S_IP were not extracted, skip the line
if [ -z "$S_HW" ] || [ -z "$S_IP" ]; then
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

worth adding a log message?

Copy link
Member Author

Choose a reason for hiding this comment

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

added logs for invalid mac to ip lines


# If no interface is found, skip this entry
if [ -z "$interface_name" ]; then
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

worth adding a log message?

Copy link
Member Author

Choose a reason for hiding this comment

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

added logs for device not found

Copy link

@mnecas mnecas merged commit 9c75aca into kubev2v:main Sep 11, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants