foreman_netbox 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/contracts/foreman_netbox/device_contract.rb +3 -3
  4. data/app/contracts/foreman_netbox/params/interface_params.rb +6 -8
  5. data/app/contracts/foreman_netbox/params/ip_address_params.rb +5 -7
  6. data/app/contracts/foreman_netbox/params/tenant_params.rb +4 -6
  7. data/app/contracts/foreman_netbox/virtual_machine_contract.rb +3 -3
  8. data/app/interactors/foreman_netbox/delete_host/organizer.rb +1 -1
  9. data/app/interactors/foreman_netbox/sync_host/organizer.rb +1 -1
  10. data/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +0 -2
  11. data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +10 -10
  12. data/app/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url.rb +1 -1
  13. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb +1 -1
  14. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb +3 -3
  15. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +2 -3
  16. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb +1 -1
  17. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +1 -1
  18. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb +4 -4
  19. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb +3 -1
  20. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +1 -1
  21. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
  22. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb +3 -1
  23. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb +2 -2
  24. data/app/interactors/foreman_netbox/sync_host/sync_device/update.rb +2 -0
  25. data/app/interactors/foreman_netbox/sync_host/sync_tags/organizer.rb +2 -2
  26. data/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb +2 -2
  27. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +0 -2
  28. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +8 -8
  29. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url.rb +1 -1
  30. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb +3 -3
  31. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb +1 -1
  32. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +1 -1
  33. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb +4 -4
  34. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +3 -1
  35. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +1 -1
  36. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
  37. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb +3 -1
  38. data/app/lib/foreman_netbox/api.rb +2 -2
  39. data/app/models/orchestration/netbox.rb +3 -5
  40. data/app/services/foreman_netbox/cached_netbox_parameters.rb +11 -11
  41. data/app/services/foreman_netbox/netbox_parameters.rb +27 -27
  42. data/app/services/foreman_netbox/netbox_parameters_comparator.rb +12 -6
  43. data/db/migrate/20230303095650_fix_netbox_settings_category_to_dsl.rb +9 -0
  44. data/lib/foreman_netbox/engine.rb +32 -15
  45. data/lib/foreman_netbox/version.rb +1 -1
  46. data/lib/tasks/foreman_netbox_tasks.rake +0 -2
  47. data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +7 -7
  48. data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +7 -7
  49. data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +8 -8
  50. data/test/interactors/foreman_netbox/sync_host/organizer_test.rb +13 -13
  51. data/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +1 -1
  52. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb +1 -1
  53. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb +4 -4
  54. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb +1 -1
  55. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb +4 -4
  56. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb +1 -1
  57. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb +6 -6
  58. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +1 -1
  59. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb +3 -3
  60. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +1 -1
  61. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb +4 -4
  62. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
  63. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +5 -5
  64. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
  65. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +4 -4
  66. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +8 -8
  67. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb +1 -1
  68. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb +3 -3
  69. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +1 -1
  70. data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +38 -8
  71. data/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb +1 -1
  72. data/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb +3 -3
  73. data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +1 -1
  74. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb +2 -2
  75. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb +1 -1
  76. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb +2 -2
  77. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb +4 -4
  78. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +1 -1
  79. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb +3 -3
  80. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +1 -1
  81. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb +4 -4
  82. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
  83. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +5 -5
  84. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
  85. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +6 -6
  86. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +8 -8
  87. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +8 -8
  88. data/test/models/foreman_netbox/netbox_facet_test.rb +1 -1
  89. data/test/models/foreman_netbox/nics/base_test.rb +1 -1
  90. data/test/services/foreman_netbox/netbox_attributes_test.rb +16 -16
  91. data/test/services/foreman_netbox/netbox_parameters_comparator_test.rb +31 -31
  92. data/test/test_plugin_helper.rb +4 -9
  93. metadata +75 -117
  94. data/app/models/setting/netbox.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9df549aa83fb9c91e18bba3c2690cb6f9c14977ca2364198b12b20cc01140069
