snapdelta 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snapdelta-0.1.0/.gitignore +5 -0
- snapdelta-0.1.0/LICENSE +202 -0
- snapdelta-0.1.0/PKG-INFO +72 -0
- snapdelta-0.1.0/README.md +40 -0
- snapdelta-0.1.0/pyproject.toml +40 -0
- snapdelta-0.1.0/src/snapdelta/__init__.py +5 -0
- snapdelta-0.1.0/src/snapdelta/about.py +50 -0
- snapdelta-0.1.0/src/snapdelta/activity.py +182 -0
- snapdelta-0.1.0/src/snapdelta/catalog.py +160 -0
- snapdelta-0.1.0/src/snapdelta/cli.py +528 -0
- snapdelta-0.1.0/src/snapdelta/errors.py +36 -0
- snapdelta-0.1.0/src/snapdelta/inputs.py +26 -0
- snapdelta-0.1.0/src/snapdelta/inventory.py +177 -0
- snapdelta-0.1.0/src/snapdelta/jsonfile.py +36 -0
- snapdelta-0.1.0/src/snapdelta/output.py +202 -0
- snapdelta-0.1.0/src/snapdelta/parallel.py +37 -0
- snapdelta-0.1.0/src/snapdelta/profile.py +191 -0
- snapdelta-0.1.0/src/snapdelta/py.typed +0 -0
- snapdelta-0.1.0/src/snapdelta/render.py +257 -0
- snapdelta-0.1.0/src/snapdelta/settings.py +634 -0
- snapdelta-0.1.0/src/snapdelta/snapshot.py +108 -0
- snapdelta-0.1.0/src/snapdelta/source.py +213 -0
- snapdelta-0.1.0/src/snapdelta/store.py +728 -0
- snapdelta-0.1.0/src/snapdelta/take.py +296 -0
- snapdelta-0.1.0/tests/conftest.py +71 -0
- snapdelta-0.1.0/tests/test_activity.py +104 -0
- snapdelta-0.1.0/tests/test_catalog.py +59 -0
- snapdelta-0.1.0/tests/test_cli.py +347 -0
- snapdelta-0.1.0/tests/test_inputs.py +9 -0
- snapdelta-0.1.0/tests/test_inventory.py +143 -0
- snapdelta-0.1.0/tests/test_output.py +101 -0
- snapdelta-0.1.0/tests/test_package.py +5 -0
- snapdelta-0.1.0/tests/test_parallel.py +65 -0
- snapdelta-0.1.0/tests/test_profile.py +114 -0
- snapdelta-0.1.0/tests/test_render.py +73 -0
- snapdelta-0.1.0/tests/test_settings.py +296 -0
- snapdelta-0.1.0/tests/test_snapshot.py +98 -0
- snapdelta-0.1.0/tests/test_source.py +150 -0
- snapdelta-0.1.0/tests/test_store.py +232 -0
- snapdelta-0.1.0/tests/test_take.py +77 -0
snapdelta-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
snapdelta-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: snapdelta
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Snapshot your devices and services, then see exactly what changed: CLI and Python API, built on diffsync
|
|
5
|
+
Project-URL: Homepage, https://github.com/antoinekh/snapdelta
|
|
6
|
+
Project-URL: Documentation, https://github.com/antoinekh/snapdelta/tree/main/docs
|
|
7
|
+
Project-URL: Issues, https://github.com/antoinekh/snapdelta/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/antoinekh/snapdelta/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Antoine Keranflec'h <antoine.keranflech@gmail.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: diff,diffsync,netdevops,network-automation,nornir,snapshot
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: Intended Audience :: Telecommunications Industry
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: System :: Networking
|
|
23
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.13
|
|
26
|
+
Requires-Dist: diffsync<3,>=2.2
|
|
27
|
+
Requires-Dist: pydantic>=2.7
|
|
28
|
+
Requires-Dist: pyyaml>=6
|
|
29
|
+
Requires-Dist: tomlkit>=0.15
|
|
30
|
+
Requires-Dist: typer>=0.12
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<img src="https://raw.githubusercontent.com/antoinekh/snapdelta/main/docs/images/logo-wordmark-light.svg" width="400" alt="snapdelta" />
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
**Snapshot your devices and services, then see exactly what changed.**
|
|
38
|
+
|
|
39
|
+
Take a snapshot of anything, then compare two snapshots. A plugin brings the [diffsync](https://github.com/networktocode/diffsync) models and a source: the way to get the data of one target, from input files, an API, NETCONF or SSH. snapdelta saves each load as a snapshot, compares two snapshots on their models, not on text, and shows what changed.
|
|
40
|
+
|
|
41
|
+
This package is the core and the `snapdelta` CLI. The web UI, the JSON API and the MCP server are in [snapdelta-web](https://pypi.org/project/snapdelta-web/).
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
snapdelta needs Python 3.13 or later. In your plugin project:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
uv add snapdelta snapdelta-web
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Use it
|
|
52
|
+
|
|
53
|
+
With a plugin source installed (here `my-source`):
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
snapdelta snapshot --source my-source --all-targets --label before
|
|
57
|
+
snapdelta snapshot --source my-source --all-targets --label after
|
|
58
|
+
snapdelta diff R1@before R1@after
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Documentation
|
|
62
|
+
|
|
63
|
+
- [Getting started](https://github.com/antoinekh/snapdelta/blob/main/docs/getting-started.md): your own project, step by step
|
|
64
|
+
- [Architecture](https://github.com/antoinekh/snapdelta/blob/main/docs/architecture.md): the parts and the extension points
|
|
65
|
+
- [Profiles](https://github.com/antoinekh/snapdelta/blob/main/docs/profiles.md): ignore, tolerance, counts, pairs
|
|
66
|
+
- [Inventory](https://github.com/antoinekh/snapdelta/blob/main/docs/inventory.md): the optional Nornir inventory
|
|
67
|
+
- [Settings](https://github.com/antoinekh/snapdelta/blob/main/docs/settings.md): every key of `snapdelta.toml`
|
|
68
|
+
- [Changelog](https://github.com/antoinekh/snapdelta/blob/main/CHANGELOG.md)
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
Apache License 2.0.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/antoinekh/snapdelta/main/docs/images/logo-wordmark-light.svg" width="400" alt="snapdelta" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
**Snapshot your devices and services, then see exactly what changed.**
|
|
6
|
+
|
|
7
|
+
Take a snapshot of anything, then compare two snapshots. A plugin brings the [diffsync](https://github.com/networktocode/diffsync) models and a source: the way to get the data of one target, from input files, an API, NETCONF or SSH. snapdelta saves each load as a snapshot, compares two snapshots on their models, not on text, and shows what changed.
|
|
8
|
+
|
|
9
|
+
This package is the core and the `snapdelta` CLI. The web UI, the JSON API and the MCP server are in [snapdelta-web](https://pypi.org/project/snapdelta-web/).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
snapdelta needs Python 3.13 or later. In your plugin project:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
uv add snapdelta snapdelta-web
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Use it
|
|
20
|
+
|
|
21
|
+
With a plugin source installed (here `my-source`):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
snapdelta snapshot --source my-source --all-targets --label before
|
|
25
|
+
snapdelta snapshot --source my-source --all-targets --label after
|
|
26
|
+
snapdelta diff R1@before R1@after
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
- [Getting started](https://github.com/antoinekh/snapdelta/blob/main/docs/getting-started.md): your own project, step by step
|
|
32
|
+
- [Architecture](https://github.com/antoinekh/snapdelta/blob/main/docs/architecture.md): the parts and the extension points
|
|
33
|
+
- [Profiles](https://github.com/antoinekh/snapdelta/blob/main/docs/profiles.md): ignore, tolerance, counts, pairs
|
|
34
|
+
- [Inventory](https://github.com/antoinekh/snapdelta/blob/main/docs/inventory.md): the optional Nornir inventory
|
|
35
|
+
- [Settings](https://github.com/antoinekh/snapdelta/blob/main/docs/settings.md): every key of `snapdelta.toml`
|
|
36
|
+
- [Changelog](https://github.com/antoinekh/snapdelta/blob/main/CHANGELOG.md)
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
Apache License 2.0.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "snapdelta"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Snapshot your devices and services, then see exactly what changed: CLI and Python API, built on diffsync"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
authors = [{ name = "Antoine Keranflec'h", email = "antoine.keranflech@gmail.com" }]
|
|
9
|
+
keywords = ["network-automation", "netdevops", "snapshot", "diff", "diffsync", "nornir"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 3 - Alpha",
|
|
12
|
+
"Environment :: Console",
|
|
13
|
+
"Intended Audience :: System Administrators",
|
|
14
|
+
"Intended Audience :: Telecommunications Industry",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Topic :: System :: Networking",
|
|
21
|
+
"Topic :: System :: Networking :: Monitoring",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
dependencies = ["diffsync>=2.2,<3", "pydantic>=2.7", "pyyaml>=6", "typer>=0.12", "tomlkit>=0.15"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/antoinekh/snapdelta"
|
|
28
|
+
Documentation = "https://github.com/antoinekh/snapdelta/tree/main/docs"
|
|
29
|
+
Issues = "https://github.com/antoinekh/snapdelta/issues"
|
|
30
|
+
Changelog = "https://github.com/antoinekh/snapdelta/blob/main/CHANGELOG.md"
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
snapdelta = "snapdelta.cli:app"
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["hatchling"]
|
|
37
|
+
build-backend = "hatchling.build"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/snapdelta"]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""What a user or a support request needs to know: the versions, the plugins and the project links."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import platform
|
|
6
|
+
from collections.abc import Iterable
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
9
|
+
|
|
10
|
+
from .source import broken_sources, source_classes
|
|
11
|
+
|
|
12
|
+
PROJECT_URL = "https://github.com/antoinekh/snapdelta"
|
|
13
|
+
DOCS_URL = f"{PROJECT_URL}/tree/main/docs"
|
|
14
|
+
CHANGELOG_URL = f"{PROJECT_URL}/blob/main/CHANGELOG.md"
|
|
15
|
+
ISSUES_URL = f"{PROJECT_URL}/issues"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class Component:
|
|
20
|
+
name: str
|
|
21
|
+
version: str
|
|
22
|
+
sources: list[str] = field(default_factory=list)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def package_version(distribution: str) -> str:
|
|
26
|
+
try:
|
|
27
|
+
return version(distribution)
|
|
28
|
+
except PackageNotFoundError:
|
|
29
|
+
return "unknown"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def components(extra: Iterable[str] = ()) -> list[Component]:
|
|
33
|
+
"""snapdelta, the other given packages (the web UI), diffsync and Python."""
|
|
34
|
+
names = ["snapdelta", *extra, "diffsync"]
|
|
35
|
+
return [*(Component(name, package_version(name)) for name in names), Component("Python", platform.python_version())]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def plugins() -> list[Component]:
|
|
39
|
+
"""The installed plugins with their sources; a source with no distribution is listed under its own name."""
|
|
40
|
+
by_plugin: dict[str, list[str]] = {}
|
|
41
|
+
for name, cls in sorted(source_classes().items()):
|
|
42
|
+
by_plugin.setdefault(cls.distribution or name, []).append(name)
|
|
43
|
+
for name in sorted(broken_sources()):
|
|
44
|
+
by_plugin.setdefault(f"{name} (cannot load)", []).append(name)
|
|
45
|
+
return [Component(plugin, package_version(plugin), names) for plugin, names in sorted(by_plugin.items())]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def version_line() -> str:
|
|
49
|
+
core, diffsync = package_version("snapdelta"), package_version("diffsync")
|
|
50
|
+
return f"snapdelta {core} (diffsync {diffsync}, Python {platform.python_version()})"
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""What snapdelta did: one run per command (snapshots, a diff), with its result and the log messages of its loads.
|
|
2
|
+
|
|
3
|
+
A source plugin logs with the standard `logging` module. While a load runs, `LogCollector` adds each message to
|
|
4
|
+
the log of that load, even from the threads of `run_parallel()`, which copy the context of their caller.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import getpass
|
|
10
|
+
import logging
|
|
11
|
+
import secrets
|
|
12
|
+
from collections.abc import Iterator
|
|
13
|
+
from contextlib import contextmanager
|
|
14
|
+
from contextvars import ContextVar
|
|
15
|
+
from datetime import UTC, datetime
|
|
16
|
+
from enum import StrEnum
|
|
17
|
+
from typing import TYPE_CHECKING
|
|
18
|
+
|
|
19
|
+
from pydantic import BaseModel, Field
|
|
20
|
+
|
|
21
|
+
from .errors import SnapdeltaError
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from .store import Store
|
|
25
|
+
|
|
26
|
+
_log = logging.getLogger(__name__)
|
|
27
|
+
# The log that receives the messages of the current context, and the target that they are about.
|
|
28
|
+
_lines: ContextVar[list[LogLine] | None] = ContextVar("snapdelta_log_lines", default=None)
|
|
29
|
+
_target: ContextVar[str | None] = ContextVar("snapdelta_log_target", default=None)
|
|
30
|
+
# Only a load collects: the compare of a run logs too (diffsync), and that says nothing about the targets.
|
|
31
|
+
_loading: ContextVar[bool] = ContextVar("snapdelta_loading", default=False)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class LogLine(BaseModel):
|
|
35
|
+
at: datetime
|
|
36
|
+
level: str
|
|
37
|
+
logger: str
|
|
38
|
+
target: str | None = None
|
|
39
|
+
message: str
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class RunStatus(StrEnum):
|
|
43
|
+
OK = "ok"
|
|
44
|
+
PARTIAL = "partial"
|
|
45
|
+
FAILED = "failed"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Run(BaseModel):
|
|
49
|
+
"""One command: what it took or compared, how it ended, and the log of its loads."""
|
|
50
|
+
|
|
51
|
+
id: str
|
|
52
|
+
kind: str = Field(description="snapshot or diff")
|
|
53
|
+
origin: str = Field(description="cli, web, api, mcp, or python for a direct call")
|
|
54
|
+
user: str | None = None
|
|
55
|
+
started_at: datetime
|
|
56
|
+
ended_at: datetime
|
|
57
|
+
status: RunStatus
|
|
58
|
+
targets: list[str] = []
|
|
59
|
+
saved: list[str] = Field(default=[], description="The references of the saved snapshots.")
|
|
60
|
+
output: str | None = Field(default=None, description="The name of the saved diff.")
|
|
61
|
+
errors: dict[str, str] = Field(default={}, description="The error of each failed target, or of the run under `*`.")
|
|
62
|
+
log: list[LogLine] = []
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def duration_s(self) -> float:
|
|
66
|
+
return (self.ended_at - self.started_at).total_seconds()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class LogCollector(logging.Handler):
|
|
70
|
+
"""Adds each message of a load to the log of the current context; any other message goes nowhere."""
|
|
71
|
+
|
|
72
|
+
def emit(self, record: logging.LogRecord) -> None:
|
|
73
|
+
lines = _lines.get()
|
|
74
|
+
if lines is None or not _loading.get():
|
|
75
|
+
return
|
|
76
|
+
try:
|
|
77
|
+
message = record.getMessage()
|
|
78
|
+
except (TypeError, ValueError):
|
|
79
|
+
message = str(record.msg)
|
|
80
|
+
lines.append(
|
|
81
|
+
LogLine(
|
|
82
|
+
at=datetime.fromtimestamp(record.created, UTC),
|
|
83
|
+
level=record.levelname.lower(),
|
|
84
|
+
logger=record.name,
|
|
85
|
+
target=_target.get(),
|
|
86
|
+
message=message,
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def configure_logging(level: str = "info") -> None:
|
|
92
|
+
"""Collect the messages at `level` and above, and keep the console at warning; once per process."""
|
|
93
|
+
root = logging.getLogger()
|
|
94
|
+
wanted = logging.getLevelNamesMapping()[level.upper()]
|
|
95
|
+
for handler in root.handlers:
|
|
96
|
+
# The console handler of logging.basicConfig() shows warnings only, as before the collector.
|
|
97
|
+
if type(handler) is logging.StreamHandler and handler.level == logging.NOTSET:
|
|
98
|
+
handler.setLevel(logging.WARNING)
|
|
99
|
+
if not any(isinstance(handler, LogCollector) for handler in root.handlers):
|
|
100
|
+
root.addHandler(LogCollector(wanted))
|
|
101
|
+
else:
|
|
102
|
+
for handler in root.handlers:
|
|
103
|
+
if isinstance(handler, LogCollector):
|
|
104
|
+
handler.setLevel(wanted)
|
|
105
|
+
root.setLevel(min(root.level or logging.WARNING, wanted))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@contextmanager
|
|
109
|
+
def collecting(target: str | None = None, loading: bool = True) -> Iterator[list[LogLine]]:
|
|
110
|
+
"""The log of the load in the block, about `target`; the lines also go to the log around it."""
|
|
111
|
+
outer = _lines.get()
|
|
112
|
+
lines: list[LogLine] = []
|
|
113
|
+
tokens = (_lines.set(lines), _target.set(target), _loading.set(loading))
|
|
114
|
+
try:
|
|
115
|
+
yield lines
|
|
116
|
+
finally:
|
|
117
|
+
_lines.reset(tokens[0])
|
|
118
|
+
_target.reset(tokens[1])
|
|
119
|
+
_loading.reset(tokens[2])
|
|
120
|
+
if outer is not None:
|
|
121
|
+
outer.extend(lines)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class RunRecord:
|
|
125
|
+
"""A run while it goes on; the caller fills `saved`, `output` and `errors`."""
|
|
126
|
+
|
|
127
|
+
def __init__(self, kind: str, origin: str, targets: list[str]) -> None:
|
|
128
|
+
self.kind = kind
|
|
129
|
+
self.origin = origin
|
|
130
|
+
self.targets = targets
|
|
131
|
+
self.started_at = datetime.now(UTC)
|
|
132
|
+
self.saved: list[str] = []
|
|
133
|
+
self.output: str | None = None
|
|
134
|
+
self.errors: dict[str, str] = {}
|
|
135
|
+
self.log: list[LogLine] = []
|
|
136
|
+
|
|
137
|
+
def finished(self) -> Run:
|
|
138
|
+
done = len(self.saved) + (1 if self.output else 0)
|
|
139
|
+
status = RunStatus.OK if not self.errors else RunStatus.PARTIAL if done else RunStatus.FAILED
|
|
140
|
+
# Microseconds, so that the ids of two runs of the same second sort in their order.
|
|
141
|
+
stamp = self.started_at.strftime("%Y%m%dT%H%M%S%fZ")
|
|
142
|
+
return Run(
|
|
143
|
+
id=f"{stamp}-{self.kind}-{secrets.token_hex(2)}",
|
|
144
|
+
kind=self.kind,
|
|
145
|
+
origin=self.origin,
|
|
146
|
+
user=_user() if self.origin == "cli" else None,
|
|
147
|
+
started_at=self.started_at,
|
|
148
|
+
ended_at=datetime.now(UTC),
|
|
149
|
+
status=status,
|
|
150
|
+
targets=self.targets,
|
|
151
|
+
saved=self.saved,
|
|
152
|
+
output=self.output,
|
|
153
|
+
errors=self.errors,
|
|
154
|
+
# The loads add their lines when they end: the time gives back the order of the events.
|
|
155
|
+
log=sorted(self.log, key=lambda line: line.at),
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@contextmanager
|
|
160
|
+
def recorded(store: Store, kind: str, origin: str, targets: list[str]) -> Iterator[RunRecord]:
|
|
161
|
+
"""Record the block as a run of the store; an error fails the run and goes on to the caller."""
|
|
162
|
+
record = RunRecord(kind, origin, targets)
|
|
163
|
+
try:
|
|
164
|
+
with collecting(loading=False) as lines:
|
|
165
|
+
record.log = lines
|
|
166
|
+
yield record
|
|
167
|
+
except Exception as error:
|
|
168
|
+
record.errors["*"] = str(error) if isinstance(error, SnapdeltaError) else f"{type(error).__name__}: {error}"
|
|
169
|
+
raise
|
|
170
|
+
finally:
|
|
171
|
+
try:
|
|
172
|
+
store.save_run(record.finished())
|
|
173
|
+
except (OSError, SnapdeltaError) as error:
|
|
174
|
+
# The command itself went well: a run that cannot be saved must not turn it into an error.
|
|
175
|
+
_log.warning("the run was not saved: %s", error)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _user() -> str | None:
|
|
179
|
+
try:
|
|
180
|
+
return getpass.getuser()
|
|
181
|
+
except (KeyError, OSError):
|
|
182
|
+
return None
|