You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-24Lines changed: 24 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
# dsync
1
+
# DiffSync
2
2
3
-
DSync is a utility library that can be used to compare and synchronize different datasets.
3
+
DiffSync is a utility library that can be used to compare and synchronize different datasets.
4
4
5
5
For example, it can be used to compare a list of devices from 2 inventories system and, if required, synchronize them in either direction.
6
6
7
7
```python
8
-
A =DSyncSystemA()
9
-
B =DSyncSystemB()
8
+
A =DiffSyncSystemA()
9
+
B =DiffSyncSystemB()
10
10
11
11
A.load()
12
12
B.load()
@@ -24,24 +24,24 @@ A.sync_to(B)
24
24
25
25
# Getting Started
26
26
27
-
To be able to properly compare different datasets, DSync rely on a shared datamodel that both systems must use.
27
+
To be able to properly compare different datasets, DiffSync relies on a shared datamodel that both systems must use.
28
28
29
-
## Define your model with DSyncModel
29
+
## Define your model with DiffSyncModel
30
30
31
-
DSyncModel is based on [Pydantic](https://pydantic-docs.helpmanual.io/) and is using Python Typing to define the format of each attribute.
32
-
Each DSyncModel class supports the following class-level attributes:
31
+
DiffSyncModel is based on [Pydantic](https://pydantic-docs.helpmanual.io/) and is using Python Typing to define the format of each attribute.
32
+
Each DiffSyncModel class supports the following class-level attributes:
33
33
-`_modelname` (str) Define the type of the model, it's used to store the data internally (Mandatory)
34
34
-`_identifiers` List(str) List of instance field names used as primary keys for this object (Mandatory)
35
35
-`_shortname` List(str) List of instance field names to use for a shorter name (Optional)
36
36
-`_attributes` List(str) List of additional instance field names for this object (Optional)
37
37
-`_children` Dict: Dict of {`<modelname>`: `field_name`} to indicate how child objects should be stored. (Optional)
38
38
39
-
> DSyncModel must uniquely identified by their unique id, composed of all fields defined in `_identifiers`. DSyncModel do not support incremental IDs as primary key.
39
+
> DiffSyncModel instances must be uniquely identified by their unique id, composed of all fields defined in `_identifiers`. DiffSyncModel does not support incremental IDs as primary key.
40
40
41
41
```python
42
-
fromdsyncimportDSyncModel
42
+
fromdiffsyncimportDiffSyncModel
43
43
44
-
classSite(DSyncModel):
44
+
classSite(DiffSyncModel):
45
45
_modelname ="site"
46
46
_identifiers = ("name",)
47
47
_shortname = ()
@@ -54,16 +54,16 @@ class Site(DSyncModel):
54
54
```
55
55
56
56
### Relationship between models.
57
-
Currently the relationship between models are very loose, by design. Instead of storing an object, it's recommended to store the uid of an object and retrieve it from the store as needed.
57
+
Currently the relationships between models are very loose by design. Instead of storing an object, it's recommended to store the uid of an object and retrieve it from the store as needed.
58
58
59
-
## DSync
59
+
## DiffSync
60
60
61
-
A DSync object must reference each model available at the top of the object by its modelname and must have a `top_level` attribute defined to indicate how the diff and the synchronization should be done. In the example below, `"site"` is the only top level objects so the synchronization engine will check all sites and all children of each site (devices)
61
+
A DiffSync object must reference each model available at the top of the object by its modelname and must have a `top_level` attribute defined to indicate how the diff and the synchronization should be done. In the example below, `"site"` is the only top level objects so the synchronization engine will check all sites and all children of each site (devices)
62
62
63
63
```python
64
-
fromdsyncimportDSync
64
+
fromdiffsyncimportDiffSync
65
65
66
-
classBackendA(DSync):
66
+
classBackendA(DiffSync):
67
67
68
68
site = Site
69
69
device = Device
@@ -73,12 +73,12 @@ class BackendA(DSync):
73
73
74
74
It's up to the user to populate the internal cache with the appropriate data. In the example below we are using the `load()` method to populate the cache but it's not mandatory, it could be done differently
75
75
76
-
## Store data in a DSync object
76
+
## Store data in a DiffSync object
77
77
78
-
To add a site to the local cache/store, you need to pass a valid DSyncModel object to the `add()` function.
78
+
To add a site to the local cache/store, you need to pass a valid DiffSyncModel object to the `add()` function.
79
79
```python
80
80
81
-
classBackendA(DSync):
81
+
classBackendA(DiffSync):
82
82
[...]
83
83
84
84
defload(self):
@@ -94,17 +94,17 @@ class BackendA(DSync):
94
94
95
95
## Update Remote system on Sync
96
96
97
-
To update a remote system, you need to extend your DSyncModel class(es) to define your own `create`, `update` and/or `delete` methods for each model.
98
-
A DSyncModel instance stores a reference to its parent DSync class in case you need to use it to look up other model instances from the DSync's cache.
97
+
To update a remote system, you need to extend your DiffSyncModel class(es) to define your own `create`, `update` and/or `delete` methods for each model.
98
+
A DiffSyncModel instance stores a reference to its parent DiffSync class in case you need to use it to look up other model instances from the DiffSync's cache.
99
99
100
100
```python
101
-
classDevice(DSyncModel):
101
+
classDevice(DiffSyncModel):
102
102
[...]
103
103
104
104
@classmethod
105
-
defcreate(cls, dsync, ids, attrs):
105
+
defcreate(cls, diffsync, ids, attrs):
106
106
## TODO add your own logic here to create the device on the remote system
0 commit comments