diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-09-20 15:18:50 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-09-20 15:18:50 +0200 |
commit | 103e8404cdea70dad486940f209b9683f1c7b936 (patch) | |
tree | e8f18c41978d0dbb05ed9b61fe2db62402a809d3 /python/vyos/ifconfig/interface.py | |
parent | 993f6873c02f3f79013acedfe61ce705bdb3a4d0 (diff) | |
download | vyos-1x-103e8404cdea70dad486940f209b9683f1c7b936.tar.gz vyos-1x-103e8404cdea70dad486940f209b9683f1c7b936.zip |
ifconfig: T2653: remove duplicates of get_config()
A lot of derived classes from Interface implemented their own get_config()
method which more or less was the same everywhere. We also hat different
qualifiers like @staticmethod or @classmethod.
This is now changed to only have the @classmethod in Interface base class which
will return the necessary dictionary keys for the required interfaces. This
change is a mid reduction in lines of code which is always a very nice thing!
Diffstat (limited to 'python/vyos/ifconfig/interface.py')
-rw-r--r-- | python/vyos/ifconfig/interface.py | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 4e420dc1d..807191b3d 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -174,6 +174,15 @@ class Interface(Control): def exists(cls, ifname): return os.path.exists(f'/sys/class/net/{ifname}') + @classmethod + def get_config(cls): + """ + Some but not all interfaces require a configuration when they are added + using iproute2. This method will provide the configuration dictionary + used by this class. + """ + return deepcopy(cls.default) + def __init__(self, ifname, **kargs): """ This is the base interface class which supports basic IP/MAC address @@ -1084,7 +1093,7 @@ class VLANIf(Interface): def _create(self): # bail out early if interface already exists - if os.path.exists(f'/sys/class/net/{self.ifname}'): + if self.exists(f'{self.ifname}'): return cmd = 'ip link add link {source_interface} name {ifname} type vlan id {vlan_id}' @@ -1100,20 +1109,6 @@ class VLANIf(Interface): # interface is always A/D down. It needs to be enabled explicitly self.set_admin_state('down') - @staticmethod - def get_config(): - """ - MACsec interfaces require a configuration when they are added using - iproute2. This static method will provide the configuration dictionary - used by this class. - - Example: - >> dict = VLANIf().get_config() - """ - config = deepcopy(__class__.default) - del config['type'] - return config - def set_admin_state(self, state): """ Set interface administrative state to be 'up' or 'down' |