summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-08-26 22:43:53 +0200
committerGitHub <noreply@github.com>2019-08-26 22:43:53 +0200
commit4d8eddc6ddae516f7ef988ad58bcd0e13f184c11 (patch)
tree4be28667d3f9b41d7595935e3836986e84233348 /src/conf_mode
parent27cc65e8a25412944d2bd2c0ee7cf13dff98e1a4 (diff)
parent10e5e6acf6711149c7502e5fbb3de6a75ede1adf (diff)
downloadvyos-1x-4d8eddc6ddae516f7ef988ad58bcd0e13f184c11.tar.gz
vyos-1x-4d8eddc6ddae516f7ef988ad58bcd0e13f184c11.zip
Merge pull request #118 from c-po/pyroute2
loopback: T1601: migrate to pyroute2
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-xsrc/conf_mode/interface-bridge.py2
-rwxr-xr-xsrc/conf_mode/interface-loopback.py42
2 files changed, 26 insertions, 18 deletions
diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py
index d5ef85940..85ea68e26 100755
--- a/src/conf_mode/interface-bridge.py
+++ b/src/conf_mode/interface-bridge.py
@@ -247,7 +247,7 @@ def apply(bridge):
if bridge['disable']:
br.down()
- # commit change son bridge interface
+ # commit changes on bridge interface
br.commit()
# configure additional bridge member options
diff --git a/src/conf_mode/interface-loopback.py b/src/conf_mode/interface-loopback.py
index 445a9af64..5c1419b11 100755
--- a/src/conf_mode/interface-loopback.py
+++ b/src/conf_mode/interface-loopback.py
@@ -14,14 +14,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-#
-
-import os
-import sys
-import copy
-
-import vyos.configinterface as VyIfconfig
+from os import environ
+from sys import exit
+from copy import deepcopy
+from pyroute2 import IPDB
from vyos.config import Config
from vyos import ConfigError
@@ -37,12 +34,12 @@ def diff(first, second):
return [item for item in first if item not in second]
def get_config():
- loopback = copy.deepcopy(default_config_data)
+ loopback = deepcopy(default_config_data)
conf = Config()
# determine tagNode instance
try:
- loopback['intf'] = os.environ['VYOS_TAGNODE_VALUE']
+ loopback['intf'] = environ['VYOS_TAGNODE_VALUE']
except KeyError as E:
print("Interface not specified")
@@ -60,6 +57,8 @@ def get_config():
# retrieve interface description
if conf.exists('description'):
loopback['description'] = conf.return_value('description')
+ else:
+ loopback['description'] = loopback['intf']
# Determine interface addresses (currently effective) - to determine which
# address is no longer valid and needs to be removed from the interface
@@ -76,19 +75,28 @@ def generate(loopback):
return None
def apply(loopback):
- # Remove loopback interface
+ ipdb = IPDB(mode='explicit')
+ lo_if = loopback['intf']
+
+ # the loopback device always exists
+ lo = ipdb.interfaces[lo_if]
+ # begin() a transaction prior to make any change
+ lo.begin()
+
if not loopback['deleted']:
# update interface description used e.g. within SNMP
- VyIfconfig.set_description(loopback['intf'], loopback['description'])
-
- # Configure interface address(es)
+ # update interface description used e.g. within SNMP
+ lo.ifalias = loopback['description']
+ # configure interface address(es)
for addr in loopback['address']:
- VyIfconfig.add_interface_address(loopback['intf'], addr)
+ lo.add_ip(addr)
- # Remove interface address(es)
+ # remove interface address(es)
for addr in loopback['address_remove']:
- VyIfconfig.remove_interface_address(loopback['intf'], addr)
+ lo.del_ip(addr)
+ # commit changes on loopback interface
+ lo.commit()
return None
if __name__ == '__main__':
@@ -99,4 +107,4 @@ if __name__ == '__main__':
apply(c)
except ConfigError as e:
print(e)
- sys.exit(1)
+ exit(1)