File: create_vlan.py

package info (click to toggle)
pyroute2 0.8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,704 kB
  • sloc: python: 50,245; makefile: 280; javascript: 183; ansic: 81; sh: 44; awk: 17
file content (31 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from pyroute2 import NDB
from pyroute2.common import uifname

# unique interface names
vlan_host = uifname()
vlan_interface = uifname()

with NDB() as ndb:


    (
        ndb.interfaces.create(ifname=vlan_host, kind='dummy')
        .set('state', 'up')
        .commit()
    )
    (
        ndb.interfaces.create(
            ifname=vlan_interface,
            kind='vlan',
            link=ndb.interfaces[vlan_host],
            vlan_id=101
        )
        .set('mtu', 1400)
        .set('state', 'up')
        .add_ip('10.251.0.1/24')
        .add_ip('10.251.0.2/24')
        .commit()
    )

    for i in (vlan_interface, vlan_host):
        ndb.interfaces[i].remove().commit()