foreman_netbox 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -6
  3. data/app/interactors/foreman_netbox/delete_host/delete_device.rb +1 -1
  4. data/app/interactors/foreman_netbox/delete_host/delete_virtual_machine.rb +1 -1
  5. data/app/interactors/foreman_netbox/sync_host/sync_device/create.rb +1 -1
  6. data/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +3 -3
  7. data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +1 -1
  8. data/app/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url.rb +1 -1
  9. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create.rb +1 -1
  10. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find.rb +1 -1
  11. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create.rb +1 -1
  12. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find.rb +1 -1
  13. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create.rb +1 -1
  14. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +2 -2
  15. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create.rb +1 -1
  16. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +1 -1
  17. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create.rb +2 -2
  18. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +1 -1
  19. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb +1 -3
  20. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/create.rb +1 -1
  21. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/find.rb +1 -1
  22. data/app/interactors/foreman_netbox/sync_host/sync_tags/create.rb +1 -1
  23. data/app/interactors/foreman_netbox/sync_host/sync_tags/find.rb +1 -1
  24. data/app/interactors/foreman_netbox/sync_host/sync_tenant/create.rb +1 -1
  25. data/app/interactors/foreman_netbox/sync_host/sync_tenant/find.rb +1 -1
  26. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/create.rb +1 -1
  27. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +2 -2
  28. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +1 -1
  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/create.rb +1 -1
  31. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find.rb +1 -1
  32. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/create.rb +1 -1
  33. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find.rb +1 -1
  34. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create.rb +8 -8
  35. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +1 -1
  36. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create.rb +2 -2
  37. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +2 -4
  38. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +1 -1
  39. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb +1 -3
  40. data/app/lib/foreman_netbox/api.rb +11 -2
  41. data/app/services/foreman_netbox/netbox_parameters.rb +2 -2
  42. data/app/services/foreman_netbox/netbox_parameters_comparator.rb +2 -2
  43. data/db/migrate/20230303095650_fix_netbox_settings_category_to_dsl.rb +0 -2
  44. data/lib/foreman_netbox/engine.rb +47 -40
  45. data/lib/foreman_netbox/version.rb +1 -1
  46. data/lib/tasks/foreman_netbox_tasks.rake +0 -48
  47. data/test/fixtures/netbox_device_raw_data.json +1 -1
  48. data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +1 -1
  49. data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +1 -1
  50. data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +1 -1
  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/save_netbox_url_test.rb +2 -2
  53. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +1 -1
  54. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +1 -1
  55. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +2 -2
  56. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +1 -1
  57. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +2 -2
  58. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +2 -2
  59. data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +2 -2
  60. data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +1 -1
  61. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url_test.rb +2 -2
  62. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +1 -1
  63. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +1 -1
  64. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +2 -2
  65. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +1 -1
  66. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +1 -1
  67. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +2 -2
  68. data/test/test_plugin_helper.rb +1 -1
  69. data/test/unit/foreman_netbox/api_test.rb +52 -0
  70. metadata +57 -56
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c6e291e619bba70de7b1c7c67832419452ef5342d2bd008961be87a2152ee86
4
- data.tar.gz: 9bad853a3329b00878bfaea36939fa2ab02b0957540d2b2bae1b30781a7ddc0c
3
+ metadata.gz: e2c91a8bd4a7bee1886c7d066161f77810c6cb11180feb3a10e559e317de1f57
4
+ data.tar.gz: a0cecb684f0a2b3c6866afa1cd0ec59809f9f9f24d8f9d8c4161f0b4ffb2d40c
5
5
  SHA512:
6
- metadata.gz: 3612479271e7bec9c1499e482691cae0e4e2f7aed0b3d8de93085d98630d3faef83fd82ba4200c377b4ab497ebba63106c6ef4542c28a4c6cecd0c4d638161c9
7
- data.tar.gz: ca1bfcace00f154324c72738a75059f66103ad200548c5314e5303ce6be656d1e21a2627f95f4c648ecf26c8e821cd6a28ebc92d78c381c49b78dce0acc267b2
6
+ metadata.gz: 02bb7f16c232d7fae6b8f51b7959c2a89161eef2625a2daae1e0c7c97a93d898a7d99e4efc396a61a59e570a4c9f90693e05edbb5fe9ce6bbb375e2ee71fccd2
7
+ data.tar.gz: fb3f6c70f8e3b4594438ca99d72078ac5193e586d8abb449d452cfec17cba0f502908acd60744a70c66bb6b660df4c7e0a1260e1e2fa65a3a9c38b3348436248
data/README.md CHANGED
@@ -1,16 +1,17 @@
1
1
  # ForemanNetbox
2
2
 
3
- [<img src="https://opensourcelogos.aws.dmtech.cloud/dmTECH_opensource_logo.svg" height="21" width="130">](https://www.dmtech.de/)
3
+ [<img src="https://raw.githubusercontent.com/dm-drogeriemarkt/.github/refs/heads/main/assets/dmtech-open-source-badge.svg">](https://www.dmtech.de/)
4
4
 
5
5
  This is a plugin for Foreman that introduces integration with [NetBox](https://netbox.readthedocs.io)
6
6
 
7
7
  ## Compatibility
8
8
 
9
- | Netbox Version | Plugin Version |
10
- | -------------- | -------------- |
11
- | 2.8 | 1.0 |
12
- | 2.11 | 1.1 |
13
- | 3.3 | 1.2 |
9
+ | Foreman Version | Netbox Version | Plugin Version |
10
+ | --------------- | -------------- | -------------- |
11
+ | <3.13 | 2.8 | 1.0 |
12
+ | <3.13 | 2.11 | 1.1 |
13
+ | <3.13 | 3.3 | 1.2 |
14
+ | >=3.13 | 3.5 | 2.0 |
14
15
 
15
16
  ## Installation
16
17
 
@@ -10,7 +10,7 @@ module ForemanNetbox
10
10
  end
11
11
 
12
12
  def call
13
- ForemanNetbox::API.client.dcim.devices.find_by(name: context.host.name)&.delete
13
+ ForemanNetbox::Api.client.dcim.devices.find_by(name: context.host.name)&.delete
14
14
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
15
15
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
16
16
  context.fail!(error: "#{self.class}: #{e}")
@@ -10,7 +10,7 @@ module ForemanNetbox
10
10
  end
11
11
 
12
12
  def call
13
- ForemanNetbox::API.client.virtualization.virtual_machines.find_by(name: context.host.name)&.delete
13
+ ForemanNetbox::Api.client.virtualization.virtual_machines.find_by(name: context.host.name)&.delete
14
14
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
15
15
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
16
16
  context.fail!(error: "#{self.class}: #{e}")
@@ -12,7 +12,7 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  def call
15
- context.device = ForemanNetbox::API.client::DCIM::Device.new(params).save
15
+ context.device = ForemanNetbox::Api.client::DCIM::Device.new(params).save
16
16
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
17
17
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
18
18
  context.fail!(error: "#{self.class}: #{e}")
@@ -21,17 +21,17 @@ module ForemanNetbox
21
21
  def find_by_serial
22
22
  serial = netbox_params.dig(:device, :serial)
23
23
 
24
- ForemanNetbox::API.client.dcim.devices.filter(serial: serial).first if serial
24
+ ForemanNetbox::Api.client.dcim.devices.filter(serial: serial).first if serial
25
25
  end
26
26
 
27
27
  def find_by_mac
28
- ForemanNetbox::API.client.dcim.devices.filter(mac_address: mac).first if mac
28
+ ForemanNetbox::Api.client.dcim.devices.filter(mac_address: mac).first if mac
29
29
  end
30
30
 
31
31
  def find_by_name
32
32
  name = netbox_params.dig(:device, :name)
33
33
 
34
- ForemanNetbox::API.client.dcim.devices.find_by(name: name)
34
+ ForemanNetbox::Api.client.dcim.devices.find_by(name: name)
35
35
  end
36
36
  end
37
37
  end
@@ -24,7 +24,7 @@ module ForemanNetbox
24
24
  SyncDevice::Create,
25
25
  SyncDevice::SyncInterfaces::Organizer,
26
26
  SyncDevice::Update,
27
- SyncDevice::SaveNetboxUrl
27
+ SyncDevice::SaveNetboxURL
28
28
  end
29
29
  end
30
30
  end
@@ -3,7 +3,7 @@
3
3
  module ForemanNetbox
4
4
  module SyncHost
5
5
  module SyncDevice
6
- class SaveNetboxUrl
6
+ class SaveNetboxURL
7
7
  include ::Interactor
8
8
 
9
9
  around do |interactor|
@@ -12,7 +12,7 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  def call
15
- context.device_role = ForemanNetbox::API.client::DCIM::DeviceRole.new(params).save
15
+ context.device_role = ForemanNetbox::Api.client::DCIM::DeviceRole.new(params).save
16
16
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
17
17
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
18
18
  context.fail!(error: "#{self.class}: #{e}")
@@ -8,7 +8,7 @@ module ForemanNetbox
8
8
  include ::Interactor
9
9
 
10
10
  def call
11
- context.device_role = ForemanNetbox::API.client.dcim.device_roles.find_by(params)
11
+ context.device_role = ForemanNetbox::Api.client.dcim.device_roles.find_by(params)
12
12
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
13
13
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
14
14
  context.fail!(error: "#{self.class}: #{e}")
@@ -13,7 +13,7 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  def call
16
- context.device_type = ForemanNetbox::API.client::DCIM::DeviceType.new(params).save
16
+ context.device_type = ForemanNetbox::Api.client::DCIM::DeviceType.new(params).save
17
17
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
18
18
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
19
19
  context.fail!(error: "#{self.class}: #{e}")
@@ -8,7 +8,7 @@ module ForemanNetbox
8
8
  include ::Interactor
9
9
 
10
10
  def call
11
- context.device_type = ForemanNetbox::API.client.dcim.device_types.find_by(params)
11
+ context.device_type = ForemanNetbox::Api.client.dcim.device_types.find_by(params)
12
12
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
13
13
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
14
14
  context.fail!(error: "#{self.class}: #{e}")
@@ -13,7 +13,7 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  def call
16
- context.manufacturer = ForemanNetbox::API.client::DCIM::Manufacturer.new(params).save
16
+ context.manufacturer = ForemanNetbox::Api.client::DCIM::Manufacturer.new(params).save
17
17
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
18
18
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
19
19
  context.fail!(error: "#{self.class}: #{e}")
@@ -23,13 +23,13 @@ module ForemanNetbox
23
23
  def find_by_slug
24
24
  params = netbox_params.fetch(:manufacturer).slice(:slug)
25
25
 
26
- ForemanNetbox::API.client.dcim.manufacturers.find_by(params)
26
+ ForemanNetbox::Api.client.dcim.manufacturers.find_by(params)
27
27
  end
28
28
 
29
29
  def find_by_name
30
30
  params = netbox_params.fetch(:manufacturer).slice(:name)
31
31
 
32
- ForemanNetbox::API.client.dcim.manufacturers.find_by(params)
32
+ ForemanNetbox::Api.client.dcim.manufacturers.find_by(params)
33
33
  end
34
34
  end
35
35
  end
@@ -17,7 +17,7 @@ module ForemanNetbox
17
17
  .select { |i| i[:name] }
18
18
  .reject { |i| interfaces.map(&:name).include?(i[:name]) }
19
19
  .map do |new_interface|
20
- ForemanNetbox::API.client::DCIM::Interface.new(
20
+ ForemanNetbox::Api.client::DCIM::Interface.new(
21
21
  new_interface.except(:type)
22
22
  .merge(
23
23
  type: new_interface.dig(:type, :value),
@@ -8,7 +8,7 @@ module ForemanNetbox
8
8
  include ::Interactor
9
9
 
10
10
  def call
11
- context.interfaces = ForemanNetbox::API.client.dcim.interfaces.filter(params)
11
+ context.interfaces = ForemanNetbox::Api.client.dcim.interfaces.filter(params)
12
12
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
13
13
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
14
14
  context.fail!(error: "#{self.class}: #{e}")
@@ -14,14 +14,14 @@ module ForemanNetbox
14
14
  interface_id = interfaces_map.fetch(ip_address.dig(:interface, :name), nil)
15
15
 
16
16
  next unless interface_id
17
- next unless ForemanNetbox::API.client
17
+ next unless ForemanNetbox::Api.client
18
18
  .ipam
19
19
  .ip_addresses
20
20
  .filter(interface_id: interface_id, address: ip_address[:address])
21
21
  .total
22
22
  .zero?
23
23
 
24
- ForemanNetbox::API.client::IPAM::IpAddress.new(
24
+ ForemanNetbox::Api.client::IPAM::IpAddress.new(
25
25
  ip_address.slice(:address)
26
26
  .merge(
27
27
  assigned_object_type: 'dcim.interface', assigned_object_id: interface_id,
@@ -9,7 +9,7 @@ module ForemanNetbox
9
9
  include ::Interactor
10
10
 
11
11
  def call
12
- context.ip_addresses = ForemanNetbox::API.client.ipam.ip_addresses.filter(params)
12
+ context.ip_addresses = ForemanNetbox::Api.client.ipam.ip_addresses.filter(params)
13
13
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
14
14
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
15
15
  context.fail!(error: "#{self.class}: #{e}")
@@ -22,9 +22,7 @@ module ForemanNetbox
22
22
 
23
23
  return unless new_params
24
24
 
25
- if netbox_interface.mac_address != new_params[:mac_address]
26
- netbox_interface.mac_address = new_params[:mac_address]
27
- end
25
+ netbox_interface.mac_address = new_params[:mac_address] if netbox_interface.mac_address != new_params[:mac_address]
28
26
  assign_tags_to(netbox_interface)
29
27
 
30
28
  netbox_interface.save
@@ -13,7 +13,7 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  def call
16
- context.site = ForemanNetbox::API.client::DCIM::Site.new(params).save
16
+ context.site = ForemanNetbox::Api.client::DCIM::Site.new(params).save
17
17
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
18
18
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
19
19
  context.fail!(error: "#{self.class}: #{e}")
@@ -8,7 +8,7 @@ module ForemanNetbox
8
8
  include ::Interactor
9
9
 
10
10
  def call
11
- context.site = ForemanNetbox::API.client.dcim.sites.find_by(params)
11
+ context.site = ForemanNetbox::Api.client.dcim.sites.find_by(params)
12
12
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
13
13
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
14
14
  context.fail!(error: "#{self.class}: #{e}")
@@ -15,7 +15,7 @@ module ForemanNetbox
15
15
  def new_tags
16
16
  SyncTags::Organizer::DEFAULT_TAGS
17
17
  .reject { |params| existing_slugs.include?(params[:slug]) }
18
- .map { |params| ForemanNetbox::API.client::Extras::Tag.new(params).save }
18
+ .map { |params| ForemanNetbox::Api.client::Extras::Tag.new(params).save }
19
19
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
20
20
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
21
21
  context.fail!(error: "#{self.class}: #{e}")
@@ -8,7 +8,7 @@ module ForemanNetbox
8
8
 
9
9
  def call
10
10
  context.tags = slugs.map do |slug|
11
- ForemanNetbox::API.client.extras.tags.find_by(slug: slug)
11
+ ForemanNetbox::Api.client.extras.tags.find_by(slug: slug)
12
12
  end.compact
13
13
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
14
14
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
@@ -12,7 +12,7 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  def call
15
- context.tenant = ForemanNetbox::API.client::Tenancy::Tenant.new(params).save
15
+ context.tenant = ForemanNetbox::Api.client::Tenancy::Tenant.new(params).save
16
16
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
17
17
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
18
18
  context.fail!(error: "#{self.class}: #{e}")
@@ -7,7 +7,7 @@ module ForemanNetbox
7
7
  include ::Interactor
8
8
 
9
9
  def call
10
- context.tenant = ForemanNetbox::API.client.tenancy.tenants.find_by(params)
10
+ context.tenant = ForemanNetbox::Api.client.tenancy.tenants.find_by(params)
11
11
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
12
12
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
13
13
  context.fail!(error: "#{self.class}: #{e}")
@@ -12,7 +12,7 @@ module ForemanNetbox
12
12
  end
13
13
 
14
14
  def call
15
- context.virtual_machine = ForemanNetbox::API.client::Virtualization::VirtualMachine.new(params).save
15
+ context.virtual_machine = ForemanNetbox::Api.client::Virtualization::VirtualMachine.new(params).save
16
16
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
17
17
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
18
18
  context.fail!(error: "#{self.class}: #{e}")
@@ -19,12 +19,12 @@ module ForemanNetbox
19
19
  delegate :mac, to: :host
20
20
 
21
21
  def find_by_mac
22
- ForemanNetbox::API.client.virtualization.virtual_machines.filter(mac_address: mac).first if mac
22
+ ForemanNetbox::Api.client.virtualization.virtual_machines.filter(mac_address: mac).first if mac
23
23
  end
24
24
 
25
25
  def find_by_name
26
26
  params = netbox_params.fetch(:virtual_machine).slice(:name)
27
- ForemanNetbox::API.client.virtualization.virtual_machines.find_by(params)
27
+ ForemanNetbox::Api.client.virtualization.virtual_machines.find_by(params)
28
28
  end
29
29
  end
30
30
  end
@@ -22,7 +22,7 @@ module ForemanNetbox
22
22
  SyncVirtualMachine::Create,
23
23
  SyncVirtualMachine::SyncInterfaces::Organizer,
24
24
  SyncVirtualMachine::Update,
25
- SyncVirtualMachine::SaveNetboxUrl
25
+ SyncVirtualMachine::SaveNetboxURL
26
26
  end
27
27
  end
28
28
  end
@@ -3,7 +3,7 @@
3
3
  module ForemanNetbox
4
4
  module SyncHost
5
5
  module SyncVirtualMachine
6
- class SaveNetboxUrl
6
+ class SaveNetboxURL
7
7
  include ::Interactor
8
8
 
9
9
  around do |interactor|
@@ -13,7 +13,7 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  def call
16
- context.cluster = ForemanNetbox::API.client::Virtualization::Cluster.new(params).save
16
+ context.cluster = ForemanNetbox::Api.client::Virtualization::Cluster.new(params).save
17
17
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
18
18
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
19
19
  context.fail!(error: "#{self.class}: #{e}")
@@ -8,7 +8,7 @@ module ForemanNetbox
8
8
  include ::Interactor
9
9
 
10
10
  def call
11
- context.cluster = ForemanNetbox::API.client.virtualization.clusters.find_by(params)
11
+ context.cluster = ForemanNetbox::Api.client.virtualization.clusters.find_by(params)
12
12
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
13
13
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
14
14
  context.fail!(error: "#{self.class}: #{e}")
@@ -13,7 +13,7 @@ module ForemanNetbox
13
13
  end
14
14
 
15
15
  def call
16
- context.cluster_type = ForemanNetbox::API.client::Virtualization::ClusterType.new(params).save
16
+ context.cluster_type = ForemanNetbox::Api.client::Virtualization::ClusterType.new(params).save
17
17
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
18
18
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
19
19
  context.fail!(error: "#{self.class}: #{e}")
@@ -11,7 +11,7 @@ module ForemanNetbox
11
11
  def call
12
12
  return unless params
13
13
 
14
- context.cluster_type = ForemanNetbox::API.client.virtualization.cluster_types.find_by(params)
14
+ context.cluster_type = ForemanNetbox::Api.client.virtualization.cluster_types.find_by(params)
15
15
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
16
16
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
17
17
  context.fail!(error: "#{self.class}: #{e}")
@@ -17,14 +17,14 @@ module ForemanNetbox
17
17
  .select { |i| i[:name] }
18
18
  .reject { |i| interfaces.map(&:name).include?(i[:name]) }
19
19
  .map do |new_interface|
20
- ForemanNetbox::API.client::Virtualization::Interface.new(
21
- new_interface.except(:type)
22
- .merge(
23
- virtual_machine: virtual_machine.id,
24
- tags: default_tag_ids
25
- )
26
- ).save
27
- end
20
+ ForemanNetbox::Api.client::Virtualization::Interface.new(
21
+ new_interface.except(:type)
22
+ .merge(
23
+ virtual_machine: virtual_machine.id,
24
+ tags: default_tag_ids
25
+ )
26
+ ).save
27
+ end
28
28
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
29
29
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
30
30
  context.fail!(error: "#{self.class}: #{e}")
@@ -8,7 +8,7 @@ module ForemanNetbox
8
8
  include ::Interactor
9
9
 
10
10
  def call
11
- context.interfaces = ForemanNetbox::API.client.virtualization.interfaces.filter(params)
11
+ context.interfaces = ForemanNetbox::Api.client.virtualization.interfaces.filter(params)
12
12
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
13
13
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
14
14
  context.fail!(error: "#{self.class}: #{e}")
@@ -14,14 +14,14 @@ module ForemanNetbox
14
14
  interface_id = interfaces_map.fetch(ip_address.dig(:interface, :name), nil)
15
15
 
16
16
  next unless interface_id
17
- next unless ForemanNetbox::API.client
17
+ next unless ForemanNetbox::Api.client
18
18
  .ipam
19
19
  .ip_addresses
20
20
  .filter(vminterface_id: interface_id, address: ip_address[:address])
21
21
  .total
22
22
  .zero?
23
23
 
24
- ForemanNetbox::API.client::IPAM::IpAddress.new(
24
+ ForemanNetbox::Api.client::IPAM::IpAddress.new(
25
25
  ip_address.slice(:address)
26
26
  .merge(
27
27
  assigned_object_type: 'virtualization.vminterface', assigned_object_id: interface_id,
@@ -22,9 +22,8 @@ module ForemanNetbox
22
22
 
23
23
  context.interfaces.each do |netbox_interface|
24
24
  host_interface_ips = ip_addresses_netbox_params.select do |ip|
25
- ip.dig(:interface, :name) == netbox_interface.name
26
- end
27
- .map { |ip| ip.fetch(:address) }
25
+ ip.dig(:interface, :name) == netbox_interface.name
26
+ end.map { |ip| ip.fetch(:address) }
28
27
 
29
28
  context.ip_addresses
30
29
  .select { |ip| ip['assigned_object_type'] == 'virtualization.vminterface' && ip['assigned_object_id'] == netbox_interface.id }
@@ -32,7 +31,6 @@ module ForemanNetbox
32
31
  .each(&:delete)
33
32
  end
34
33
  end
35
-
36
34
  delegate :netbox_params, to: :context
37
35
  end
38
36
  end
@@ -9,7 +9,7 @@ module ForemanNetbox
9
9
  include ::Interactor
10
10
 
11
11
  def call
12
- context.ip_addresses = ForemanNetbox::API.client.ipam.ip_addresses.filter(params)
12
+ context.ip_addresses = ForemanNetbox::Api.client.ipam.ip_addresses.filter(params)
13
13
  rescue NetboxClientRuby::LocalError, NetboxClientRuby::ClientError, NetboxClientRuby::RemoteError => e
14
14
  ::Foreman::Logging.logger('foreman_netbox/import').error("#{self.class} error #{e}: #{e.backtrace}")
15
15
  context.fail!(error: "#{self.class}: #{e}")
@@ -22,9 +22,7 @@ module ForemanNetbox
22
22
 
23
23
  return unless new_params
24
24
 
25
- if netbox_interface.mac_address != new_params[:mac_address]
26
- netbox_interface.mac_address = new_params[:mac_address]
27
- end
25
+ netbox_interface.mac_address = new_params[:mac_address] if netbox_interface.mac_address != new_params[:mac_address]
28
26
  assign_tags_to(netbox_interface)
29
27
 
30
28
  netbox_interface.save
@@ -1,12 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanNetbox
4
- class API
4
+ class Api
5
5
  def self.client
6
6
  NetboxClientRuby.configure do |config|
7
- config.netbox.api_base_url = "#{Setting['netbox_url']}/api"
7
+ config.netbox.api_base_url = netbox_api_url
8
8
  config.netbox.auth.token = Setting['netbox_api_token']
9
9
  end
10
10
  end
11
+
12
+ def self.netbox_api_url
13
+ return Setting['netbox_api_url'] if URI.parse(Setting['netbox_api_url']).is_a?(URI::HTTP)
14
+
15
+ api_url = "#{Setting['netbox_url']}/api"
16
+ return api_url if URI.parse(api_url).is_a?(URI::HTTP)
17
+
18
+ raise Foreman::Exception, 'Invalid Netbox API URL, please check the netbox_url and netbox_api_url settings'
19
+ end
11
20
  end
12
21
  end
@@ -123,7 +123,7 @@ module ForemanNetbox
123
123
  }
124
124
  end
125
125
 
126
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
126
+ # rubocop:disable Metrics/CyclomaticComplexity
127
127
  def ip_addresses
128
128
  {
129
129
  ip_addresses: host.interfaces.map do |interface|
@@ -144,7 +144,7 @@ module ForemanNetbox
144
144
  end.flatten,
145
145
  }
146
146
  end
147
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
147
+ # rubocop:enable Metrics/CyclomaticComplexity
148
148
 
149
149
  def virtual_machine
150
150
  {
@@ -66,7 +66,7 @@ module ForemanNetbox
66
66
  end.compact
67
67
  end
68
68
 
69
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
69
+ # rubocop:disable Metrics/CyclomaticComplexity
70
70
  def diff_new
71
71
  new_hash.except(*added_keys).each_with_object({}) do |(key, new_value), memo|
72
72
  case new_value
@@ -97,6 +97,6 @@ module ForemanNetbox
97
97
  end
98
98
  end.compact
99
99
  end
100
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
100
+ # rubocop:enable Metrics/CyclomaticComplexity
101
101
  end
102
102
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  class FixNetboxSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
4
4
  def up
5
- # rubocop:disable Rails/SkipsModelValidations
6
5
  Setting.where(category: 'Setting::Netbox').update_all(category: 'Setting') if column_exists?(:settings, :category)
7
- # rubocop:enable Rails/SkipsModelValidations
8
6
  end
9
7
  end