mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08: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)
|
adopt_components = getattr(self, '_adopt_components', False)
|
||||||
disable_replication = getattr(self, '_disable_replication', False)
|
disable_replication = getattr(self, '_disable_replication', False)
|
||||||
|
|
||||||
# If this is a new Module and component replication has not been disabled, instantiate all its
|
# We skip adding components if the module is being edited or
|
||||||
# related components per the ModuleType definition
|
# both replication and component adoption is disabled
|
||||||
if is_new and not disable_replication:
|
if not is_new or (disable_replication and not adopt_components):
|
||||||
# Iterate all component templates
|
return
|
||||||
|
|
||||||
|
# Iterate all component types
|
||||||
for templates, component_attribute, component_model in [
|
for templates, component_attribute, component_model in [
|
||||||
("consoleporttemplates", "consoleports", ConsolePort),
|
("consoleporttemplates", "consoleports", ConsolePort),
|
||||||
("consoleserverporttemplates", "consoleserverports", ConsoleServerPort),
|
("consoleserverporttemplates", "consoleserverports", ConsoleServerPort),
|
||||||
@ -1098,7 +1100,8 @@ class Module(NetBoxModel, ConfigContextModel):
|
|||||||
update_instances.append(existing_item)
|
update_instances.append(existing_item)
|
||||||
continue
|
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)
|
create_instances.append(template_instance)
|
||||||
|
|
||||||
component_model.objects.bulk_create(create_instances)
|
component_model.objects.bulk_create(create_instances)
|
||||||
|
Loading…
Reference in New Issue
Block a user