diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-06-30 14:19:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 14:19:38 -0400 |
commit | 882f1a5f2d5bafd08e6900a2782c3affa67c9d86 (patch) | |
tree | 9cd90da0ae7068b3326617d093680ea7b5866cb8 /cloudinit/distros/networking.py | |
parent | 66e114a660c53400e389f119781f378311b65108 (diff) | |
download | vyos-cloud-init-882f1a5f2d5bafd08e6900a2782c3affa67c9d86.tar.gz vyos-cloud-init-882f1a5f2d5bafd08e6900a2782c3affa67c9d86.zip |
networking: refactor is_physical from cloudinit.net (#457)
As the first refactor PR, this also includes the initial structure for tests.
LP: #1884619
Diffstat (limited to 'cloudinit/distros/networking.py')
-rw-r--r-- | cloudinit/distros/networking.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/cloudinit/distros/networking.py b/cloudinit/distros/networking.py index eecdccc6..e421a2ce 100644 --- a/cloudinit/distros/networking.py +++ b/cloudinit/distros/networking.py @@ -1,4 +1,5 @@ import abc +import os from cloudinit import net @@ -79,8 +80,15 @@ class Networking(metaclass=abc.ABCMeta): def is_bridge(self, devname: DeviceName) -> bool: return net.is_bridge(devname) + @abc.abstractmethod def is_physical(self, devname: DeviceName) -> bool: - return net.is_physical(devname) + """ + Is ``devname`` a physical network device? + + Examples of non-physical network devices: bonds, bridges, tunnels, + loopback devices. + """ + pass def is_renamed(self, devname: DeviceName) -> bool: return net.is_renamed(devname) @@ -103,7 +111,8 @@ class Networking(metaclass=abc.ABCMeta): class BSDNetworking(Networking): """Implementation of networking functionality shared across BSDs.""" - pass + def is_physical(self, devname: DeviceName) -> bool: + raise NotImplementedError() class LinuxNetworking(Networking): @@ -126,3 +135,6 @@ class LinuxNetworking(Networking): def is_netfail_standby(self, devname: DeviceName) -> bool: return net.is_netfail_standby(devname) + + def is_physical(self, devname: DeviceName) -> bool: + return os.path.exists(net.sys_dev_path(devname, "device")) |