4
- data.tar.gz: 0adf0c06724a964efa56d7ca8b294ca73882c351a50c8063a1906f4ad3a429ac
3
+ metadata.gz: 0c6e291e619bba70de7b1c7c67832419452ef5342d2bd008961be87a2152ee86
4
+ data.tar.gz: 9bad853a3329b00878bfaea36939fa2ab02b0957540d2b2bae1b30781a7ddc0c
5
5
  SHA512:
6
- metadata.gz: dcd1893a719badc47fe8d083a46fa5ee403bc9f1c31a0963d05624c34f00dad74a8320cdaaf0917e6fc484c899f62fe56db277642e62ba240ef471d1214bd67c
7
- data.tar.gz: 1e3e688b369849e00c54440e4de52507bdefd30109d4688fc478b22a1ceaa751593859be6fbc8480ce60a6ee0050f0ab783dbfc721df428d93aa3bfd44feb7de
6
+ metadata.gz: 3612479271e7bec9c1499e482691cae0e4e2f7aed0b3d8de93085d98630d3faef83fd82ba4200c377b4ab497ebba63106c6ef4542c28a4c6cecd0c4d638161c9
7
+ data.tar.gz: ca1bfcace00f154324c72738a75059f66103ad200548c5314e5303ce6be656d1e21a2627f95f4c648ecf26c8e821cd6a28ebc92d78c381c49b78dce0acc267b2
data/README.md CHANGED
@@ -10,6 +10,7 @@ This is a plugin for Foreman that introduces integration with [NetBox](https://n
10
10
  | -------------- | -------------- |
11
11
  | 2.8 | 1.0 |
12
12
  | 2.11 | 1.1 |
13
+ | 3.3 | 1.2 |
13
14
 
14
15
  ## Installation
15
16
 
@@ -4,9 +4,9 @@ module ForemanNetbox
4
4
  class DeviceContract < Dry::Validation::Contract
5
5
  # rubocop:disable Metrics/BlockLength
6
6
  params do
7
- optional(:tenant).hash(ForemanNetbox::Params::TenantParams.new)
8
- optional(:ip_addresses).array(ForemanNetbox::Params::IpAddressParams.new)
9
- optional(:interfaces).array(ForemanNetbox::Params::InterfaceParams.new)
7
+ optional(:tenant).hash(ForemanNetbox::Params::TenantParams)
8
+ optional(:ip_addresses).array(ForemanNetbox::Params::IpAddressParams)
9
+ optional(:interfaces).array(ForemanNetbox::Params::InterfaceParams)
10
10
 
11
11
  required(:device).filled(:hash) do
12
12
  required(:name).filled(:string)
@@ -2,15 +2,13 @@
2
2
 
3
3
  module ForemanNetbox
4
4
  module Params
5
- class InterfaceParams < Dry::Schema::Params
6
- define do
7
- required(:name).filled(:string)
8
- required(:type).filled(:hash) do
9
- required(:value).filled(:string)
10
- end
11
- optional(:mac_address).maybe(:string)
12
- optional(:tags).array(:string)
5
+ InterfaceParams = Dry::Schema.Params do
6
+ required(:name).filled(:string)
7
+ required(:type).filled(:hash) do
8
+ required(:value).filled(:string)
13
9
  end
10
+ optional(:mac_address).maybe(:string)
11
+ optional(:tags).array(:string)
14
12
  end
15
13
  end
16
14
  end
@@ -2,14 +2,12 @@
2
2
 
3
3
  module ForemanNetbox
4
4
  module Params
5
- class IpAddressParams < Dry::Schema::Params
6
- define do
7
- required(:address).filled(:string)
8
- required(:interface).filled(:hash) do
9
- required(:name).filled(:string)
10
- end
11
- optional(:tags).array(:string)
5
+ IpAddressParams = Dry::Schema.Params do
6
+ required(:address).filled(:string)
7
+ required(:interface).filled(:hash) do
8
+ required(:name).filled(:string)
12
9
  end
10
+ optional(:tags).array(:string)
13
11
  end
14
12
  end
15
13
  end
@@ -2,12 +2,10 @@
2
2
 
3
3
  module ForemanNetbox
4
4
  module Params
5
- class TenantParams < Dry::Schema::Params
6
- define do
7
- required(:name).filled(:string)
8
- required(:slug).filled(:string)
9
- optional(:tags).array(:string)
10
- end
5
+ TenantParams = Dry::Schema.Params do
6
+ required(:name).filled(:string)
7
+ required(:slug).filled(:string)
8
+ optional(:tags).array(:string)
11
9
  end
12
10
  end
13
11
  end
@@ -3,9 +3,9 @@
3
3
  module ForemanNetbox
4
4
  class VirtualMachineContract < Dry::Validation::Contract
5
5
  params do
6
- optional(:tenant).hash(ForemanNetbox::Params::TenantParams.new)
7
- optional(:ip_addresses).array(ForemanNetbox::Params::IpAddressParams.new)
8
- optional(:interfaces).array(ForemanNetbox::Params::InterfaceParams.new)
6
+ optional(:tenant).hash(ForemanNetbox::Params::TenantParams)
7
+ optional(:ip_addresses).array(ForemanNetbox::Params::IpAddressParams)
8
+ optional(:interfaces).array(ForemanNetbox::Params::InterfaceParams)
9
9
 
10
10
  required(:virtual_machine).filled(:hash) do
11
11
  required(:name).filled(:string)
@@ -6,7 +6,7 @@ module ForemanNetbox
6
6
  include ::Interactor::Organizer
7
7
 
8
8
  organize DeleteHost::DeleteVirtualMachine,
9
- DeleteHost::DeleteDevice
9
+ DeleteHost::DeleteDevice
10
10
  end
11
11
  end
12
12
  end
@@ -11,7 +11,7 @@ module ForemanNetbox
11
11
  end
12
12
 
13
13
  organize SyncHost::SyncVirtualMachine::Organizer,
14
- SyncHost::SyncDevice::Organizer
14
+ SyncHost::SyncDevice::Organizer
15
15
 
16
16
  def call
17
17
  super
@@ -7,9 +7,7 @@ module ForemanNetbox
7
7
  include ::Interactor
8
8
 
9
9
  def call
10
- # rubocop:disable Rails/DynamicFindBy
11
10
  context.device = find_by_serial || find_by_mac || find_by_name
12
- # rubocop:enable Rails/DynamicFindBy
13
11
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
14
12
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
15
13
  context.fail!(error: "#{self.class}: #{e}")
@@ -15,16 +15,16 @@ module ForemanNetbox
15
15
  end
16
16
 
17
17
  organize SyncDevice::Validate,
18
- SyncHost::SyncTags::Organizer,
19
- SyncHost::SyncTenant::Organizer,
20
- SyncDevice::SyncSite::Organizer,
21
- SyncDevice::SyncDeviceRole::Organizer,
22
- SyncDevice::SyncDeviceType::Organizer,
23
- SyncDevice::Find,
24
- SyncDevice::Create,
25
- SyncDevice::SyncInterfaces::Organizer,
26
- SyncDevice::Update,
27
- SyncDevice::SaveNetboxUrl
18
+ SyncHost::SyncTags::Organizer,
19
+ SyncHost::SyncTenant::Organizer,
20
+ SyncDevice::SyncSite::Organizer,
21
+ SyncDevice::SyncDeviceRole::Organizer,
22
+ SyncDevice::SyncDeviceType::Organizer,
23
+ SyncDevice::Find,
24
+ SyncDevice::Create,
25
+ SyncDevice::SyncInterfaces::Organizer,
26
+ SyncDevice::Update,
27
+ SyncDevice::SaveNetboxUrl
28
28
  end
29
29
  end
30
30
  end
@@ -21,7 +21,7 @@ module ForemanNetbox
21
21
  delegate :url, to: :netbox_facet, prefix: true, allow_nil: true
22
22
 
23
23
  def netbox_device_url
24
- "#{Setting::Netbox[:netbox_url]}/dcim/devices/#{device&.id}" if device&.id
24
+ "#{Setting[:netbox_url]}/dcim/devices/#{device&.id}" if device&.id
25
25
  end
26
26
  end
27
27
  end
@@ -12,7 +12,7 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  organize SyncDeviceRole::Find,
15
- SyncDeviceRole::Create
15
+ SyncDeviceRole::Create
16
16
  end
17
17
  end
18
18
  end
@@ -12,9 +12,9 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  organize SyncDeviceType::SyncManufacturer::Organizer,
15
- SyncDeviceType::Find,
16
- SyncDeviceType::Update,
17
- SyncDeviceType::Create
15
+ SyncDeviceType::Find,
16
+ SyncDeviceType::Update,
17
+ SyncDeviceType::Create
18
18
  end
19
19
  end
20
20
  end
@@ -9,10 +9,9 @@ module ForemanNetbox
9
9
  include ::Interactor
10
10
 
11
11
  def call
12
- # rubocop:disable Rails/DynamicFindBy
13
12
  context.manufacturer = find_by_slug || find_by_name
14
- # rubocop:enable Rails/DynamicFindBy
15
- rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
13
+ rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError,
14
+ NetboxClientRuby::RemoteError => e
16
15
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
17
16
  context.fail!(error: "#{self.class}: #{e}")
18
17
  end
@@ -13,7 +13,7 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  organize SyncManufacturer::Find,
16
- SyncManufacturer::Create
16
+ SyncManufacturer::Create
17
17
  end
18
18
  end
19
19
  end
@@ -20,7 +20,7 @@ module ForemanNetbox
20
20
 
21
21
  def params
22
22
  {
23
- device_id: device.id
23
+ device_id: device.id,
24
24
  }
25
25
  end
26
26
  end
@@ -12,10 +12,10 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  organize SyncInterfaces::Find,
15
- SyncInterfaces::Delete,
16
- SyncInterfaces::Create,
17
- SyncInterfaces::SyncIpAddresses::Organizer,
18
- SyncInterfaces::Update
15
+ SyncInterfaces::Delete,
16
+ SyncInterfaces::Create,
17
+ SyncInterfaces::SyncIpAddresses::Organizer,
18
+ SyncInterfaces::Update
19
19
  end
20
20
  end
21
21
  end
@@ -21,7 +21,9 @@ module ForemanNetbox
21
21
  ip_addresses_netbox_params = netbox_params.fetch(:ip_addresses, [])
22
22
 
23
23
  context.interfaces.each do |netbox_interface|
24
- host_interface_ips = ip_addresses_netbox_params.select { |i| i.dig(:interface, :name) == netbox_interface.name }
24
+ host_interface_ips = ip_addresses_netbox_params.select do |i|
25
+ i.dig(:interface, :name) == netbox_interface.name
26
+ end
25
27
  .map { |i| i.fetch(:address) }
26
28
 
27
29
  context.ip_addresses
@@ -21,7 +21,7 @@ module ForemanNetbox
21
21
 
22
22
  def params
23
23
  {
24
- device_id: device.id
24
+ device_id: device.id,
25
25
  }
26
26
  end
27
27
  end
@@ -13,9 +13,9 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  organize SyncIpAddresses::Find,
16
- SyncIpAddresses::Delete,
17
- SyncIpAddresses::Update,
18
- SyncIpAddresses::Create
16
+ SyncIpAddresses::Delete,
17
+ SyncIpAddresses::Update,
18
+ SyncIpAddresses::Create
19
19
  end
20
20
  end
21
21
  end
@@ -22,7 +22,9 @@ module ForemanNetbox
22
22
 
23
23
  return unless new_params
24
24
 
25
- netbox_interface.mac_address = new_params[:mac_address] if netbox_interface.mac_address != new_params[:mac_address]
25
+ if netbox_interface.mac_address != new_params[:mac_address]
26
+ netbox_interface.mac_address = new_params[:mac_address]
27
+ end
26
28
  assign_tags_to(netbox_interface)
27
29
 
28
30
  netbox_interface.save
@@ -16,8 +16,8 @@ module ForemanNetbox
16
16
  end
17
17
 
18
18
  organize SyncSite::Find,
19
- SyncSite::Update,
20
- SyncSite::Create
19
+ SyncSite::Update,
20
+ SyncSite::Create
21
21
  end
22
22
  end
23
23
  end
@@ -62,6 +62,8 @@ module ForemanNetbox
62
62
  end
63
63
 
64
64
  def assign_site
65
+ return if device.site&.id && Setting[:netbox_skip_site_update]
66
+
65
67
  device.site = site&.id if device.site&.id != site&.id
66
68
  end
67
69
 
@@ -7,7 +7,7 @@ module ForemanNetbox
7
7
  include ::Interactor::Organizer
8
8
 
9
9
  DEFAULT_TAGS = [
10
- { name: 'foreman', slug: 'foreman' }
10
+ { name: 'foreman', slug: 'foreman' },
11
11
  ].freeze
12
12
 
13
13
  after do
@@ -15,7 +15,7 @@ module ForemanNetbox
15
15
  end
16
16
 
17
17
  organize SyncTags::Find,
18
- SyncTags::Create
18
+ SyncTags::Create
19
19
  end
20
20
  end
21
21
  end
@@ -11,8 +11,8 @@ module ForemanNetbox
11
11
  end
12
12
 
13
13
  organize SyncTenant::Find,
14
- SyncTenant::Update,
15
- SyncTenant::Create
14
+ SyncTenant::Update,
15
+ SyncTenant::Create
16
16
  end
17
17
  end
18
18
  end
@@ -7,9 +7,7 @@ module ForemanNetbox
7
7
  include ::Interactor
8
8
 
9
9
  def call
10
- # rubocop:disable Rails/DynamicFindBy
11
10
  context.virtual_machine = find_by_mac || find_by_name
12
- # rubocop:enable Rails/DynamicFindBy
13
11
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
14
12
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
15
13
  context.fail!(error: "#{self.class}: #{e}")
@@ -15,14 +15,14 @@ module ForemanNetbox
15
15
  end
16
16
 
17
17
  organize SyncVirtualMachine::Validate,
18
- SyncHost::SyncTags::Organizer,
19
- SyncHost::SyncTenant::Organizer,
20
- SyncVirtualMachine::SyncCluster::Organizer,
21
- SyncVirtualMachine::Find,
22
- SyncVirtualMachine::Create,
23
- SyncVirtualMachine::SyncInterfaces::Organizer,
24
- SyncVirtualMachine::Update,
25
- SyncVirtualMachine::SaveNetboxUrl
18
+ SyncHost::SyncTags::Organizer,
19
+ SyncHost::SyncTenant::Organizer,
20
+ SyncVirtualMachine::SyncCluster::Organizer,
21
+ SyncVirtualMachine::Find,
22
+ SyncVirtualMachine::Create,
23
+ SyncVirtualMachine::SyncInterfaces::Organizer,
24
+ SyncVirtualMachine::Update,
25
+ SyncVirtualMachine::SaveNetboxUrl
26
26
  end
27
27
  end
28
28
  end
@@ -23,7 +23,7 @@ module ForemanNetbox
23
23
  def netbox_virtual_machine_url
24
24
  return unless context.virtual_machine&.id
25
25
 
26
- "#{Setting::Netbox[:netbox_url]}/virtualization/virtual-machines/#{context.virtual_machine&.id}"
26
+ "#{Setting[:netbox_url]}/virtualization/virtual-machines/#{context.virtual_machine&.id}"
27
27
  end
28
28
  end
29
29
  end
@@ -12,9 +12,9 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  organize SyncCluster::SyncClusterType::Organizer,
15
- SyncCluster::Find,
16
- SyncCluster::Update,
17
- SyncCluster::Create
15
+ SyncCluster::Find,
16
+ SyncCluster::Update,
17
+ SyncCluster::Create
18
18
  end
19
19
  end
20
20
  end
@@ -13,7 +13,7 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  organize SyncClusterType::Find,
16
- SyncClusterType::Create
16
+ SyncClusterType::Create
17
17
  end
18
18
  end
19
19
  end
@@ -20,7 +20,7 @@ module ForemanNetbox
20
20
 
21
21
  def params
22
22
  {
23
- virtual_machine_id: virtual_machine.id
23
+ virtual_machine_id: virtual_machine.id,
24
24
  }
25
25
  end
26
26
  end
@@ -12,10 +12,10 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  organize SyncInterfaces::Find,
15
- SyncInterfaces::Delete,
16
- SyncInterfaces::Create,
17
- SyncInterfaces::SyncIpAddresses::Organizer,
18
- SyncInterfaces::Update
15
+ SyncInterfaces::Delete,
16
+ SyncInterfaces::Create,
17
+ SyncInterfaces::SyncIpAddresses::Organizer,
18
+ SyncInterfaces::Update
19
19
  end
20
20
  end
21
21
  end
@@ -21,7 +21,9 @@ module ForemanNetbox
21
21
  ip_addresses_netbox_params = netbox_params.fetch(:ip_addresses, [])
22
22
 
23
23
  context.interfaces.each do |netbox_interface|
24
- host_interface_ips = ip_addresses_netbox_params.select { |ip| ip.dig(:interface, :name) == netbox_interface.name }
24
+ host_interface_ips = ip_addresses_netbox_params.select do |ip|
25
+ ip.dig(:interface, :name) == netbox_interface.name
26
+ end
25
27
  .map { |ip| ip.fetch(:address) }
26
28
 
27
29
  context.ip_addresses
@@ -17,7 +17,7 @@ module ForemanNetbox
17
17
 
18
18
  def params
19
19
  {
20
- virtual_machine_id: context.virtual_machine.id
20
+ virtual_machine_id: context.virtual_machine.id,
21
21
  }
22
22
  end
23
23
  end
@@ -13,9 +13,9 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  organize SyncIpAddresses::Find,
16
- SyncIpAddresses::Delete,
17
- SyncIpAddresses::Update,
18
- SyncIpAddresses::Create
16
+ SyncIpAddresses::Delete,
17
+ SyncIpAddresses::Update,
18
+ SyncIpAddresses::Create
19
19
  end
20
20
  end
21
21
  end
@@ -22,7 +22,9 @@ module ForemanNetbox
22
22
 
23
23
  return unless new_params
24
24
 
25
- netbox_interface.mac_address = new_params[:mac_address] if netbox_interface.mac_address != new_params[:mac_address]
25
+ if netbox_interface.mac_address != new_params[:mac_address]
26
+ netbox_interface.mac_address = new_params[:mac_address]
27
+ end
26
28
  assign_tags_to(netbox_interface)
27
29
 
28
30
  netbox_interface.save
@@ -4,8 +4,8 @@ module ForemanNetbox
4
4
  class API
5
5
  def self.client
6
6
  NetboxClientRuby.configure do |config|
7
- config.netbox.api_base_url = "#{Setting::Netbox['netbox_url']}/api"
8
- config.netbox.auth.token = Setting::Netbox['netbox_api_token']
7
+ config.netbox.api_base_url = "#{Setting['netbox_url']}/api"
8
+ config.netbox.auth.token = Setting['netbox_api_token']
9
9
  end
10
10
  end
11
11
  end
@@ -14,7 +14,7 @@ module Orchestration
14
14
  protected
15
15
 
16
16
  def netbox_orchestration_allowed?
17
- Setting::Netbox[:netbox_orchestration_enabled] && netbox_will_change?
17
+ Setting[:netbox_orchestration_enabled] && netbox_will_change?
18
18
  end
19
19
 
20
20
  def queue_netbox_push
@@ -23,8 +23,7 @@ module Orchestration
23
23
  ::Foreman::Logging.logger('foreman_netbox/import')
24
24
  .info("Queued import of #{name} to Netbox. Changes that will be sent: #{netbox_params_diff}")
25
25
 
26
- post_queue.create(name: _('Push host %s to Netbox') % self, priority: 100,
27
- action: [self, :set_netbox])
26
+ post_queue.create(name: _('Push host %s to Netbox') % self, priority: 100, action: [self, :set_netbox])
28
27
  end
29
28
 
30
29
  def queue_netbox_destroy
@@ -33,8 +32,7 @@ module Orchestration
33
32
  ::Foreman::Logging.logger('foreman_netbox/import')
34
33
  .info("Queued delete of #{name} from Netbox.")
35
34
 
36
- queue.create(name: _('Delete host %s from Netbox') % self, priority: 60,
37
- action: [self, :del_netbox])
35
+ queue.create(name: _('Delete host %s from Netbox') % self, priority: 60, action: [self, :del_netbox])
38
36
  end
39
37
 
40
38
  def set_netbox
@@ -25,7 +25,7 @@ module ForemanNetbox
25
25
  attr_accessor :result
26
26
 
27
27
  def read_interfaces
28
- return unless data.keys.include?(:interfaces)
28
+ return unless data.key?(:interfaces)
29
29
 
30
30
  result[:interfaces] = data.fetch(:interfaces, {}).fetch(:results, []).map do |interface|
31
31
  interface.slice(:name, :mac_address)
@@ -35,7 +35,7 @@ module ForemanNetbox
35
35
  end
36
36
 
37
37
  def read_ip_addresses
38
- return unless data.keys.include?(:ip_addresses)
38
+ return unless data.key?(:ip_addresses)
39
39
 
40
40
  result[:ip_addresses] = data.fetch(:ip_addresses, {}).fetch(:results, []).map do |ip_address|
41
41
  ip_address.slice(:address)
@@ -44,31 +44,31 @@ module ForemanNetbox
44
44
  end
45
45
 
46
46
  def read_virtual_machine
47
- return unless data.keys.include?(:virtual_machine)
47
+ return unless data.key?(:virtual_machine)
48
48
 
49
49
  result[:virtual_machine] = data.fetch(:virtual_machine, {}).slice(:name, :vcpus, :memory, :disk)
50
50
  end
51
51
 
52
52
  def read_tenant
53
- return unless data.keys.include?(:tenant)
53
+ return unless data.key?(:tenant)
54
54
 
55
55
  result[:tenant] = data.fetch(:tenant, {}).slice(:name, :slug)
56
56
  end
57
57
 
58
58
  def read_cluster
59
- return unless data.keys.include?(:cluster)
59
+ return unless data.key?(:cluster)
60
60
 
61
61
  result[:cluster] = data.fetch(:cluster, {}).slice(:name)
62
62
  end
63
63
 
64
64
  def read_cluster_type
65
- return unless data.keys.include?(:cluster_type)
65
+ return unless data.key?(:cluster_type)
66
66
 
67
67
  result[:cluster_type] = data.fetch(:cluster_type, {}).slice(:name, :slug)
68
68
  end
69
69
 
70
70
  def read_device
71
- return unless data.keys.include?(:device)
71
+ return unless data.key?(:device)
72
72
 
73
73
  result[:device] = data.fetch(:device, {})
74
74
  .slice(:name, :serial)
@@ -77,25 +77,25 @@ module ForemanNetbox
77
77
  end
78
78
 
79
79
  def read_device_role
80
- return unless data.keys.include?(:device_role)
80
+ return unless data.key?(:device_role)
81
81
 
82
82
  result[:device_role] = data.fetch(:device_role, {}).slice(:name, :color, :slug)
83
83
  end
84
84
 
85
85
  def read_device_type
86
- return unless data.keys.include?(:device_type)
86
+ return unless data.key?(:device_type)
87
87
 
88
88
  result[:device_type] = data.fetch(:device_type, {}).slice(:model, :slug)
89
89
  end
90
90
 
91
91
  def read_manufacturer
92
- return unless data.keys.include?(:manufacturer)
92
+ return unless data.key?(:manufacturer)
93
93
 
94
94
  result[:manufacturer] = data.fetch(:manufacturer, {}).slice(:name, :slug)
95
95
  end
96
96
 
97
97
  def read_site
98
- return unless data.keys.include?(:site)
98
+ return unless data.key?(:site)
99
99
 
100
100
  result[:site] = data.fetch(:site, {}).slice(:name, :slug)
101
101
  end