netbox-cesnet-services-plugin 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netbox_cesnet_services_plugin-1.0.0/CONTRIBUTING.md +128 -0
- netbox_cesnet_services_plugin-1.0.0/LICENSE +1 -0
- netbox_cesnet_services_plugin-1.0.0/MANIFEST.in +10 -0
- netbox_cesnet_services_plugin-1.0.0/PKG-INFO +12 -0
- netbox_cesnet_services_plugin-1.0.0/README.md +61 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/__init__.py +19 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/api/__init__.py +0 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/api/serializers.py +123 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/api/urls.py +11 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/api/views.py +26 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/choices.py +12 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/filtersets/__init__.py +3 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/filtersets/bgpconnection.py +88 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/filtersets/lldpneighbor.py +69 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/filtersets/lldpneighborleaf.py +27 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/forms/__init__.py +3 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/forms/bgpconnection.py +122 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/forms/lldpneighbor.py +127 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/forms/lldpneighborleaf.py +106 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0001_initial.py +38 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0002_bgpconnection_comments.py +18 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0003_alter_bgpconnection_options_bgpconnection_device.py +25 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0004_alter_bgpconnection_options_bgpconnection_raw_vrf_and_more.py +34 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0005_alter_bgpconnection_role.py +18 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0006_lldpneighbor.py +39 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0007_lldpneighbor_comments.py +18 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0008_alter_lldpneighbor_device_a_and_more.py +60 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/0009_lldpneighbor_status_lldpneighborleaf_status.py +23 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/migrations/__init__.py +0 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/models/__init__.py +3 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/models/bgpconnection.py +120 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/models/lldpneighbor.py +141 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/models/lldpneighborleaf.py +96 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/navigation.py +26 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/tables/__init__.py +3 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/tables/bgpconnection.py +64 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/tables/lldpneighbor.py +38 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/tables/lldpneighborleaf.py +38 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/template_content.py +331 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/bgpconnection/bgpconnection.html +67 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/bgpconnection/bgpconnection_include.html +5 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/details/connection_endpoints.html +37 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/details/detail_interface_inc.html +66 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/details/multiple_children.html +90 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/lldpneighbor/lldpneighbor.html +64 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/lldpneighbor/lldpneighbor_include.html +5 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/lldpneighborleaf/lldpneighborleaf.html +62 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/templates/netbox_cesnet_services_plugin/lldpneighborleaf/lldpneighborleaf_include.html +5 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/urls.py +113 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/views/__init__.py +3 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/views/bgpconnection.py +54 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/views/lldpneighbor.py +35 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/views/lldpneighborleaf.py +39 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin.egg-info/PKG-INFO +12 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin.egg-info/SOURCES.txt +60 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin.egg-info/dependency_links.txt +1 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin.egg-info/not-zip-safe +1 -0
- netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin.egg-info/top_level.txt +2 -0
- netbox_cesnet_services_plugin-1.0.0/setup.cfg +4 -0
- netbox_cesnet_services_plugin-1.0.0/setup.py +13 -0
- netbox_cesnet_services_plugin-1.0.0/tests/__init__.py +1 -0
- netbox_cesnet_services_plugin-1.0.0/tests/test_netbox_cesnet_services_plugin.py +5 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Contributions are welcome, and they are greatly appreciated! Every little bit
|
|
4
|
+
helps, and credit will always be given.
|
|
5
|
+
|
|
6
|
+
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
|
|
7
|
+
|
|
8
|
+
- Reporting a bug
|
|
9
|
+
- Discussing the current state of the code
|
|
10
|
+
- Submitting a fix
|
|
11
|
+
- Proposing new features
|
|
12
|
+
- Becoming a maintainer
|
|
13
|
+
|
|
14
|
+
## General Tips for Working on GitHub
|
|
15
|
+
|
|
16
|
+
* Register for a free [GitHub account](https://github.com/signup) if you haven't already.
|
|
17
|
+
* You can use [GitHub Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) for formatting text and adding images.
|
|
18
|
+
* To help mitigate notification spam, please avoid "bumping" issues with no activity. (To vote an issue up or down, use a :thumbsup: or :thumbsdown: reaction.)
|
|
19
|
+
* Please avoid pinging members with `@` unless they've previously expressed interest or involvement with that particular issue.
|
|
20
|
+
* Familiarize yourself with [this list of discussion anti-patterns](https://github.com/bradfitz/issue-tracker-behaviors) and make every effort to avoid them.
|
|
21
|
+
|
|
22
|
+
## Types of Contributions
|
|
23
|
+
|
|
24
|
+
### Report Bugs
|
|
25
|
+
|
|
26
|
+
Report bugs at https://github.com/kani999/netbox_cesnet_services_plugin/issues.
|
|
27
|
+
|
|
28
|
+
If you are reporting a bug, please include:
|
|
29
|
+
|
|
30
|
+
* Your operating system name and version.
|
|
31
|
+
* Any details about your local setup that might be helpful in troubleshooting.
|
|
32
|
+
* Detailed steps to reproduce the bug.
|
|
33
|
+
|
|
34
|
+
### Fix Bugs
|
|
35
|
+
|
|
36
|
+
Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
|
|
37
|
+
wanted" is open to whoever wants to implement it.
|
|
38
|
+
|
|
39
|
+
### Implement Features
|
|
40
|
+
|
|
41
|
+
Look through the GitHub issues for features. Anything tagged with "enhancement"
|
|
42
|
+
and "help wanted" is open to whoever wants to implement it.
|
|
43
|
+
|
|
44
|
+
### Write Documentation
|
|
45
|
+
|
|
46
|
+
NetBox cesnet_services Plugin could always use more documentation, whether as part of the
|
|
47
|
+
official NetBox cesnet_services Plugin docs, in docstrings, or even on the web in blog posts,
|
|
48
|
+
articles, and such.
|
|
49
|
+
|
|
50
|
+
### Submit Feedback
|
|
51
|
+
|
|
52
|
+
The best way to send feedback is to file an issue at https://github.com/kani999/netbox_cesnet_services_plugin/issues.
|
|
53
|
+
|
|
54
|
+
If you are proposing a feature:
|
|
55
|
+
|
|
56
|
+
* Explain in detail how it would work.
|
|
57
|
+
* Keep the scope as narrow as possible, to make it easier to implement.
|
|
58
|
+
* Remember that this is a volunteer-driven project, and that contributions
|
|
59
|
+
are welcome :)
|
|
60
|
+
|
|
61
|
+
## Get Started!
|
|
62
|
+
|
|
63
|
+
Ready to contribute? Here's how to set up `netbox_cesnet_services_plugin` for local development.
|
|
64
|
+
|
|
65
|
+
1. Fork the `netbox_cesnet_services_plugin` repo on GitHub.
|
|
66
|
+
2. Clone your fork locally
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
$ git clone git@github.com:your_name_here/netbox_cesnet_services_plugin.git
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
3. Install dependencies and start your virtualenv:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
$ poetry install -E test -E doc -E dev
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
4. Create a branch for local development:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
$ git checkout -b name-of-your-bugfix-or-feature
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Now you can make your changes locally.
|
|
85
|
+
|
|
86
|
+
5. When you're done making changes, check that your changes pass the
|
|
87
|
+
tests, including testing other Python versions, with tox:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
$ poetry run tox
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
6. Commit your changes and push your branch to GitHub:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
$ git add .
|
|
97
|
+
$ git commit -m "Your detailed description of your changes."
|
|
98
|
+
$ git push origin name-of-your-bugfix-or-feature
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
7. Submit a pull request through the GitHub website.
|
|
102
|
+
|
|
103
|
+
## Pull Request Guidelines
|
|
104
|
+
|
|
105
|
+
Before you submit a pull request, check that it meets these guidelines:
|
|
106
|
+
|
|
107
|
+
1. The pull request should include tests.
|
|
108
|
+
2. If the pull request adds functionality, the docs should be updated. Put
|
|
109
|
+
your new functionality into a function with a docstring, and add the
|
|
110
|
+
feature to the list in README.md.
|
|
111
|
+
3. The pull request should work for Python 3.6, 3.7, 3.8 and 3.9. Check
|
|
112
|
+
https://github.com/kani999/netbox_cesnet_services_plugin/actions
|
|
113
|
+
and make sure that the tests pass for all supported Python versions.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## Deploying
|
|
117
|
+
|
|
118
|
+
A reminder for the maintainers on how to deploy.
|
|
119
|
+
Make sure all your changes are committed (including an entry in CHANGELOG.md).
|
|
120
|
+
Then run:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
$ poetry run bump2version patch # possible: major / minor / patch
|
|
124
|
+
$ git push
|
|
125
|
+
$ git push --tags
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
GitHub Actions will then deploy to PyPI if tests pass.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include CONTRIBUTING.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include README.md
|
|
4
|
+
|
|
5
|
+
recursive-include tests *
|
|
6
|
+
recursive-exclude * __pycache__
|
|
7
|
+
recursive-exclude * *.py[co]
|
|
8
|
+
|
|
9
|
+
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
|
|
10
|
+
recursive-include netbox_cesnet_services_plugin/templates *
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# NetBox cesnet_services Plugin
|
|
2
|
+
|
|
3
|
+
NetBox plugin for cesnet_services.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
* Free software: Apache-2.0
|
|
7
|
+
* Documentation: https://kani999.github.io/netbox-cesnet-services-plugin/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
The features the plugin provides should be listed here.
|
|
13
|
+
|
|
14
|
+
## Compatibility
|
|
15
|
+
|
|
16
|
+
| NetBox Version | Plugin Version |
|
|
17
|
+
|----------------|----------------|
|
|
18
|
+
| 3.4 | 0.1.0 |
|
|
19
|
+
|
|
20
|
+
## Installing
|
|
21
|
+
|
|
22
|
+
For adding to a NetBox Docker setup see
|
|
23
|
+
[the general instructions for using netbox-docker with plugins](https://github.com/netbox-community/netbox-docker/wiki/Using-Netbox-Plugins).
|
|
24
|
+
|
|
25
|
+
While this is still in development and not yet on pypi you can install with pip:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install git+https://github.com/kani999/netbox_cesnet_services_plugin
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
or by adding to your `local_requirements.txt` or `plugin_requirements.txt` (netbox-docker):
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git+https://github.com/kani999/netbox_cesnet_services_plugin
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Enable the plugin in `/opt/netbox/netbox/netbox/configuration.py`,
|
|
38
|
+
or if you use netbox-docker, your `/configuration/plugins.py` file :
|
|
39
|
+
|
|
40
|
+
Set device platforms for filtering choices in LLDPNeighbor form.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
PLUGINS = [
|
|
44
|
+
'netbox_cesnet_services_plugin'
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
PLUGINS_CONFIG = {
|
|
48
|
+
"netbox_cesnet_services_plugin": {
|
|
49
|
+
"platforms" : ["ios", "iosxe", "iosxr", "nxos", "nxos_ssh"],
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Credits
|
|
55
|
+
|
|
56
|
+
Based on the NetBox plugin tutorial:
|
|
57
|
+
|
|
58
|
+
- [demo repository](https://github.com/netbox-community/netbox-plugin-demo)
|
|
59
|
+
- [tutorial](https://github.com/netbox-community/netbox-plugin-tutorial)
|
|
60
|
+
|
|
61
|
+
This package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and the [`netbox-community/cookiecutter-netbox-plugin`](https://github.com/netbox-community/cookiecutter-netbox-plugin) project template.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Top-level package for NetBox cesnet_services Plugin."""
|
|
2
|
+
|
|
3
|
+
__author__ = """Jan Krupa"""
|
|
4
|
+
__email__ = "jan.krupa@cesnet.cz"
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
from netbox.plugins import PluginConfig
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CesnetServicesConfig(PluginConfig):
|
|
12
|
+
name = "netbox_cesnet_services_plugin"
|
|
13
|
+
verbose_name = "NetBox cesnet_services Plugin"
|
|
14
|
+
description = "NetBox plugin for cesnet_services."
|
|
15
|
+
version = __version__
|
|
16
|
+
base_url = "netbox-cesnet-services-plugin"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
config = CesnetServicesConfig
|
|
File without changes
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from ipam.api.serializers import IPAddressSerializer, PrefixSerializer, VRFSerializer
|
|
2
|
+
from dcim.api.serializers import DeviceSerializer, InterfaceSerializer
|
|
3
|
+
from netbox.api.serializers import NetBoxModelSerializer
|
|
4
|
+
from rest_framework import serializers
|
|
5
|
+
|
|
6
|
+
from netbox_cesnet_services_plugin.models import BGPConnection, LLDPNeighbor, LLDPNeighborLeaf
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LLDPNeighborLeafSerializer(NetBoxModelSerializer):
|
|
12
|
+
url = serializers.HyperlinkedIdentityField(
|
|
13
|
+
view_name="plugins-api:netbox_cesnet_services_plugin-api:lldpneighborleaf-detail"
|
|
14
|
+
)
|
|
15
|
+
device_nb = DeviceSerializer(nested=True)
|
|
16
|
+
interface_nb = InterfaceSerializer(nested=True)
|
|
17
|
+
|
|
18
|
+
class Meta:
|
|
19
|
+
model = LLDPNeighborLeaf
|
|
20
|
+
fields = (
|
|
21
|
+
"id",
|
|
22
|
+
"url",
|
|
23
|
+
"device_nb",
|
|
24
|
+
"interface_nb",
|
|
25
|
+
"device_ext",
|
|
26
|
+
"interface_ext",
|
|
27
|
+
"status",
|
|
28
|
+
"comments",
|
|
29
|
+
"tags",
|
|
30
|
+
"imported_data",
|
|
31
|
+
"custom_fields",
|
|
32
|
+
"created",
|
|
33
|
+
"last_updated",
|
|
34
|
+
)
|
|
35
|
+
brief_fields = (
|
|
36
|
+
"id",
|
|
37
|
+
"device_nb",
|
|
38
|
+
"interface_nb",
|
|
39
|
+
"device_ext",
|
|
40
|
+
"interface_ext",
|
|
41
|
+
"status",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class LLDPNeighborSerializer(NetBoxModelSerializer):
|
|
47
|
+
url = serializers.HyperlinkedIdentityField(
|
|
48
|
+
view_name="plugins-api:netbox_cesnet_services_plugin-api:lldpneighbor-detail"
|
|
49
|
+
)
|
|
50
|
+
device_a = DeviceSerializer(nested=True)
|
|
51
|
+
interface_a = InterfaceSerializer(nested=True)
|
|
52
|
+
device_b = DeviceSerializer(nested=True)
|
|
53
|
+
interface_b = InterfaceSerializer(nested=True)
|
|
54
|
+
|
|
55
|
+
class Meta:
|
|
56
|
+
model = LLDPNeighbor
|
|
57
|
+
fields = (
|
|
58
|
+
"id",
|
|
59
|
+
"url",
|
|
60
|
+
"device_a",
|
|
61
|
+
"interface_a",
|
|
62
|
+
"device_b",
|
|
63
|
+
"interface_b",
|
|
64
|
+
"status",
|
|
65
|
+
"comments",
|
|
66
|
+
"tags",
|
|
67
|
+
"imported_data",
|
|
68
|
+
"custom_fields",
|
|
69
|
+
"created",
|
|
70
|
+
"last_updated",
|
|
71
|
+
)
|
|
72
|
+
brief_fields = (
|
|
73
|
+
"id",
|
|
74
|
+
"device_a",
|
|
75
|
+
"interface_a",
|
|
76
|
+
"device_b",
|
|
77
|
+
"interface_b",
|
|
78
|
+
"status",
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class BGPConnectionSerializer(NetBoxModelSerializer):
|
|
83
|
+
url = serializers.HyperlinkedIdentityField(
|
|
84
|
+
view_name="plugins-api:netbox_cesnet_services_plugin-api:bgpconnection-detail"
|
|
85
|
+
)
|
|
86
|
+
device = DeviceSerializer(nested=True)
|
|
87
|
+
next_hop = IPAddressSerializer(nested=True, allow_null=True)
|
|
88
|
+
bgp_prefix = PrefixSerializer(nested=True, allow_null=True)
|
|
89
|
+
vrf = VRFSerializer(nested=True, allow_null=True)
|
|
90
|
+
|
|
91
|
+
class Meta:
|
|
92
|
+
model = BGPConnection
|
|
93
|
+
fields = (
|
|
94
|
+
"id",
|
|
95
|
+
"display",
|
|
96
|
+
"url",
|
|
97
|
+
"device",
|
|
98
|
+
"raw_next_hop",
|
|
99
|
+
"next_hop",
|
|
100
|
+
"raw_bgp_prefix",
|
|
101
|
+
"bgp_prefix",
|
|
102
|
+
"raw_vrf",
|
|
103
|
+
"vrf",
|
|
104
|
+
"role",
|
|
105
|
+
"tags",
|
|
106
|
+
"import_data",
|
|
107
|
+
"custom_fields",
|
|
108
|
+
"created",
|
|
109
|
+
"last_updated",
|
|
110
|
+
)
|
|
111
|
+
brief_fields = (
|
|
112
|
+
"id",
|
|
113
|
+
"url",
|
|
114
|
+
"display",
|
|
115
|
+
"device",
|
|
116
|
+
"raw_next_hop",
|
|
117
|
+
"next_hop",
|
|
118
|
+
"raw_bgp_prefix",
|
|
119
|
+
"bgp_prefix",
|
|
120
|
+
"raw_vrf",
|
|
121
|
+
"vrf",
|
|
122
|
+
"role",
|
|
123
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from netbox.api.routers import NetBoxRouter
|
|
2
|
+
|
|
3
|
+
from . import views
|
|
4
|
+
|
|
5
|
+
app_name = 'netbox_cesnet_services_plugin'
|
|
6
|
+
router = NetBoxRouter()
|
|
7
|
+
router.register('bgp-connections', views.BGPConnectionViewSet)
|
|
8
|
+
router.register('lldp-neighbors', views.LLDPNeighborViewSet)
|
|
9
|
+
router.register('lldp-neighbor-leafs', views.LLDPNeighborLeafViewSet)
|
|
10
|
+
|
|
11
|
+
urlpatterns = router.urls
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from netbox.api.metadata import ContentTypeMetadata
|
|
2
|
+
from netbox.api.viewsets import NetBoxModelViewSet
|
|
3
|
+
|
|
4
|
+
from netbox_cesnet_services_plugin import filtersets, models
|
|
5
|
+
from .serializers import BGPConnectionSerializer, LLDPNeighborSerializer, LLDPNeighborLeafSerializer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BGPConnectionViewSet(NetBoxModelViewSet):
|
|
9
|
+
metadata_class = ContentTypeMetadata
|
|
10
|
+
queryset = models.BGPConnection.objects.all()
|
|
11
|
+
serializer_class = BGPConnectionSerializer
|
|
12
|
+
filterset_class = filtersets.BGPConnectionFilterSet
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class LLDPNeighborViewSet(NetBoxModelViewSet):
|
|
16
|
+
metadata_class = ContentTypeMetadata
|
|
17
|
+
queryset = models.LLDPNeighbor.objects.all()
|
|
18
|
+
serializer_class = LLDPNeighborSerializer
|
|
19
|
+
filterset_class = filtersets.LLPDNeighborFilterSet
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class LLDPNeighborLeafViewSet(NetBoxModelViewSet):
|
|
23
|
+
metadata_class = ContentTypeMetadata
|
|
24
|
+
queryset = models.LLDPNeighborLeaf.objects.all()
|
|
25
|
+
serializer_class = LLDPNeighborLeafSerializer
|
|
26
|
+
filterset_class = filtersets.LLPDNeighborLeafFilterSet
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from utilities.choices import ChoiceSet
|
|
2
|
+
from django.utils.translation import gettext_lazy as _
|
|
3
|
+
|
|
4
|
+
class LLDPNeigborStatusChoices(ChoiceSet):
|
|
5
|
+
|
|
6
|
+
STATUS_ACTIVE = 'active'
|
|
7
|
+
STATUS_INACTIVE = 'inactive'
|
|
8
|
+
|
|
9
|
+
CHOICES = (
|
|
10
|
+
(STATUS_ACTIVE, _('Active'), 'green'),
|
|
11
|
+
(STATUS_INACTIVE, _('Inactive'), 'yellow'),
|
|
12
|
+
)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from django.db.models import Q
|
|
2
|
+
from django.utils.translation import gettext as _
|
|
3
|
+
import django_filters
|
|
4
|
+
from netbox.filtersets import NetBoxModelFilterSet
|
|
5
|
+
from ipam.models import IPAddress, Prefix, VRF
|
|
6
|
+
from extras.filters import TagFilter
|
|
7
|
+
from netbox_cesnet_services_plugin.models import BGPConnection, BGPConnectionChoices
|
|
8
|
+
from utilities.forms.fields import DynamicMultipleChoiceField
|
|
9
|
+
from dcim.models import Device
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BGPConnectionFilterSet(NetBoxModelFilterSet):
|
|
13
|
+
q = django_filters.CharFilter(method="search", label="Search")
|
|
14
|
+
device = django_filters.ModelMultipleChoiceFilter(queryset=Device.objects.all())
|
|
15
|
+
next_hop = django_filters.ModelMultipleChoiceFilter(
|
|
16
|
+
queryset=IPAddress.objects.all()
|
|
17
|
+
)
|
|
18
|
+
bgp_prefix = django_filters.ModelMultipleChoiceFilter(queryset=Prefix.objects.all())
|
|
19
|
+
vrf = django_filters.ModelMultipleChoiceFilter(queryset=VRF.objects.all())
|
|
20
|
+
|
|
21
|
+
# TODO: as CHAR filter or as IPAddress filter?
|
|
22
|
+
raw_next_hop = django_filters.CharFilter(
|
|
23
|
+
# method='filter_address',
|
|
24
|
+
label=_("Address"),
|
|
25
|
+
lookup_expr="icontains",
|
|
26
|
+
)
|
|
27
|
+
raw_bgp_prefix = django_filters.CharFilter(
|
|
28
|
+
# method='filter_prefix',
|
|
29
|
+
label=_("Prefix"),
|
|
30
|
+
lookup_expr="icontains",
|
|
31
|
+
)
|
|
32
|
+
raw_vrf = django_filters.CharFilter(
|
|
33
|
+
label=_("VRF"),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
role = DynamicMultipleChoiceField(choices=BGPConnectionChoices, required=False)
|
|
37
|
+
|
|
38
|
+
tag = TagFilter()
|
|
39
|
+
|
|
40
|
+
class Meta:
|
|
41
|
+
model = BGPConnection
|
|
42
|
+
fields = [
|
|
43
|
+
"raw_next_hop",
|
|
44
|
+
"next_hop",
|
|
45
|
+
"raw_bgp_prefix",
|
|
46
|
+
"bgp_prefix",
|
|
47
|
+
"vrf",
|
|
48
|
+
"role",
|
|
49
|
+
"tag",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
def search(self, queryset, name, value):
|
|
53
|
+
filters = (
|
|
54
|
+
Q(device__name=value)
|
|
55
|
+
| Q(raw_next_hop__icontains=value)
|
|
56
|
+
| Q(raw_bgp_prefix__icontains=value)
|
|
57
|
+
| Q(bgp_prefix__tenant__name__icontains=value)
|
|
58
|
+
| Q(raw_vrf__icontains=value)
|
|
59
|
+
| Q(vrf__name__icontains=value)
|
|
60
|
+
| Q(role__icontains=value)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
return queryset.filter(filters)
|
|
64
|
+
|
|
65
|
+
# TODO: Filter `raw`` Address and Prefix with netaddr or treat it like a string?
|
|
66
|
+
"""
|
|
67
|
+
def filter_address(self, queryset, name, value):
|
|
68
|
+
# Let's first parse the addresses passed
|
|
69
|
+
# as argument. If they are all invalid,
|
|
70
|
+
# we return an empty queryset
|
|
71
|
+
# TODO: Use Netaddr or ipaddress module
|
|
72
|
+
value = self.parse_inet_addresses(value)
|
|
73
|
+
if len(value) == 0:
|
|
74
|
+
return queryset.none()
|
|
75
|
+
try:
|
|
76
|
+
return queryset.filter(address__net_in=value)
|
|
77
|
+
except ValidationError:
|
|
78
|
+
return queryset.none()
|
|
79
|
+
|
|
80
|
+
def filter_prefix(self, queryset, name, value):
|
|
81
|
+
query_values = []
|
|
82
|
+
for v in value:
|
|
83
|
+
try:
|
|
84
|
+
query_values.append(netaddr.IPNetwork(v))
|
|
85
|
+
except (AddrFormatError, ValueError):
|
|
86
|
+
pass
|
|
87
|
+
return queryset.filter(prefix__in=query_values)
|
|
88
|
+
"""
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from django.db.models import Q
|
|
2
|
+
import django_filters
|
|
3
|
+
from extras.filters import TagFilter
|
|
4
|
+
from netbox.filtersets import NetBoxModelFilterSet
|
|
5
|
+
from dcim.models import Device, Interface
|
|
6
|
+
from netbox_cesnet_services_plugin.models import LLDPNeighbor
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LLPDNeighborFilterSet(NetBoxModelFilterSet):
|
|
10
|
+
q = django_filters.CharFilter(method="search", label="Search")
|
|
11
|
+
device_a = django_filters.ModelMultipleChoiceFilter(queryset=Device.objects.all())
|
|
12
|
+
interface_a = django_filters.ModelMultipleChoiceFilter(
|
|
13
|
+
queryset=Interface.objects.all()
|
|
14
|
+
)
|
|
15
|
+
device_b = django_filters.ModelMultipleChoiceFilter(queryset=Device.objects.all())
|
|
16
|
+
interface_b = django_filters.ModelMultipleChoiceFilter(
|
|
17
|
+
queryset=Interface.objects.all()
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
device_a_id = django_filters.ModelMultipleChoiceFilter(
|
|
21
|
+
field_name='device_a__id',
|
|
22
|
+
queryset=Device.objects.all(),
|
|
23
|
+
to_field_name='id',
|
|
24
|
+
label='Device (ID)',
|
|
25
|
+
)
|
|
26
|
+
device_b_id = django_filters.ModelMultipleChoiceFilter(
|
|
27
|
+
field_name='device_b__id',
|
|
28
|
+
queryset=Device.objects.all(),
|
|
29
|
+
to_field_name='id',
|
|
30
|
+
label='Device (ID)',
|
|
31
|
+
)
|
|
32
|
+
interface_a_id = django_filters.ModelMultipleChoiceFilter(
|
|
33
|
+
field_name='interface_a__id',
|
|
34
|
+
queryset=Interface.objects.all(),
|
|
35
|
+
to_field_name='id',
|
|
36
|
+
label='Interface (ID)',
|
|
37
|
+
)
|
|
38
|
+
interface_b_id = django_filters.ModelMultipleChoiceFilter(
|
|
39
|
+
field_name='interface_b__id',
|
|
40
|
+
queryset=Interface.objects.all(),
|
|
41
|
+
to_field_name='id',
|
|
42
|
+
label='Interface (ID)',
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
tag = TagFilter()
|
|
46
|
+
|
|
47
|
+
class Meta:
|
|
48
|
+
model = LLDPNeighbor
|
|
49
|
+
fields = {"id",
|
|
50
|
+
"device_a",
|
|
51
|
+
"interface_a",
|
|
52
|
+
"device_b",
|
|
53
|
+
"interface_b",
|
|
54
|
+
"status",
|
|
55
|
+
"device_a_id",
|
|
56
|
+
"device_b_id",
|
|
57
|
+
"interface_a_id",
|
|
58
|
+
"interface_b_id",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
def search(self, queryset, name, value):
|
|
62
|
+
filters = (
|
|
63
|
+
Q(device_a__name__icontains=value)
|
|
64
|
+
| Q(device_b__name__icontains=value)
|
|
65
|
+
| Q(interface_a__name__icontains=value)
|
|
66
|
+
| Q(interface_a__name__icontains=value)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
return queryset.filter(filters)
|
netbox_cesnet_services_plugin-1.0.0/netbox_cesnet_services_plugin/filtersets/lldpneighborleaf.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import django_filters
|
|
2
|
+
from django.db.models import Q
|
|
3
|
+
from netbox.filtersets import NetBoxModelFilterSet
|
|
4
|
+
from dcim.models import Device, Interface
|
|
5
|
+
from netbox_cesnet_services_plugin.models import LLDPNeighborLeaf
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LLPDNeighborLeafFilterSet(NetBoxModelFilterSet):
|
|
9
|
+
q = django_filters.CharFilter(method="search", label="Search")
|
|
10
|
+
device_nb = django_filters.ModelMultipleChoiceFilter(queryset=Device.objects.all())
|
|
11
|
+
interface_nb = django_filters.ModelMultipleChoiceFilter(
|
|
12
|
+
queryset=Interface.objects.all()
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
class Meta:
|
|
16
|
+
model = LLDPNeighborLeaf
|
|
17
|
+
fields = {"id", "device_nb", "interface_nb", "device_ext", "interface_ext", "status"}
|
|
18
|
+
|
|
19
|
+
def search(self, queryset, name, value):
|
|
20
|
+
filters = (
|
|
21
|
+
Q(device_nb__name__icontains=value)
|
|
22
|
+
| Q(interface_nb__name__icontains=value)
|
|
23
|
+
| Q(device_ext__icontains=value)
|
|
24
|
+
| Q(interface_ext__icontains=value)
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
return queryset.filter(filters)
|