Skip to content

Commit f35fcb3

Browse files
committed
docs
1 parent 739eaf8 commit f35fcb3

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Validity is the [NetBox](https://netboxlabs.com/oss/netbox/) plugin to write "au
1515

1616
* **Configuration compliance**. You can make sure your devices are provisioned properly, and their config follows the rules you have defined via tests.
1717
* **Pre- / post-configuration checks**. You can make sure your network is in the expected state before or/and after configuration changes have been made. You can use Validity API to include these checks into your automation pipelines.
18+
* **Config Backup**. Save your device configs to **Git** or **AWS S3**
1819

1920
**Validity usage workflow:**
2021

@@ -40,7 +41,6 @@ Validity completely separates compliance test code from all the other things lik
4041
* Truly vendor-agnostic. You can easily integrate any vendor config format using [TTP](https://github.com/dmulyalin/ttp) or a bunch of other [serialization options](https://validity.readthedocs.io/en/latest/entities/serializers/)
4142
* Writing compliance tests using Python expressions and [JQ](https://stedolan.github.io/jq/manual/)
4243
* Gathering configuration or state info directly from the devices via **SSH**, **Telnet**, **Netconf** or **REST API**.
43-
* Flexible selector system to apply the tests only to a specific subset of devices
4444
* Concept of **dynamic pairs**. With dynamic pair you can compare 2 different devices between each other (e.g. compare the configuration of 2 MC-LAG members).
4545
* **Test result explanation**. When some test fails, you can get the **explanation** of the calculation process step by step. It helps to identify the cause of the failure.
4646
* **ORM access** inside the test. You have full access to the **device** properties. For instance, you may leverage [Configuration Contexts](https://docs.netbox.dev/en/stable/features/context-data/) NetBox feature to store your desired configuration and compare it with the config collected from the device.

docs/entities/backuppoints.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Backup Points
2+
3+
If a [Data Source](https://netboxlabs.com/docs/netbox/en/stable/models/core/datasource/) is used to download data to NetBox, **Backup Point** solves the opposite task, it can **upload** data source contents to some external storage. This is mostly suitable for performing [device configuration backup](../features/config_backup.md).
4+
5+
Currently **Git** and **AWS S3** backup methods are available.
6+
7+
## Fields
8+
9+
#### Name
10+
The Name of the Backup Point. Must be unique.
11+
12+
#### Data Source
13+
Data Source which is going to be backed up. Only Data Sources with the type [device_polling](datasources.md) are allowed to be used here.
14+
15+
#### Back Up After Sync
16+
If this param is `True`, backup will be performed each time respective Data Source is synced. For instance, you press "Sync" button on the Data Source page, sync is performed and after that Data Source contents are uploaded to the destination(s) specified in all bound Backup Points.
17+
18+
#### Method
19+
Defines protocol for uploading the Data Source.
20+
21+
Available options are:
22+
* Git (over http(s))
23+
* Amazon S3 (or any other S3-compatible service)
24+
25+
#### URL
26+
URL of the endpoint where the Data Source contents will be uploaded.
27+
28+
Examples of the URLs:
29+
30+
| Method | Example URL |
31+
|---------------|------------------------------------------------------------|
32+
| Git | `https://github.com/amyasnikov/my_awesome_repo` |
33+
| S3 no-archive | `https://s3.eu-north-1.amazonaws.com/bucket_name/folder` |
34+
| S3 archive | `https://s3.eu-north-1.amazonaws.com/bucket_name/arch.zip` |
35+
36+
37+
#### Ignore Rules
38+
A set of rules (one per line) identifying filenames to ignore during Data Source backup. Some examples are provided below. See Python's [fnmatch()](https://docs.python.org/3/library/fnmatch.html) documentation for a complete reference.
39+
40+
| Rule | Description |
41+
|--------------------|--------------------------------------------------------------|
42+
| `folder/file.json` | Do not back up one specific file |
43+
| `*.txt` | Do not back up all files with **txt** extension |
44+
| `router-??.txt` | Do not back up files like `router-11.txt` and `router-ab.txt` |
45+
46+
47+
#### Git-specific parameters
48+
* **Username**, **Password** - credentials to perform HTTP authentication, and access the repository
49+
* **Branch** - git branch. Default repository branch will be used if the field is empty
50+
51+
#### S3-specific parameters
52+
* **AWS access key ID**, **AWS secret access key** - credentials to perform authentication in S3 service
53+
* **archive** - if this field is True, Data Source contents will be packed into ZIP archive and then uploaded

docs/entities/datasources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Data Source can be used in the following ways:
55

66
* Store configuration or state data for all or particular devices
77
* Be referenced by another entity containing any text information. By this moment, these entities are **Tests**, **Name Sets** and **Serializers**.
8-
* Data Source called **Validity Polling** is used to poll network devices and collect gathered information
8+
* Data Source called **Validity Polling** (with type **device_polling**) is used to poll network devices and collect gathered information
99

1010
## Custom Fields
1111

docs/features/config_backup.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Configuration Backup
2+
3+
Validity supports device configurations backups to remote **Git** or **S3** server(s).
4+
5+
## Backup provisioning
6+
7+
1. Follow the steps described in the [Quickstart: Polling](../quickstart_polling.md) article to set up all the entities required for device polling.
8+
9+
2. Polling is done when the Data Source is synced. In most cases it will be the default **Validity Polling** Data Source, but you are free to create your own one with the type *device_polling*.
10+
11+
3. Create a [Backup Point](../entities/backuppoints.md) which describes a place where the Data Source with the configs have to be uploaded.
12+
13+
Example using pynetbox:
14+
15+
```python
16+
import pynetbox
17+
18+
nb = pynetbox.api('http://localhost:8000', token=nb_token)
19+
20+
validity_polling = nb.core.data_sources.get(name="Validity Polling")
21+
22+
nb.plugins.validity.backup_points.create(
23+
name='my_github_repo',
24+
data_source=data_source.id,
25+
upload_url='https://github.com/amyasnikov/my_repo',
26+
method='git',
27+
parameters={"username": "amyasnikov", "password": github_token}
28+
)
29+
```
30+
31+
## Backing Up
32+
33+
There are several options to trigger the backup process:
34+
35+
* Press "Back Up" button on the Backup Point page.
36+
37+
* Specify `Backup After Sync: True` in the Backup Point settings. This will trigger the backup process each time the respective data source is being synced (no matter via button, API or somehow else).
38+
39+
* Execute [RunTests](../entities/scripts.md#run-tests) script with `Sync Data Sources: True` option (`Backup After Sync: True` is required as well).
40+
41+
42+
### Options for periodic backup
43+
44+
There are several options to provision periodic configuration backup process (e.g. daily, each 6 hours, etc):
45+
46+
1. Provision [RunTests](../entities/scripts.md#run-tests) script to execute on a regular basis using **Interval** script parameter. This will run everything at once:
47+
* poll the devices (perform data source sync)
48+
* execute compliance tests
49+
* back up the data source
50+
51+
52+
2. If you don't want to run the tests via scheduler and want backup only, you can create tiny [custom script](https://netboxlabs.com/docs/netbox/en/stable/customization/custom-scripts/) inside your NetBox and configure it to run periodically.
53+
54+
```python
55+
from core.models import DataSource
56+
from extras.scripts import Script, ObjectVar
57+
58+
class SyncDataSource(Script):
59+
data_source = ObjectVar(model=DataSource)
60+
61+
def run(self, data, commit):
62+
data['data_source'].sync()
63+
64+
```
65+
66+
Execution of this script triggers the sync of the DataSource (and hence the backup process for bound Backup points with `Backup After Sync: True`).
67+
68+
3. Wait till periodic Data Source sync is implemented in the core NetBox. There is an [issue](https://github.com/netbox-community/netbox/issues/18287) for it, upvotes are appreciated.

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ nav:
1919
- Results & Reports: entities/results_and_reports.md
2020
- Pollers: entities/pollers.md
2121
- Commands: entities/commands.md
22+
- Backup Points: entities/backuppoints.md
2223
- Scripts: entities/scripts.md
2324
- Features & Tips:
2425
- How to write the Tests: features/howto_write_tests.md
2526
- How to work with Device State: features/state.md
2627
- Dynamic Pairs: features/dynamic_pairs.md
2728
- Webhooks: features/webhooks.md
29+
- Config backup: features/config_backup.md
2830

2931
markdown_extensions:
3032
- pymdownx.highlight:

0 commit comments

Comments
 (0)