Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit a30020ff authored by Laurent VENIER's avatar Laurent VENIER :speech_balloon:
Browse files

Merge branch 'ntt' into 'main'

Ntt

See merge request digit-c4/netbox-mapping!1
parents 4f95d3ad 20ee9690
No related branches found
No related tags found
1 merge request!1Ntt
Pipeline #53888 failed
Showing
with 586 additions and 92 deletions
.git
.gitignore
.dockerignore
.env
.github
*.sh
__pycache__/
test
venv
*.egg-info
dist
build
.idea
.DS_Store
Dockerfile
libs/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env.*
!.env.example
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
##
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# Crash log files
crash.log
crash.*.log
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json
# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json
# Include override files you do wish to add to version control using negated pattern
# !example_override.tf
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
# Ignore CLI configuration files
.terraformrc
terraform.rc
stages:
- build
build-job:
stage: build
script:
- echo "Build..."
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/kreuzwerker/docker" {
version = "3.0.2"
constraints = "3.0.2"
hashes = [
"h1:XjdpVL61KtTsuPE8swok3GY8A+Bu3TZs8T2DOEpyiXo=",
"zh:15b0a2b2b563d8d40f62f83057d91acb02cd0096f207488d8b4298a59203d64f",
"zh:23d919de139f7cd5ebfd2ff1b94e6d9913f0977fcfc2ca02e1573be53e269f95",
"zh:38081b3fe317c7e9555b2aaad325ad3fa516a886d2dfa8605ae6a809c1072138",
"zh:4a9c5065b178082f79ad8160243369c185214d874ff5048556d48d3edd03c4da",
"zh:5438ef6afe057945f28bce43d76c4401254073de01a774760169ac1058830ac2",
"zh:60b7fadc287166e5c9873dfe53a7976d98244979e0ab66428ea0dea1ebf33e06",
"zh:61c5ec1cb94e4c4a4fb1e4a24576d5f39a955f09afb17dab982de62b70a9bdd1",
"zh:a38fe9016ace5f911ab00c88e64b156ebbbbfb72a51a44da3c13d442cd214710",
"zh:c2c4d2b1fd9ebb291c57f524b3bf9d0994ff3e815c0cd9c9bcb87166dc687005",
"zh:d567bb8ce483ab2cf0602e07eae57027a1a53994aba470fa76095912a505533d",
"zh:e83bf05ab6a19dd8c43547ce9a8a511f8c331a124d11ac64687c764ab9d5a792",
"zh:e90c934b5cd65516fbcc454c89a150bfa726e7cf1fe749790c7480bbeb19d387",
"zh:f05f167d2eaf913045d8e7b88c13757e3cf595dd5cd333057fdafc7c4b7fed62",
"zh:fcc9c1cea5ce85e8bcb593862e699a881bd36dffd29e2e367f82d15368659c3d",
]
}
FROM netboxcommunity/netbox:v3.5-2.6.0
USER root
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
python3-dev \
python3-venv \
&& \
rm -rf /var/lib/apt/lists/*
COPY . /opt/netbox/netbox/plugins/netbox_rps_plugin
RUN pip install /opt/netbox/netbox/plugins/netbox_rps_plugin
RUN echo "PLUGINS = ['netbox_rps_plugin']" >> /opt/netbox/netbox/netbox/configuration.py
recursive-include src *.html
# Netbox Mapping
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://code.europa.eu/digit-c4/netbox-mapping.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://code.europa.eu/digit-c4/netbox-mapping/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
# RPS Plugin for Netbox
A Netbox v3.5 plugin for RPS mapping management
![Screenshot of the Netbox RPS plugin detail screen](./docs/Screenshot 2023-05-14 at 11.38.51.png)
## Quickstart
```shell
$ terraform init
$ terraform apply -var="deploy_service=true"
```
And browse [http://localhost:8000](http://localhost:8000).
* username is `username`
* and password is `password`
## Build
To build a [`netboxcommunity/netbox:v3.5-2.6.0`](https://hub.docker.com/layers/netboxcommunity/netbox/v3.5-2.6.0/images/sha256-edbb00e74a5cdb4bfeb51abbd9280cc005d1242152a67be7e2cd057e7d568fc2?context=explore)
Docker image including the plugin pre-installed, simply run
```shell
$ docker build .
```
Refer to the community [Docker image](https://hub.docker.com/r/netboxcommunity/netbox)
for environment variable configuration.
## Tests
see [tests directory](./tests/README.md)
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.2"
}
}
}
provider "docker" {
host = "unix:///var/run/docker.sock"
}
variable "deploy_administration" {
type = bool
default = false
}
variable "deploy_service" {
type = bool
default = false
}
resource "docker_network" "network" {
name = "netbox_rps"
}
resource "docker_image" "redis" {
name = "redis:7-alpine"
}
resource "docker_container" "redis" {
image = docker_image.redis.image_id
name = "redis"
command = [
"sh",
"-c", # this is to evaluate the $REDIS_PASSWORD from the env
"redis-server --appendonly yes --requirepass \"$REDIS_PASSWORD\"" # $$ is because of Docker
]
env = [
"REDIS_PASSWORD=password"
]
ports {
internal = 6379
external = 6379
}
networks_advanced {
name = docker_network.network.name
}
}
resource "docker_image" "postgres" {
name = "postgres:15-alpine"
}
resource "docker_container" "postgres" {
image = docker_image.postgres.image_id
name = "postgres"
env = [
"POSTGRES_USER=username",
"POSTGRES_PASSWORD=password",
"POSTGRES_DB=netbox"
]
ports {
internal = 5432
external = 5432
}
networks_advanced {
name = docker_network.network.name
}
}
resource "docker_container" "adminer" {
count = var.deploy_administration ? 1 : 0
image = "adminer"
name = "adminer"
ports {
internal = 8080
external = 8080
}
networks_advanced {
name = docker_network.network.name
}
}
resource "docker_image" "netbox" {
count = var.deploy_service ? 1 : 0
name = "netbox_rps"
build {
context = "."
}
}
resource "docker_container" "netbox" {
count = var.deploy_service ? 1 : 0
name = "netbox"
image = docker_image.netbox[0].image_id
ports {
internal = 8080
external = 8000
}
networks_advanced {
name = docker_network.network.name
}
env = [
"CORS_ORIGIN_ALLOW_ALL=True",
"DB_HOST=postgres",
"DB_NAME=postgres",
"DB_USER=username",
"DB_PASSWORD=password",
"REDIS_CACHE_DATABASE=1",
"REDIS_CACHE_HOST=redis",
"REDIS_CACHE_PASSWORD=password",
"REDIS_CACHE_SSL=false",
"REDIS_DATABASE=0",
"REDIS_HOST=redis",
"REDIS_PASSWORD=password",
"REDIS_SSL=false",
"SECRET_KEY=r8OwDznj!!dci#ParztZELKezarlkjjlazjkhat9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj",
"SKIP_SUPERUSER=false",
"SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567",
"SUPERUSER_EMAIL=username@global.ntt",
"SUPERUSER_NAME=username",
"SUPERUSER_PASSWORD=password",
]
}
docs/Screenshot 2023-05-14 at 11.38.51.png

730 KiB

setup.py 0 → 100644
from setuptools import find_packages, setup
setup(
name='netbox-rps-plugin',
version='0.1.0',
description='An example NetBox plugin',
install_requires=[],
packages=find_packages('./src'),
include_package_data=True,
zip_safe=False,
package_dir={'': 'src'}
)
from extras.plugins import PluginConfig
class NetBoxRpsConfig(PluginConfig):
name = 'netbox_rps_plugin'
verbose_name = 'NetBox RPS'
description = 'Netbox'
version = '0.1.0'
base_url = 'rps'
config = NetBoxRpsConfig
from rest_framework import serializers
from ..models import Mapping
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
class NestedMappingSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_rps_plugin-api:mapping-detail'
)
class Meta:
model = Mapping
fields = ('id', 'url', 'display')
class MappingSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_rps_plugin-api:mapping-detail'
)
class Meta:
model = Mapping
fields = (
'id', 'url', 'display', 'source', 'target', 'authentication', 'testingpage', 'webdav', 'Comment', 'custom_fields', 'created',
'last_updated',
)
from netbox.api.routers import NetBoxRouter
from . import views
app_name = 'netbox_rps_plugin'
router = NetBoxRouter()
router.register('mapping', views.MappingViewSet)
urlpatterns = router.urls
from netbox.api.viewsets import NetBoxModelViewSet
from .. import filtersets, models
from .serializers import MappingSerializer
class MappingViewSet(NetBoxModelViewSet):
queryset = models.Mapping.objects.all()
serializer_class = MappingSerializer
filterset_class = filtersets.MappingFilterSet
http_method_names = ['get', 'post', 'patch']
from netbox.filtersets import NetBoxModelFilterSet
from .models import Mapping
from django.db.models import Q
class MappingFilterSet(NetBoxModelFilterSet):
class Meta:
model = Mapping
fields = ('id', 'authentication', 'source', 'target', 'Comment')
def search(self, queryset, name, value):
return queryset.filter( Q(source__icontains=value) | Q(target__icontains=value)
| Q(authentication__icontains=value) | Q(Comment__icontains=value))
from django import forms
from netbox.forms import NetBoxModelForm
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm
from .models import Mapping, AuthenticationChoices
class MappingForm(NetBoxModelForm):
class Meta:
model = Mapping
fields = (
'source', 'target', 'authentication', 'webdav', 'testingpage', 'Comment', 'tags',
)
help_texts = {
'target': 'URL-friendly unique shorthand'
}
labels = {
'source': 'Source',
'target': 'Target',
}
class MappingFilterForm(NetBoxModelFilterSetForm):
model = Mapping
authentication = forms.MultipleChoiceField(
choices=AuthenticationChoices,
required=False,
)
# Generated by Django 4.1.5 on 2023-02-13 13:42
import django.contrib.postgres.fields
from django.db import migrations, models
import django.db.models.deletion
import taggit.managers
import utilities.json
class Migration(migrations.Migration):
initial = True
dependencies = [
('extras', '0084_staging'),
('ipam', '0063_standardize_description_comments'),
]
operations = [
migrations.CreateModel(
name='Mapping',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
('source', models.CharField(blank=True, max_length=120)),
('target', models.CharField(blank=True, max_length=120)),
('authentication', models.CharField(max_length=30)),
('testingpage', models.CharField(max_length=120)),
('webdav', models.BooleanField(default=False)),
('Comment', models.CharField(blank=True, max_length=500)),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={
'ordering': ('source'),
},
),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment