mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Allow mixture of component replication and adoption
This commit is contained in:
parent
977ccb01f2
commit
8040804c75
@ -1068,10 +1068,12 @@ class Module(NetBoxModel, ConfigContextModel):
|
||||
adopt_components = getattr(self, '_adopt_components', False)
|
||||
disable_replication = getattr(self, '_disable_replication', False)
|
||||
|
||||
# If this is a new Module and component replication has not been disabled, instantiate all its
|
||||
# related components per the ModuleType definition
|
||||
if is_new and not disable_replication:
|
||||
# Iterate all component templates
|
||||
# We skip adding components if the module is being edited or
|
||||
# both replication and component adoption is disabled
|
||||
if not is_new or (disable_replication and not adopt_components):
|
||||
return
|
||||
|
||||
# Iterate all component types
|
||||
for templates, component_attribute, component_model in [
|
||||
("consoleporttemplates", "consoleports", ConsolePort),
|
||||
("consoleserverporttemplates", "consoleserverports", ConsoleServerPort),
|
||||
@ -1098,7 +1100,8 @@ class Module(NetBoxModel, ConfigContextModel):
|
||||
update_instances.append(existing_item)
|
||||
continue
|
||||
|
||||
# If we are not adopting components or the component doesn't already exist
|
||||
# Only create new components if replication is enabled
|
||||
if not disable_replication:
|
||||
create_instances.append(template_instance)
|
||||
|
||||
component_model.objects.bulk_create(create_instances)
|
||||
|
Loading…
Reference in New Issue
Block a user