Skip to content

Commit

Permalink
Merge pull request #138 from mlebreuil/develop
Browse files Browse the repository at this point in the history
v2.1.2
  • Loading branch information
mlebreuil authored Jun 8, 2024
2 parents d7c93ec + 8a7ef47 commit f51fbbd
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

## Version 2

### Version 2.1.2

* [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
Expand Down
43 changes: 33 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -74,35 +71,61 @@ 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
```
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
```
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 .
$ git commit -m "Your detailed description of your changes."
$ 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

Expand Down
114 changes: 114 additions & 0 deletions UTILS.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "netbox-contract"
version = "2.1.0"
version = "2.1.2"
authors = [
{ name="Marc Lebreuil", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion requirement.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
python-dateutil
drf_yasg
drf_yasg
2 changes: 1 addition & 1 deletion src/netbox_contract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.2'
author = 'Marc Lebreuil'
author_email = '[email protected]'
base_url = 'contracts'
Expand Down
6 changes: 3 additions & 3 deletions src/netbox_contract/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 1 addition & 2 deletions src/netbox_contract/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f51fbbd

Please sign in to comment.