From 7e0a68772112978cd5e6ac2ed789e519b68d973f Mon Sep 17 00:00:00 2001 From: Marc Lebreuil Date: Sat, 8 Jun 2024 09:47:54 +0000 Subject: [PATCH 1/5] fix issue #135 --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 5 ++++ CONTRIBUTING.md | 43 ++++++++++++++++++++++++-------- requirement.txt | 2 +- src/netbox_contract/api/views.py | 6 ++--- src/netbox_contract/models.py | 3 +-- 6 files changed, 44 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5423953..e48b86d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: rev: 23.11.0 hooks: - id: black - language_version: python3.10 + language_version: python3.12 - repo: https://github.com/PyCQA/isort rev: 5.12.0 hooks: diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e66f2d..4c6adf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ ## Version 2 +### Version 2.1.1 + +* [127](https://github.com/mlebreuil/netbox-contract/issues/135) Fix service provider creation issue +* Fix contract assignement issue + ### Version 2.1.0 * Netbox v4 compatibility. Netbox4.0.2 become a minimum requirement diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index abd9537..03cd445 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,10 +49,7 @@ For each new feature or bug fix a branch is created from the corresponding issue ## Setup your development environment -```bash -python -m pip install pre-commit -pre-commit install -``` + 1. [Install Netbox](https://github.com/netbox-community/netbox/blob/develop/docs/installation/). Make sure taht at the Netbox installtion step you follow the "Option B: Clone the Git Repository" @@ -74,11 +71,20 @@ Make sure taht at the Netbox installtion step you follow the "Option B: Clone th 5. Add the plugin to NetBox virtual environment: ``` - $ python3 -m pip install -e netbox-contract + $ cd netbox-contract + $ python3 -m pip install -e . + ``` + +6. install pre-commit: + + ```bash + python -m pip install pre-commit + pre-commit install ``` -5. Update the Netbox configuration ans run the database migrations as mentionned in the plugin installation steps. -6. Create a branch for local development: +6. Update the Netbox configuration and run the database migrations as mentionned in the plugin installation steps. + +7. Create a branch for local development: ``` $ git checkout -b name-of-your-bugfix-or-feature @@ -86,7 +92,7 @@ Make sure taht at the Netbox installtion step you follow the "Option B: Clone th Make your changes locally. -7. You can test your changes using the django development server: +8. You can test your changes using the django development server: ``` $ python3 netbox/netbox/manage.py runserver 0.0.0.0:8000 --insecure @@ -94,7 +100,7 @@ Make sure taht at the Netbox installtion step you follow the "Option B: Clone th Connect to the name or IP of the server (as defined in ALLOWED_HOSTS) on port 8000; for example, http://127.0.0.1:8000/. -7. Commit your changes and push your branch to GitHub: +9. Commit your changes and push your branch to GitHub: ``` $ git add . @@ -102,7 +108,24 @@ Make sure taht at the Netbox installtion step you follow the "Option B: Clone th $ git push origin name-of-your-bugfix-or-feature ``` -7. Submit a pull request through the GitHub website. +10. Submit a pull request through the GitHub website. + +## Model changes + +Create the migrations: + +```bash +source netbox/venv/bin/activate +python3 netbox/netbox/manage.py makemigrations netbox_contract --dry-run +python3 netbox/netbox/manage.py makemigrations netbox_contract +``` + +Apply the migrations: + +```bash +source netbox/venv/bin/activate +python3 netbox/netbox/manage.py migrate +``` ## Pull Request Guidelines diff --git a/requirement.txt b/requirement.txt index 9feba4f..6474cfb 100644 --- a/requirement.txt +++ b/requirement.txt @@ -1,2 +1,2 @@ python-dateutil -drf_yasg \ No newline at end of file +drf_yasg diff --git a/src/netbox_contract/api/views.py b/src/netbox_contract/api/views.py index 35c06fb..2114dc2 100644 --- a/src/netbox_contract/api/views.py +++ b/src/netbox_contract/api/views.py @@ -11,9 +11,9 @@ class ContractViewSet(NetBoxModelViewSet): - queryset = models.Contract.objects.prefetch_related( - 'parent', 'circuit', 'tags' - ).annotate(yrc=F('mrc') * 12) + queryset = models.Contract.objects.prefetch_related('parent', 'tags').annotate( + yrc=F('mrc') * 12 + ) serializer_class = ContractSerializer diff --git a/src/netbox_contract/models.py b/src/netbox_contract/models.py index c104978..fc10d4c 100644 --- a/src/netbox_contract/models.py +++ b/src/netbox_contract/models.py @@ -1,4 +1,4 @@ -from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation +from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.db import models from django.urls import reverse @@ -43,7 +43,6 @@ class CurrencyChoices(ChoiceSet): class ServiceProvider(ContactsMixin, NetBoxModel): name = models.CharField(max_length=100) slug = models.SlugField(max_length=100, unique=True) - contacts = GenericRelation(to='tenancy.ContactAssignment') portal_url = models.URLField(blank=True, verbose_name='Portal URL') comments = models.TextField(blank=True) From a111432fba1fc88b338b830dde7210fe76883c70 Mon Sep 17 00:00:00 2001 From: mlebreuil Date: Sat, 8 Jun 2024 12:01:34 +0200 Subject: [PATCH 2/5] Update python-publish.yml --- .github/workflows/python-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 72d83ec..6d15880 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -28,7 +28,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: '3.x' - name: Install dependencies From cb132e72ded45588c5ae23b4ac742599c5b5a1b4 Mon Sep 17 00:00:00 2001 From: Marc Lebreuil Date: Sat, 8 Jun 2024 10:07:02 +0000 Subject: [PATCH 3/5] fix module version to 2.1.1 --- pyproject.toml | 2 +- src/netbox_contract/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index be12b19..9225b72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "netbox-contract" -version = "2.1.0" +version = "2.1.1" authors = [ { name="Marc Lebreuil", email="marc@famillelebreuil.net" }, ] diff --git a/src/netbox_contract/__init__.py b/src/netbox_contract/__init__.py index 8cac0f1..d6fd249 100644 --- a/src/netbox_contract/__init__.py +++ b/src/netbox_contract/__init__.py @@ -5,7 +5,7 @@ class ContractsConfig(PluginConfig): name = 'netbox_contract' verbose_name = 'Netbox contract' description = 'Contract management plugin for Netbox' - version = '2.1.0' + version = '2.1.1' author = 'Marc Lebreuil' author_email = 'marc@famillelebreuil.net' base_url = 'contracts' From aef7c37d1dcf1920292ba74f7dfeda92194e131d Mon Sep 17 00:00:00 2001 From: Marc Lebreuil Date: Sat, 8 Jun 2024 10:10:50 +0000 Subject: [PATCH 4/5] v2.1.2 --- pyproject.toml | 2 +- src/netbox_contract/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9225b72..0814615 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "netbox-contract" -version = "2.1.1" +version = "2.1.2" authors = [ { name="Marc Lebreuil", email="marc@famillelebreuil.net" }, ] diff --git a/src/netbox_contract/__init__.py b/src/netbox_contract/__init__.py index d6fd249..e85203c 100644 --- a/src/netbox_contract/__init__.py +++ b/src/netbox_contract/__init__.py @@ -5,7 +5,7 @@ class ContractsConfig(PluginConfig): name = 'netbox_contract' verbose_name = 'Netbox contract' description = 'Contract management plugin for Netbox' - version = '2.1.1' + version = '2.1.2' author = 'Marc Lebreuil' author_email = 'marc@famillelebreuil.net' base_url = 'contracts' From 8a7ef4766794b4ca465169dbf46560a854cd43c9 Mon Sep 17 00:00:00 2001 From: Marc Lebreuil Date: Sat, 8 Jun 2024 19:46:43 +0000 Subject: [PATCH 5/5] v2.1.2 Minor cosmetic changes --- CHANGELOG.md | 2 +- UTILS.md | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 UTILS.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6adf3..7b4fb13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ## Version 2 -### Version 2.1.1 +### Version 2.1.2 * [127](https://github.com/mlebreuil/netbox-contract/issues/135) Fix service provider creation issue * Fix contract assignement issue diff --git a/UTILS.md b/UTILS.md new file mode 100644 index 0000000..56516f8 --- /dev/null +++ b/UTILS.md @@ -0,0 +1,114 @@ +# Utils + +## Generating the distribution archives + +Note: This part is now automated with Github Actions. +Each time a release is created, a new package is created. + +Make sure the package version is incremented in the following files. +- pyproject.toml +- src/netbox_contract/__init__.py + +```bash +source netbox/venv/bin/activate +cd netbox-contract +python3 -m pip install --upgrade build +python3 -m build +``` + +## Update the package in the test pypi repository + + +```bash +source netbox/venv/bin/activate +python3 -m pip install --upgrade pip +python3 -m pip install --upgrade twine +python3 -m twine upload --repository testpypi dist/* +``` + +## Update the package in the pypi repository + +Note: This part is now automated with Github Actions. +Each time a release is created, a new package is created and uploaded to PyPI. + +```bash +source netbox/venv/bin/activate +python3 -m pip install --upgrade pip +python3 -m pip install --upgrade twine +python3 -m twine upload dist/* +``` + +## install the pluggin + +For development install from local file system with the "editable" option: + +git clone + +```bash +source netbox/venv/bin/activate +python3 -m pip uninstall netbox-contract +git clone https://github.com/mlebreuil/netbox-contract.git +python3 -m pip install -e netbox-contract +``` + +from the test respository: + +```bash +source netbox/venv/bin/activate +python3 -m pip uninstall netbox-contract +python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps netbox-contract +``` + +From the production repository: + +```bash +source netbox/venv/bin/activate +python3 -m pip uninstall netbox-contract +python3 -m pip install netbox-contract +``` + +Update netbox configuration + +```python +# configuration.py +PLUGINS = [ + 'netbox_contract', +] +``` + +update the database + +```bash +source netbox/venv/bin/activate +python netbox/netbox/manage.py migrate +``` + +## initialisze the database + +Install database package. +postgresql python adapter [psycopg](https://www.psycopg.org/docs/install.html) + +```bash +pip install psycopg2 +``` + +Run the initialization script + +```bash +cd .. +python3 database_init.py +``` + +## Backup and restore the db + +```bash +pg_dump --username netbox --password --host db netbox > netbox.sql +``` + +Restore: + +```bash +psql --host=db --username=postgres --password -c 'drop database netbox' +psql --host=db --username=postgres --password -c 'create database netbox' +psql --host=db --username=postgres --password netbox < netbox.sql +``` \ No newline at end of file