-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from kpetremann/dcim_change_protection
feat: prevent device/address change when linked to CMDB
- Loading branch information
Showing
8 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
MODELS_LINKED_TO_DEVICE = {} | ||
MODELS_LINKED_TO_IP_ADDRESS = {} | ||
|
||
|
||
def from_device_name_change(*fields): | ||
"""Protects from Device name changes in NetBox DCIM. | ||
This is useful only to prevent Device name changes when CMDB is linked to it. | ||
""" | ||
|
||
def decorator(cls): | ||
if cls not in MODELS_LINKED_TO_DEVICE: | ||
MODELS_LINKED_TO_DEVICE[cls] = set() | ||
|
||
if not fields: | ||
return cls | ||
|
||
for field in fields: | ||
MODELS_LINKED_TO_DEVICE[cls].add(field) | ||
|
||
return cls | ||
|
||
return decorator | ||
|
||
|
||
def from_ip_address_change(*fields): | ||
"""Protects from IP Address "address" changes in NetBox IPAM. | ||
This is useful only to prevent IP Address "address" changes when CMDB is linked to it. | ||
""" | ||
|
||
def decorator(cls): | ||
if cls not in MODELS_LINKED_TO_IP_ADDRESS: | ||
MODELS_LINKED_TO_IP_ADDRESS[cls] = set() | ||
|
||
if not fields: | ||
return cls | ||
|
||
for field in fields: | ||
MODELS_LINKED_TO_IP_ADDRESS[cls].add(field) | ||
|
||
return cls | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters