diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-04-21 16:21:26 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-04-21 16:21:42 +0200 |
commit | e4cc4b75a324068d35472382ea8a9bb297a24883 (patch) | |
tree | 2c8158313030d17225ed0ba0e4001ebb156a3a31 /python/vyos/ifconfig | |
parent | f69824153f794132943b361fe1e96064a55b83e1 (diff) | |
download | vyos-1x-e4cc4b75a324068d35472382ea8a9bb297a24883.tar.gz vyos-1x-e4cc4b75a324068d35472382ea8a9bb297a24883.zip |
macvlan: pseudo-ethernet: 2341: bugfix empty source-interface on system boot
Diffstat (limited to 'python/vyos/ifconfig')
-rw-r--r-- | python/vyos/ifconfig/macvlan.py | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/python/vyos/ifconfig/macvlan.py b/python/vyos/ifconfig/macvlan.py index 37228e57f..b5481f4a7 100644 --- a/python/vyos/ifconfig/macvlan.py +++ b/python/vyos/ifconfig/macvlan.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library. If not, see <http://www.gnu.org/licenses/>. +from copy import deepcopy from vyos.ifconfig.interface import Interface from vyos.ifconfig.vlan import VLAN @@ -27,6 +28,9 @@ class MACVLANIf(Interface): default = { 'type': 'macvlan', + 'address': '', + 'source_interface': '', + 'mode': '', } definition = { **Interface.definition, @@ -39,30 +43,28 @@ class MACVLANIf(Interface): ['source_interface', 'mode'] def _create(self): - cmd = 'ip link add {ifname} link {source_interface} type macvlan mode {mode}'.format( - **self.config) - self._cmd(cmd) + # please do not change the order when assembling the command + cmd = 'ip link add {ifname}' + if self.config['source_interface']: + cmd += ' link {source_interface}' + cmd += ' type macvlan' + if self.config['mode']: + cmd += ' mode {mode}' + self._cmd(cmd.format(**self.config)) - @staticmethod - def get_config(): + def set_mode(self, mode): + ifname = self.config['ifname'] + cmd = f'ip link set dev {ifname} type macvlan mode {mode}' + return self._cmd(cmd) + + @classmethod + def get_config(cls): """ - VXLAN interfaces require a configuration when they are added using - iproute2. This static method will provide the configuration dictionary - used by this class. + MACVLAN interfaces require a configuration when they are added using + iproute2. This method will provide the configuration dictionary used + by this class. Example: >> dict = MACVLANIf().get_config() """ - config = { - 'address': '', - 'source_interface': '', - 'mode': '' - } - return config - - def set_mode(self, mode): - """ - """ - ifname = self.config['ifname'] - cmd = f'ip link set dev {ifname} type macvlan mode {mode}' - return self._cmd(cmd) + return deepcopy(cls.default) |