-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add function to retrieve docker0 ipv4 and ipv6 addresses #15606
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import glob | ||
import os | ||
import subprocess | ||
import netifaces | ||
|
||
from natsort import natsorted | ||
from swsscommon import swsscommon | ||
|
@@ -484,3 +485,26 @@ def get_asic_presence_list(): | |
# asic is asid id: asic0, asic1.... asicN. Get the numeric value. | ||
asics_list.append(int(get_asic_id_from_name(asic))) | ||
return asics_list | ||
|
||
def get_docker0_ip(): | ||
""" | ||
@summary: This function will return docker0 ipv4 and ipv6 addresses | ||
for multi_asic platform. | ||
This function will return None for single asic platform. | ||
@return: tuple containing docker0 ipv4 and ipv6 address | ||
""" | ||
docker0_v4 = None | ||
docker0_v6 = None | ||
|
||
# return (None, None) for single asic platform | ||
if not is_multi_asic(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helper function is added so that we could use this to get docker0 ip for multi-asic platform. |
||
return (docker0_v4, docker0_v6) | ||
|
||
interfaces = netifaces.interfaces() | ||
if "docker0" in interfaces: | ||
addresses = netifaces.ifaddresses("docker0") | ||
if netifaces.AF_INET in addresses: | ||
docker0_v4 = addresses[netifaces.AF_INET][0]['addr'] | ||
if netifaces.AF_INET6 in addresses: | ||
docker0_v6 = addresses[netifaces.AF_INET6][0]['addr'] | ||
return (docker0_v4, docker0_v6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_docker0_ips