File: create_interface.py

package info (click to toggle)
pyroute2 0.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,700 kB
  • sloc: python: 50,245; makefile: 280; javascript: 183; ansic: 81; sh: 44; awk: 17
file content (26 lines) | stat: -rw-r--r-- 643 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
from pyroute2 import NDB
from pyroute2.common import uifname


with NDB() as ndb:

    # dummy, bridge and bond interfaces are created in the
    # same way
    #
    # uifname() function is used here only to generate a
    # unique name of the interface for the regression testing,
    # you can pick up any name
    #
    ifname = uifname()
    (
        ndb.interfaces.create(kind='dummy', ifname=ifname, state='up')
        .set('state', 'up')
        .set('address', '00:11:22:33:44:55')
        .commit()
    )
    print(ndb.interfaces[ifname].show('json'))
    (
        ndb.interfaces[ifname]
        .remove()
        .commit()
    )