File: path.rst

package info (click to toggle)
librouteros 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 336 kB
  • sloc: python: 1,110; makefile: 127; sh: 8
file content (71 lines) | stat: -rw-r--r-- 1,624 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Path object
===========

``Path`` object represents absolute command path within routeros. e.g. ``/ip/address``.
You can traverse down in tree with ``join()`` method.
Works same as python `join() <https://docs.python.org/3/library/os.path.html#os.path.join>`_.

.. code-block:: python

    # First create desired path.
    interfaces = api.path('interface')
    # Traverse down into /interfaces/ethernet
    ethernet = interfaces.join('ethernet')

    # path() and join() accepts multiple arguments
    ips = api.path('ip', 'address')

Get all
-------

.. code-block:: python

    # Path objects are iterable
    tuple(interfaces)
    # This also will work, as well as anything else you can do with iterables
    for item in interfaces:
        print(item)

Add
---

.. code-block:: python

    # Will return newly created .id
    path.add(interface='ether1', address='172.31.31.1/24')

Remove
------

.. code-block:: python

    # Pass each .id as an argument.
    path.remove('*1', '*2')

.. note::

    ``.id`` change on reboot. Always read them first.

Update
------

.. code-block:: python

    params = {'disabled': True, '.id' :'*7'}
    path.update(**params)

.. note::

    ``.id`` change on reboot. Always read them first.

Arbitrary command
-----------------
For all other commands, call ``Path`` object directly.
Remember to consume the result since it returns a generator.
As a first argument, pass command that you wish to run without absolute path.

.. code-block:: python

    script = api.path('system', 'script')
    # Will run /system/script/run with desired .id
    tuple(script('run', **{'.id': '*1'}))