Skip to content

Commit 849ab3e

Browse files
Replace dolt with nautobot_version_control (#162)
* Update base URL and other plugin info * The great renaming * Improve database migration commit message * Fix tasks * Cleanup
1 parent cbad819 commit 849ab3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+231
-222
lines changed

.github/workflows/ci.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
black:
99
runs-on: "ubuntu-20.04"
1010
env:
11-
INVOKE_NAUTOBOT_DOLT_LOCAL: "True"
11+
INVOKE_NAUTOBOT_VERSION_CONTROL_LOCAL: "True"
1212
steps:
1313
- name: "Check out repository code"
1414
uses: "actions/checkout@v2"
@@ -19,7 +19,7 @@ jobs:
1919
bandit:
2020
runs-on: "ubuntu-20.04"
2121
env:
22-
INVOKE_NAUTOBOT_DOLT_LOCAL: "True"
22+
INVOKE_NAUTOBOT_VERSION_CONTROL_LOCAL: "True"
2323
steps:
2424
- name: "Check out repository code"
2525
uses: "actions/checkout@v2"
@@ -33,7 +33,7 @@ jobs:
3333
pydocstyle:
3434
runs-on: "ubuntu-20.04"
3535
env:
36-
INVOKE_NAUTOBOT_DOLT_LOCAL: "True"
36+
INVOKE_NAUTOBOT_VERSION_CONTROL_LOCAL: "True"
3737
steps:
3838
- name: "Check out repository code"
3939
uses: "actions/checkout@v2"
@@ -47,7 +47,7 @@ jobs:
4747
flake8:
4848
runs-on: "ubuntu-20.04"
4949
env:
50-
INVOKE_NAUTOBOT_DOLT_LOCAL: "True"
50+
INVOKE_NAUTOBOT_VERSION_CONTROL_LOCAL: "True"
5151
steps:
5252
- name: "Check out repository code"
5353
uses: "actions/checkout@v2"
@@ -61,7 +61,7 @@ jobs:
6161
yamllint:
6262
runs-on: "ubuntu-20.04"
6363
env:
64-
INVOKE_NAUTOBOT_DOLT_LOCAL: "True"
64+
INVOKE_NAUTOBOT_VERSION_CONTROL_LOCAL: "True"
6565
steps:
6666
- name: "Check out repository code"
6767
uses: "actions/checkout@v2"
@@ -110,11 +110,11 @@ jobs:
110110
fail-fast: true
111111
matrix:
112112
python-version: ["3.6", "3.7", "3.8", "3.9"]
113-
nautobot-version: ["1.1.2"]
113+
nautobot-version: ["1.2.0-beta.1"]
114114
runs-on: "ubuntu-20.04"
115115
env:
116-
INVOKE_NAUTOBOT_DOLT_PYTHON_VER: "${{ matrix.python-version }}"
117-
INVOKE_NAUTOBOT_DOLT_NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
116+
INVOKE_NAUTOBOT_VERSION_CONTROL_PYTHON_VER: "${{ matrix.python-version }}"
117+
INVOKE_NAUTOBOT_VERSION_CONTROL_NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
118118
steps:
119119
- name: "Check out repository code"
120120
uses: "actions/checkout@v2"

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ Add this to your `nautobot_config.py`:
199199
# database so that it may generate diffs.
200200
DATABASES["global"] = DATABASES["default"]
201201

202-
# Add Dolt to your list of plugins.
202+
# Add Nautobot Version Control to your list of plugins.
203203
PLUGINS += [
204-
"dolt",
204+
"nautobot_version_control",
205205
]
206206
```
207207

@@ -215,7 +215,7 @@ After migrations have been run, then you must enable the `DATABASE_ROUTERS` requ
215215

216216
```python
217217
# Dolt requires a custom database router to generate the before & after queries for generating diffs.
218-
DATABASE_ROUTERS = ["dolt.routers.GlobalStateRouter"]
218+
DATABASE_ROUTERS = ["nautobot_version_control.routers.GlobalStateRouter"]
219219
```
220220

221221
Note that any time you need to perform database migrations (such as when upgrading Nautobot or Dolt) you **absolutely must comment out/disable `DATABASE_ROUTERS` from your `nautobot_config.py`** or you will encounter errors.
@@ -226,4 +226,4 @@ To be written
226226

227227
### Version Control Installation (migrating an existing Nautobot install)
228228

229-
To be written
229+
To be written

development/docker-compose.dev.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ version: "3.4"
77
services:
88
nautobot:
99
environment:
10-
DATABASE_ROUTERS: "dolt.routers.GlobalStateRouter"
10+
DATABASE_ROUTERS: "nautobot_version_control.routers.GlobalStateRouter"
1111
command: "nautobot-server runserver 0.0.0.0:8080"
1212
volumes:
1313
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
1414
- "../:/source"
1515
worker:
1616
environment:
17-
DATABASE_ROUTERS: "dolt.routers.GlobalStateRouter"
17+
DATABASE_ROUTERS: "nautobot_version_control.routers.GlobalStateRouter"
1818
volumes:
1919
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
2020
- "../:/source"

development/nautobot_config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def is_truthy(arg):
6161
"PORT": os.getenv("DOLT_PORT", ""), # Database port (leave blank for default)
6262
"ENGINE": "django.db.backends.mysql",
6363
},
64-
# TODO: use `dolt.constants.GLOBAL_STATE_DB`
64+
# TODO: use `nautobot_version_control.constants.GLOBAL_STATE_DB`
6565
"global": {
66-
# TODO: use `dolt.constants.DOLT_DEFAULT_BRANCH`
66+
# TODO: use `nautobot_version_control.constants.DOLT_DEFAULT_BRANCH`
6767
"NAME": "nautobot", # Database username
6868
"USER": os.getenv("DOLT_USER", ""), # Database username
6969
"PASSWORD": os.getenv("DOLT_PASSWORD", ""), # Database password
@@ -263,7 +263,7 @@ def is_truthy(arg):
263263

264264
# Enable installed plugins. Add the name of each plugin to the list.
265265
PLUGINS = [
266-
"dolt",
266+
"nautobot_version_control",
267267
]
268268

269269
# Pull the list of routers from environment variable to be able to disable all routers when we are running the migrations

docs/design.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ When the server receives a request, it looks for this state and uses it to selec
4646
![active branch banner](images/active-branch-banner.png)
4747

4848
The business logic to handle branch selection is performed in [middleware](https://docs.djangoproject.com/en/stable/topics/http/middleware/),
49-
specifically in [DoltBranchMiddleware](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/middleware.py#L36)
49+
specifically in [DoltBranchMiddleware](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/middleware.py#L36)
5050

5151
## Database Versioning
5252

@@ -55,8 +55,8 @@ Database connections outside of the web server, such as through nbshell are also
5555
When connecting directly to the database you can check your current branch with the active_branch() function and switch branches with the checkout() method:
5656

5757
```python
58-
>>> from dolt.models import Branch
59-
>>> from dolt.utils import active_branch
58+
>>> from nautobot_version_control.models import Branch
59+
>>> from nautobot_version_control.utils import active_branch
6060
>>> active_branch()
6161
'main'
6262
>>> Branch.objects.get(name="foo").checkout()
@@ -70,13 +70,13 @@ The Version Control app extends the Nautobot's core [REST API](https://nautobot.
7070

7171
## REST API EndPoints
7272

73-
The top level API endpoint is `/api/plugins/dolt/`.
73+
The top level API endpoint is `/api/plugins/version-control/`.
7474
Below this, there are endpoints for the following models:
7575

76-
- Branch: `api/plugins/dolt/branches`
77-
- Commit: `api/plugins/dolt/commits`
78-
- Pull Request: `api/plugins/dolt/pull_requests`
79-
- Pull Request Reviews: `api/plugins/dolt/pull_requests_reviews`
76+
- Branch: `api/plugins/version-control/branches`
77+
- Commit: `api/plugins/version-control/commits`
78+
- Pull Request: `api/plugins/version-control/pull_requests`
79+
- Pull Request Reviews: `api/plugins/version-control/pull_requests_reviews`
8080

8181
The Version Control API shares a common implementation with Nautobot's core API.
8282
Features suchs as [pagination](https://nautobot.readthedocs.io/en/stable/rest-api/overview/#pagination) and
@@ -96,7 +96,7 @@ For example, the following request will list all the commits from `my-feature-br
9696
$ curl -s \
9797
-H "Authorization: Token 90579810c8d2d2e98fb34d69025f6a1cc3fa9943" \
9898
-H "dolt-branch: my-feature-branch" \
99-
0.0.0.0:8080/api/plugins/dolt/commits/
99+
0.0.0.0:8080/api/plugins/version-control/commits/
100100
```
101101

102102
Versioning requests works with all API endpoints, not just models from the Version Control app. This example queries for devices in a `my-branch`:
@@ -133,18 +133,18 @@ pprint(response.json())
133133
## Commit Logic
134134

135135
The committing logic is implemented using a combination of middleware and [Django signals](https://docs.djangoproject.com/en/stable/topics/signals/),
136-
specifically [DoltAutoCommitMiddleWare](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/middleware.py#L118).
137-
DoltAutoCommitMiddleWare wraps every server request in a [AutoDoltCommit](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/middleware.py#L134)
136+
specifically [DoltAutoCommitMiddleWare](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/middleware.py#L118).
137+
DoltAutoCommitMiddleWare wraps every server request in a [AutoDoltCommit](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/middleware.py#L134)
138138
context manager which listens for and responds to database writes made while processing the request.
139139
AutoDoltCommit listens for signals fired by Django model updates and makes a Dolt commit if updates were made during the lifetime of the context manager.
140140
The message for the commit is derived from the model signals that were captured.
141141

142142
## DoltSystemTables
143143

144-
[DoltSystemTable](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/models.py#L22)
144+
[DoltSystemTable](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/models.py#L22)
145145
is an abstract base class that forms the basis of Django models that expose Dolt system tables
146146
to the Object Relational Mapping (ORM).
147-
Plugin models such as *Commit* and *Branch* that inherit from DoltSystemTable are [unmanaged](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/models.py#L31
147+
Plugin models such as *Commit* and *Branch* that inherit from DoltSystemTable are [unmanaged](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/models.py#L31
148148
meaning that Django will ignore these models for the purposes of database migrations.
149149
This is important because Dolt system tables exist from the time the database is created and cannot be modified or deleted.
150150
Internally, Dolt generates system table data on-the-fly rather than reading it from a traditional database index.
@@ -154,7 +154,7 @@ Internally, Dolt generates system table data on-the-fly rather than reading it f
154154
The Branch model is one such "unmanaged" model.
155155
It exposes the dolt_branches system table to the ORM.
156156
System tables have a static schema, so additional object fields such as "created by" and "source branch" must be stored in another model.
157-
The [BranchMeta](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/models.py#L205) model does exactly that.
157+
The [BranchMeta](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/models.py#L205) model does exactly that.
158158
Each Branch object has an associated BranchMeta object where the `BranchMeta.branch field` is equal to the name field of the associated branch.
159159
However, this relationship is not formalized with a Foreign Key due to limitations with the dolt_branches table.
160160
Branch objects lookup their associated BranchMeta objects on a best-effort basis.
@@ -194,15 +194,15 @@ Non-versioned models:
194194
## Global State Router
195195

196196
The business logic for differentiating versioned and non-versioned models is implemented in a Django [database router](https://docs.djangoproject.com/en/stable/topics/db/multi-db/#automatic-database-routing),
197-
specifically the [GlobalStateRouter](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/routers.py#L10).
197+
specifically the [GlobalStateRouter](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/routers.py#L10).
198198
The GlobalStateRouter is responsible for choosing a database connection to read an object from or write an object to, depending on its model class.
199199
There are two connections to choose from when accessing the database.
200200
The “default” connection will access the database on the Dolt branch that was specified in the request.
201201
This connection is used to read and write versioned models.
202202
The “global” connection always accesses the database on the main branch, it is used for non-versioned models.
203203

204204
In order to choose a connection for a model, the router first references the
205-
[versioned model registry](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/__init__.py#L87)
205+
[versioned model registry](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/__init__.py#L87)
206206
to determine if the model is under version control.
207207
Currently, this registry is a hardcoded mapping from ContentType to versioned/non-versioned.
208208
The versioned model registry is structured as an ["allow-list"](https://help.dnsfilter.com/hc/en-us/articles/1500008111381-Allow-and-Block-Lists).
@@ -211,7 +211,7 @@ If a model is absent from the list, it is assumed to be non-versioned.
211211
in Nautobot core will make it possible for models to declare themselves whether they should be version controlled.
212212

213213
Database connections for versioned and non-versioned models are defined in
214-
[nautobot_config.py](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/development/nautobot_config.py#L55).
214+
[nautobot_config.py](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/development/nautobot_config.py#L55).
215215
The database configuration is as follows:
216216
```python
217217
DATABASES = {
@@ -259,7 +259,7 @@ Custom rendering functions are added to apply diff styling to the list view.
259259

260260
Diff table classes are created dynamically at runtime.
261261
When a diff table is needed to display model changes, the core model's table is looked up from the
262-
[diff table registry](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/__init__.py#L179)
262+
[diff table registry](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/__init__.py#L179)
263263
and then a new subclass is created to extend the core table.
264264
The diff table registry works much like the versioned model registry, it is a mapping from a models content type to its table.
265265
Tables in Nautobot core are all subclasses of [`django-tables2`](https://django-tables2.readthedocs.io/en/latest/).
@@ -270,8 +270,8 @@ All entries in the diff table registry must also be subclasses of `django-tables
270270
The Version Control app is designed to be used in coordination with other Nautobot plugins.
271271
By default, any models registered by other plugins will be considered non-versioned.
272272
In order to make use of version control and diff features, plugins must register their models in
273-
the [versioned models registry](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/__init__.py#L143)
274-
and the [diff table registry](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/dolt/__init__.py#L190).
273+
the [versioned models registry](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/__init__.py#L143)
274+
and the [diff table registry](https://github.com/nautobot/nautobot-plugin-version-control/blob/develop/nautobot_version_control/__init__.py#L190).
275275
Both of these functions take nested dictionaries as arguments:
276276
```python
277277
register_versioned_models({

dolt/__init__.py nautobot_version_control/__init__.py

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
""" This is the main module that contains the code for the Dolt backed Version Control plugin. """
2+
try:
3+
from importlib import metadata
4+
except ImportError:
5+
# Python version < 3.8
6+
import importlib_metadata as metadata
27

38
from django.db.models.signals import pre_migrate, post_migrate
9+
import django_tables2
410

511
from nautobot.extras.plugins import PluginConfig
612

7-
import django_tables2
13+
from nautobot_version_control.migrations import auto_dolt_commit_migration
814

9-
from dolt.migrations import auto_dolt_commit_migration
15+
__version__ = metadata.version(__name__)
1016

1117

12-
class NautobotDolt(PluginConfig):
13-
"""NautobotDolt initializes the dolt configs, middleware, and sets up migrations."""
18+
class NautobotVersionControl(PluginConfig):
19+
"""NautobotVersionControl initializes the dolt configs, middleware, and sets up migrations."""
1420

15-
name = "dolt"
16-
verbose_name = "Nautobot Dolt"
17-
description = "Nautobot + Dolt"
18-
version = "0.1"
19-
author = "Andy Arthur"
20-
author_email = "[email protected]"
21+
name = "nautobot_version_control"
22+
verbose_name = "Nautobot Version Control"
23+
description = "Nautobot Version Control with Dolt"
24+
base_url = "version-control"
25+
version = __version__
26+
author = "Network to Code, LLC"
27+
author_email = "[email protected]"
28+
min_version = "1.2.0-beta.1"
29+
max_version = "1.999"
2130
required_settings = []
2231
default_settings = {
2332
# TODO: are these respected?
2433
# this is also set in /development/nautobot_config.py
2534
"DATABASE_ROUTERS": [
26-
"dolt.routers.GlobalStateRouter",
35+
"nautobot_version_control.routers.GlobalStateRouter",
2736
],
2837
"SESSION_ENGINE": "django.contrib.sessions.backends.signed_cookies",
2938
"CACHEOPS_ENABLED": False,
3039
}
3140
middleware = [
32-
"dolt.middleware.dolt_health_check_intercept_middleware",
33-
"dolt.middleware.DoltBranchMiddleware",
34-
"dolt.middleware.DoltAutoCommitMiddleware",
41+
"nautobot_version_control.middleware.dolt_health_check_intercept_middleware",
42+
"nautobot_version_control.middleware.DoltBranchMiddleware",
43+
"nautobot_version_control.middleware.DoltAutoCommitMiddleware",
3544
]
3645

3746
def ready(self):
@@ -45,7 +54,7 @@ def ready(self):
4554
post_migrate.connect(auto_dolt_commit_migration, sender=self)
4655

4756

48-
config = NautobotDolt # pylint: disable=C0103
57+
config = NautobotVersionControl # pylint: disable=C0103
4958

5059

5160
def query_registry(model, registry):
@@ -85,7 +94,7 @@ def query_registry(model, registry):
8594
# may also be a nest dict containing a subset of version-controlled models
8695
# within the app_label.
8796
__VERSIONED_MODEL_REGISTRY___ = {
88-
"dolt": {
97+
"nautobot_version_control": {
8998
# Pull Requests are not versioned
9099
"pullrequest": False,
91100
"pullrequestreviewcomments": False,
File renamed without changes.
File renamed without changes.

dolt/api/serializers.py nautobot_version_control/api/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""serializers.py implements serializers for different modules."""
22
from nautobot.core.api import ValidatedModelSerializer
3-
from dolt.models import Branch, Commit, PullRequest, PullRequestReview
3+
from nautobot_version_control.models import Branch, Commit, PullRequest, PullRequestReview
44

55

66
class BranchSerializer(ValidatedModelSerializer):

dolt/api/urls.py nautobot_version_control/api/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
router.register("pull_requests", views.PullRequestViewSet)
1414
router.register("pull_requests_reviews", views.PullRequestReviewViewSet)
1515

16-
app_name = "dolt-api"
16+
app_name = "nautobot_version_control-api"
1717
urlpatterns = router.urls

dolt/api/views.py nautobot_version_control/api/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from rest_framework.routers import APIRootView
44
from nautobot.extras.api.views import CustomFieldModelViewSet
55

6-
from dolt import filters
7-
from dolt.models import Branch, Commit, PullRequest, PullRequestReview
6+
from nautobot_version_control import filters
7+
from nautobot_version_control.models import Branch, Commit, PullRequest, PullRequestReview
88

99
from . import serializers
1010

dolt/banner.py nautobot_version_control/banner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from nautobot.extras.choices import BannerClassChoices
66
from nautobot.extras.plugins import PluginBanner
77

8-
from dolt.constants import DOLT_BRANCH_KEYWORD
9-
from dolt.utils import active_branch
8+
from nautobot_version_control.constants import DOLT_BRANCH_KEYWORD
9+
from nautobot_version_control.utils import active_branch
1010

1111

1212
def banner(context, *args, **kwargs):
File renamed without changes.
File renamed without changes.
File renamed without changes.

dolt/diffs.py nautobot_version_control/diffs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from nautobot.tenancy import tables as tenancy_tables
1313
from nautobot.virtualization import tables as virtualization_tables
1414

15-
from dolt.dynamic.diff_factory import DiffListViewFactory
16-
from dolt.models import Commit
17-
from dolt.utils import db_for_commit
15+
from nautobot_version_control.dynamic.diff_factory import DiffListViewFactory
16+
from nautobot_version_control.models import Commit
17+
from nautobot_version_control.utils import db_for_commit
1818

1919
from . import diff_table_for_model, register_diff_tables
2020

File renamed without changes.

0 commit comments

Comments
 (0)