15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb', line 15
def call
if context.interfaces.total.zero?
context.ip_addresses.each(&:delete)
return
end
ip_addresses_netbox_params = netbox_params.fetch(:ip_addresses, [])
context.interfaces.each do |netbox_interface|
host_interface_ips = ip_addresses_netbox_params.select do |ip|
ip.dig(:interface, :name) == netbox_interface.name
end
.map { |ip| ip.fetch(:address) }
context.ip_addresses
.select { |ip| ip['assigned_object_type'] == 'virtualization.vminterface' && ip['assigned_object_id'] == netbox_interface.id }
.reject { |ip| host_interface_ips.include?(ip['address']) }
.each(&:delete)
end
end
|