Skip to content

Commit

Permalink
fixes issue with setting source tags on VLANs properly
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-Ricardo committed Feb 10, 2024
1 parent b381b0f commit 975fa8d
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions module/netbox/object_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,7 @@ def update(self, data=None, read_from_netbox=False, source=None):

return

if source is not None:
self.source = source
self.set_source(source)

display_name = self.get_display_name(data)

Expand Down Expand Up @@ -558,10 +557,10 @@ def update(self, data=None, read_from_netbox=False, source=None):

if not isinstance(value, NetBoxObject):
# try to find object.
value = self.inventory.add_update_object(defined_value_type, data=value)
# add source if item was created via this source
if value.source is None:
value.source = source
value = self.inventory.add_update_object(defined_value_type, data=value, source=source)

# add source if currently undefined (read from NetBox)
value.set_source(source)

# add to parsed data dict
parsed_data[key] = value
Expand Down Expand Up @@ -654,6 +653,14 @@ def update(self, data=None, read_from_netbox=False, source=None):
if data_updated is True and self.is_new is False:
log.debug("Updated %s object: %s" % (self.name, self.get_display_name()))

def set_source(self, source=None):
"""
updates the source attribute, Only update if undefined
"""

if source is not None and self.source is None:
self.source = source

def get_display_name(self, data=None, including_second_key=False):
"""
return a name as string of this object based on primary/secondary key
Expand Down Expand Up @@ -990,6 +997,9 @@ def compile_vlans(self, vlans):
log.error(f"Unable to parse provided VLAN data: {vlan}")
continue

# set source for this vlan if undefined
new_vlan_object.set_source(self.source)

# VLAN already in list, must have been submitted twice
if new_vlan_object in new_vlan_list:
continue
Expand Down

0 comments on commit 975fa8d

Please sign in to comment.