diff options
author | Viacheslav <v.gletenko@vyos.io> | 2021-07-02 13:43:27 +0000 |
---|---|---|
committer | Viacheslav <v.gletenko@vyos.io> | 2021-07-02 13:43:27 +0000 |
commit | 4e1a5c7cf4213fd5617e387a2d4a6d1e9a475c54 (patch) | |
tree | 59219bc423e0b53e5c39f697c5696d18d676e60b /python/vyos/ifconfig/interface.py | |
parent | cef8147afd1d031c91cc90b7642aad8ae372c81b (diff) | |
download | vyos-1x-4e1a5c7cf4213fd5617e387a2d4a6d1e9a475c54.tar.gz vyos-1x-4e1a5c7cf4213fd5617e387a2d4a6d1e9a475c54.zip |
conntrack-sync: T3535: Rewrite conf and op modes to XML python style
Diffstat (limited to 'python/vyos/ifconfig/interface.py')
-rw-r--r-- | python/vyos/ifconfig/interface.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 40bff7c3d..fb658bd61 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -732,6 +732,24 @@ class Interface(Control): """ self.set_interface('proxy_arp_pvlan', enable) + def get_addr_v4(self): + """ + Retrieve assigned IPv4 addresses from given interface. + This is done using the netifaces and ipaddress python modules. + Example: + >>> from vyos.ifconfig import Interface + >>> Interface('eth0').get_addr_v4() + ['172.16.33.30/24'] + """ + ipv4 = [] + if AF_INET in ifaddresses(self.config['ifname']): + for v4_addr in ifaddresses(self.config['ifname'])[AF_INET]: + # we need to manually assemble a list of IPv4 address/prefix + prefix = '/' + \ + str(IPv4Network('0.0.0.0/' + v4_addr['netmask']).prefixlen) + ipv4.append(v4_addr['addr'] + prefix) + return ipv4 + def get_addr(self): """ Retrieve assigned IPv4 and IPv6 addresses from given interface. |