Skip to content

Commit c7112e6

Browse files
committed
docs: add more usage examples an move them to their own page
1 parent 317bb2a commit c7112e6

File tree

3 files changed

+84
-27
lines changed

3 files changed

+84
-27
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'sphinx.ext.coverage',
3737
'sphinx.ext.viewcode',
3838
'sphinx.ext.intersphinx',
39+
'sphinx.ext.autosectionlabel',
3940
]
4041

4142
# Add any paths that contain templates here, relative to this directory.

docs/index.rst

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,8 @@ Download and Installation
4242
- ``python setup.py build``
4343
- ``python setup.py install``
4444

45-
Example
46-
-------
47-
::
48-
49-
from rtrlib import RTRManager, PfxvState
50-
51-
mgr = RTRManager('rpki-validator.realmv6.org', 8282)
52-
mgr.start()
53-
result = mgr.validate(12345, '10.10.0.0', 24)
54-
55-
if result == PfxvState.valid:
56-
print('Prefix Valid')
57-
elif result == PfxvState.invalid:
58-
print('Prefix Invalid')
59-
elif result == PfxvState.not_found:
60-
print('Prefix not found')
61-
else:
62-
print('Invalid response')
63-
64-
# iterate over all ipv4 record and print them
65-
for recordv4 in mgr.ipv4_records():
66-
print(recordv4)
67-
68-
mgr.stop()
69-
70-
71-
Further examples can be found in the tools_ dir of the repository.
45+
For usage examples see here :ref:`here <Usage Examples>`
46+
or in the tools_ dir of the repository.
7247

7348

7449
.. _rtrlib-python: https://github.com/rtrlib/python-binding
@@ -82,6 +57,7 @@ Contents:
8257

8358
api
8459
callbacks
60+
usage
8561

8662

8763

docs/usage.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
Usage Examples
3+
==============
4+
5+
Validation
6+
----------
7+
8+
::
9+
10+
from rtrlib import RTRManager, PfxvState
11+
12+
mgr = RTRManager('rpki-validator.realmv6.org', 8282)
13+
mgr.start()
14+
result = mgr.validate(12345, '10.10.0.0', 24)
15+
16+
if result == PfxvState.valid:
17+
print('Prefix Valid')
18+
elif result == PfxvState.invalid:
19+
print('Prefix Invalid')
20+
elif result == PfxvState.not_found:
21+
print('Prefix not found')
22+
else:
23+
print('Invalid response')
24+
25+
mgr.stop()
26+
27+
28+
PFX Table iteration (with iterator)
29+
-----------------------------------
30+
31+
::
32+
33+
from rtrlib import RTRManager, PfxvState
34+
35+
mgr = RTRManager('rpki-validator.realmv6.org', 8282)
36+
mgr.start()
37+
result = mgr.validate(12345, '10.10.0.0', 24)
38+
39+
for recordv4 in mgr.ipv4_records():
40+
print(recordv4)
41+
42+
mgr.stop()
43+
44+
45+
PFX Table iteration (with callback)
46+
-----------------------------------
47+
48+
::
49+
50+
from rtrlib import RTRManager, PfxvState
51+
52+
def callback(pfx_record, data):
53+
print(pfx_record)
54+
55+
mgr = RTRManager('rpki-validator.realmv6.org', 8282)
56+
mgr.start()
57+
result = mgr.validate(12345, '10.10.0.0', 24)
58+
59+
mgr.for_each_ipv4_record(callback, None)
60+
61+
mgr.stop()
62+
63+
64+
Print PFX updates
65+
-------------------
66+
67+
::
68+
69+
from rtrlib import RTRManager, register_pfx_update_callback
70+
71+
def callback(pfx_record, added):
72+
print('%s %s' % ('+' if added else '-', pfx_record))
73+
74+
register_pfx_update_callback(callback)
75+
76+
mgr = RTRManager('rpki-validator.realmv6.org', 8282)
77+
mgr.start()
78+
79+
mgr.stop()
80+

0 commit comments

Comments
 (0)