Skip to content

Commit 5b15103

Browse files
authored
Merge branch 'bb-Ricardo:development' into development
2 parents 35c877d + 2e8d0f0 commit 5b15103

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,8 @@ type = check_redfish
317317
inventory_file_path = /opt/redfish_inventory
318318
```
319319

320-
**Developers**:
321-
If you are interested in adding more source types please open an issue/discussion
322-
because the documentation of implementing a new source hasn't been finished yet. 🤷
320+
If different sources overwrite the same attribute for ex. a host then the order of the sources should be considered.
321+
The last source in order from top to bottom will prevail.
323322

324323
## Pruning
325324
Prune objects in NetBox if they are no longer present in any source.

module/netbox/object_classes.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def __init__(self, data=None, read_from_netbox=False, inventory=None, source=Non
279279
self.unset_items = list()
280280
self.source = source
281281
self.deleted = False
282+
self._original_data = dict()
282283

283284
# add empty lists for list items
284285
for key, data_type in self.data_model.items():
@@ -612,15 +613,29 @@ def update(self, data=None, read_from_netbox=False, source=None):
612613
if key == self.primary_key and current_value_str.lower() == new_value_str.lower():
613614
continue
614615

615-
self.data[key] = new_value
616-
self.updated_items.append(key)
617-
data_updated = True
618-
619616
if self.is_new is False:
617+
618+
if self._original_data.get(key) == new_value_str and key in self.updated_items:
619+
self.data[key] = new_value
620+
self.updated_items.remove(key)
621+
log.debug(f"{self.name.capitalize()} '{display_name}' attribute '{key}' was set back to "
622+
f"original NetBox value '{current_value_str}'")
623+
continue
624+
625+
# save original NetBox value for future use to detect updates which sets it back to the same value
626+
# which is already saved in NetBox
627+
elif self._original_data.get(key) is None:
628+
self._original_data[key] = current_value_str
629+
print(self._original_data[key])
630+
620631
new_value_str = new_value_str.replace("\n", " ")
621632
log.info(f"{self.name.capitalize()} '{display_name}' attribute '{key}' changed from "
622633
f"'{current_value_str}' to '{new_value_str}'")
623634

635+
self.data[key] = new_value
636+
self.updated_items.append(key)
637+
data_updated = True
638+
624639
self.resolve_relations()
625640

626641
if data_updated is True and self.is_new is False:

0 commit comments

Comments
 (0)