Skip to content

Commit 441ee7c

Browse files
committed
adds sample config and fixes some linting issues
1 parent b46a844 commit 441ee7c

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

module/netbox/object_classes.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@ def to_dict(self):
377377
if isinstance(data_value, list):
378378
new_data_value = list()
379379
for possible_option in data_value:
380-
if type(possible_option) == type:
380+
if type(possible_option) is type:
381381
new_data_value.append(str(possible_option))
382382
else:
383383
new_data_value.append(possible_option)
384384

385385
data_value = new_data_value
386386

387387
# if value is class name then print class name
388-
if type(data_value) == type:
388+
if type(data_value) is type:
389389
data_value = str(data_value)
390390

391391
data_model[data_key] = data_value
@@ -458,7 +458,7 @@ def format_slug(text=None, max_len=50):
458458
# Enforce max length
459459
return text[0:max_len]
460460

461-
def get_uniq_slug(self, text=None, max_len=50)-> str:
461+
def get_uniq_slug(self, text=None, max_len=50) -> str:
462462
"""
463463
return an uniq slug. If the default slug is already used try to
464464
append a number until a slug is found which has not been used.
@@ -480,7 +480,7 @@ def get_uniq_slug(self, text=None, max_len=50)-> str:
480480
if self.inventory.slug_used(self.__class__, slug) is False:
481481
return slug
482482

483-
for x in range(1,20):
483+
for x in range(1, 20):
484484
new_slug = f"{slug}-{x}"
485485
if self.inventory.slug_used(self.__class__, new_slug) is False and len(new_slug) <= max_len:
486486
log.info(f"Slug '{slug}' for {self.name} '{text}' has been used. "
@@ -1272,6 +1272,7 @@ def get_site_name(self, data=None):
12721272
if isinstance(this_site, dict):
12731273
return this_site.get("name")
12741274

1275+
12751276
class NBObjectList(list):
12761277
"""
12771278
Base class of listed NetBox objects. Extends list(). Currently used for tags and untagged VLANs
@@ -1697,7 +1698,6 @@ def update(self, data=None, read_from_netbox=False, source=None):
16971698

16981699
super().update(data=data, read_from_netbox=read_from_netbox, source=source)
16991700

1700-
17011701
def resolve_relations(self):
17021702

17031703
self.resolve_scoped_relations("scope_id", "scope_type")
@@ -2141,18 +2141,6 @@ def update(self, data=None, read_from_netbox=False, source=None):
21412141
object_type = data.get("assigned_object_type")
21422142
assigned_object = data.get("assigned_object_id")
21432143

2144-
# Skip IP assignments when the IP is assigned to FHRP groups when config option
2145-
# skip_fhrp_group_ips is set to True, or if the IP is manually assigned to an FHRP group (no source)
2146-
if source is not None:
2147-
if source.source_type == "vmware":
2148-
config_relation = source.get_object_relation(assigned_object, "skip_fhrp_group_ips")
2149-
if config_relation == True and object_type == "ipam.fhrpgroup":
2150-
log.debug(f"IP address with id '{assigned_object}' assigned to FHRP group. Skipping.")
2151-
return
2152-
elif object_type == "ipam.fhrpgroup":
2153-
log.debug(f"IP address with id '{assigned_object}' assigned to FHRP group. It was manually created. Skipping.")
2154-
return
2155-
21562144
# used to track changes in object primary IP assignments
21572145
previous_ip_device_vm = None
21582146
is_primary_ipv4_of_previous_device = False
@@ -2241,6 +2229,7 @@ def remove_interface_association(self):
22412229
if o_type is not None:
22422230
self.unset_attribute("assigned_object_type")
22432231

2232+
22442233
class NBMACAddress(NetBoxObject):
22452234
name = "MAC address"
22462235
api_path = "dcim/mac-addresses"

settings-example.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ password = super-secret
298298
; VMs from fail-over site to NetBox.
299299
;skip_srm_placeholder_vms = False
300300

301+
; If an IP address is assigned to a FHRP group (like HSRP, VRRP, GLBP) then this IP
302+
; address will be skipped and not synced to NetBox to prevent incorrect syncing.
303+
;skip_fhrp_group_ips = False
304+
301305
; strip domain part from host name before syncing device to NetBox
302306
;strip_host_domain_name = False
303307

@@ -454,6 +458,11 @@ inventory_file_path = /full/path/to/inventory/files
454458
; check_redfish if False only data which is not preset in NetBox will be added
455459
;overwrite_interface_attributes = False
456460

461+
; define if an IP address assigned to a FHRP group (like HSRP, VRRP, GLBP) will be
462+
; skipped. If True this IP address will be skipped and not synced to NetBox to prevent
463+
; incorrect syncing.
464+
;skip_fhrp_group_ips = False
465+
457466
; define in which order the IP address tenant will be assigned if tenant is undefined.
458467
; possible values:
459468
; * device : host or VM tenant will be assigned to the IP address

0 commit comments

Comments
 (0)