Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Netbox to own device/site existence #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DeleteDevice
include ::Interactor

around do |interactor|
interactor.call unless context.host.compute?
interactor.call if !context.host.compute? && Settings[:netbox_delete_devices]
end

def call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Create
include ForemanNetbox::Concerns::AssignTags

around do |interactor|
interactor.call unless context.device
interactor.call if !context.device && Setting[:netbox_create_devices]
end

def call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Organizer
end

after do
context.raw_data[:device] = context.device.raw_data!
context.raw_data[:device] = context.device.raw_data! if context.device
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the device may be nil if it is not found in the Netbox and devices creation is disabled, right?

Suggested change
context.raw_data[:device] = context.device.raw_data! if context.device
context.raw_data[:device] = context.device&.raw_data!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it this way to not mess with the cached parameters, since that service uses key existence to decide what data to generate.

end

organize SyncDevice::Validate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module SyncInterfaces
class Organizer
include ::Interactor::Organizer

around do |interactor|
interactor.call if context.device
end

after do
context.raw_data[:interfaces] = context.interfaces.reload.raw_data!
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Organizer
include ::Interactor::Organizer

around do |interactor|
interactor.call if context.host.location
interactor.call if context.host.location && !Setting[:netbox_skip_site_update]
ananace marked this conversation as resolved.
Show resolved Hide resolved
end

after do
Expand Down
10 changes: 10 additions & 0 deletions lib/foreman_netbox/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ class Engine < ::Rails::Engine
default: false,
full_name: N_('Skip Site Update'),
description: N_('Skip updating Site attribute for Devices')
setting 'netbox_create_devices',
type: :boolean,
default: true,
full_name: N_('Create Devices'),
description: N_('Create Netbox Device objects for Hosts if they are missing')
setting 'netbox_delete_devices',
type: :boolean,
default: true,
full_name: N_('Delete Devices'),
description: N_('Delete Device objects on Host deletion')
end
end

Expand Down