Page MenuHomePhabricator

Create generic abstraction for configuring interfaces e.g. IP address
Needs testing, NormalPublicFEATURE REQUEST


Right now there is no generic way in configuring an interface IP address from within a Python script.

The only occurance right now is in

def add_addr(intf, addr):
  # see
  ret =['ip a a dev ' + intf + ' ' + addr + ' &>/dev/null'], shell=True)
  sl.syslog(sl.LOG_NOTICE, "ip a a dev " + intf + " " + addr)

def del_addr(intf, addr):
  ret =['ip a d dev ' + intf + ' ' + addr + ' &>/dev/null'], shell=True)
  sl.syslog(sl.LOG_NOTICE, "ip a d dev " + intf + " " + addr)

We need to make this available in the generic vyos python library or a proper 3rd party library to be reusable from within multiple scripts.


  • add IPv4/IPv6 interface address
  • remove IPv4/IPv6 interface address
  • add DHCP/DHCPv6 interface address
  • remove DHCP/DHCPv6 interface address
  • add interface description /sys/class/net/eth0/ifalias


Difficulty level
Hard (possibly days)
Why the issue appeared?
Will be filled on close

Event Timeline

c-po created this task.Thu, Aug 1, 10:46 AM
hagbard added a subscriber: hagbard.EditedFri, Aug 2, 5:57 PM

disable (up/down) is required too.
DHCP might be called from the class, but I think it makes sense to give it to networkd, since it can detect interface up/down and triggers the dhcp client again if needed or releases the IP.

hagbard added a comment.EditedFri, Aug 2, 8:49 PM

I started with a few line of example code, if that would be something we wanna go with, I'll take the task. comments always welcome.

runar added a subscriber: runar.Sat, Aug 3, 9:09 AM

This is a good start! The names should be made pythonic and why not use getters and setters? Then we dont need set_ functions but use the objects directly.

We also can couple it with something like this ? Make a all in one ip/tunnel/bridge/bond config library

hagbard claimed this task.Sun, Aug 4, 3:26 AM
hagbard changed the task status from Open to In progress.Tue, Aug 6, 4:38 PM

I'd like to make it more generic anyway, so basically it will be come a wrapper for the ip commands plus some check/find function maybe (like what mac belongs to what interface, bonding etc).

pasik added a subscriber: pasik.Wed, Aug 7, 7:38 PM
hagbard triaged this task as Normal priority.Wed, Aug 7, 8:06 PM
hagbard changed Difficulty level from Unknown (require assessment) to Hard (possibly days).

I have almost all requested stuff implemented, plus some more like setting mtu, mac address etc. I'm planning to include that into vyos-1x after testing.

dhcp can be done via systemd or the traditional isc-dhcp client, which way should we go? systemd.networkd does link detection too and stops dhcp if the link is lost and starts it again when the link returns to state up.

Aug  8 16:01:36 vyos systemd[1]: Starting Network Service...
Aug  8 16:01:36 vyos systemd-networkd[2370]: eth3            : gained carrier
Aug  8 16:01:36 vyos systemd-networkd[2370]: eth3            : link configured
Aug  8 16:04:57 vyos systemd-networkd[2370]: eth3            : lost carrier
Aug  8 16:06:37 vyos systemd-networkd[2370]: eth3            : gained carrier
hagbard changed the task status from In progress to Needs testing.Thu, Aug 8, 9:34 PM
While documentation is on its way, below is a very small example on how to use it:


from vyos.interfaceconfig import Interface

a = Interface("eth2")
print (a.get_link_state())
hagbard changed the status of subtask T1569: interfaceconfig class documetation from Open to In progress.Thu, Aug 8, 10:44 PM

moved get functions into properties, for ifalias, macaddr and mtu to see how it works. If the old get_ function is being used, it prints a message to the console but still works. Will see how well that works.