Can we dump changes done?

25 views
Skip to first unread message

Debashis Prusty

unread,
Jul 10, 2017, 6:35:49 AM7/10/17
to pyroute2-dev
Hi,

Can we dump the changes done through IPDB or IPRoute objects to network configuration scripts(meaning dumping changes from kernel to disk) so that on reboot or service restart the system comes up with these changes?

Regards,
Debashis

Peter Saveliev

unread,
Jul 10, 2017, 6:58:12 AM7/10/17
to Debashis Prusty, pyroute2-dev
Right now there are several ways to do that:

1. Iterate IPDB objects and run dump():

In [1]: from pyroute2 import IPDB
In [2]: ip = IPDB()
In [3]: ip.interfaces.lo.dump()
Out[3]:
{'address': '00:00:00:00:00:00',
 'broadcast': '00:00:00:00:00:00',
 'carrier': 1,
 'carrier_changes': 0,
 'family': 0,
 'flags': 65609,
 'group': 0,
 'gso_max_segs': 65535,
 'gso_max_size': 65536,
 'ifi_type': 772,
 'ifname': 'lo',
 'index': 1,
 'ipaddr': (('127.0.0.1', 8), ('::1', 128)),
 'ipdb_priority': 0,
 'ipdb_scope': 'system',
 'linkmode': 0,
 'mtu': 65536,
 'neighbours': ('127.0.0.1',),
 'num_rx_queues': 1,
 'num_tx_queues': 1,
 'operstate': 'UNKNOWN',
 'ports': (),
 'promiscuity': 0,
 'proto_down': 0,
 'qdisc': 'noqueue',
 'txqlen': 1000,
 'vlans': ()}

The dump() method returns simple Python objects that can be used with JSON:

In [1]: from pyroute2 import IPDB
In [2]: import json
In [3]: ip = IPDB()
In [4]: json.dumps(ip.interfaces.lo.dump())
Out[4]: '{"family": 0, "txqlen": 1000, "ipdb_scope": "system", "index": 1, "operstate": "UNKNOWN", "num_tx_queues": 1, "group": 0, "carrier_changes": 0, "ipaddr": [["127.0.0.1", 8], ["::1", 128]], "neighbours": ["127.0.0.1"], "ifname": "lo", "promiscuity": 0, "linkmode": 0, "broadcast": "00:00:00:00:00:00", "address": "00:00:00:00:00:00", "vlans": [], "ipdb_priority": 0, "gso_max_segs": 65535, "gso_max_size": 65536, "qdisc": "noqueue", "mtu": 65536, "num_rx_queues": 1, "carrier": 1, "flags": 65609, "ifi_type": 772, "proto_down": 0, "ports": []}'

This data can be stored in files, loaded with JSON library and loaded with load():

with IPDB() as ipdb:
    with open('eth0.config', 'r') as f:
        ipdb.interfaces.eth0.load(json.loads(f.read())).commit()


Another way — an experimental cli:
Usage for now:
$ git clone g...@github.com:svinota/pyroute2
$ cd pyroute2
$ export PYTHONPATH=`pwd`
$ cat config | ./cli/ipdb

In some of the nearest releases the cli will be documented and provided in the package as well, so it will be installed from pip. But as for now it is yet an experimental feature.

--
You received this message because you are subscribed to the Google Groups "pyroute2-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyroute2-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages