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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/contracts/foreman_netbox/device_contract.rb +3 -3
- data/app/contracts/foreman_netbox/params/interface_params.rb +6 -8
- data/app/contracts/foreman_netbox/params/ip_address_params.rb +5 -7
- data/app/contracts/foreman_netbox/params/tenant_params.rb +4 -6
- data/app/contracts/foreman_netbox/virtual_machine_contract.rb +3 -3
- data/app/interactors/foreman_netbox/delete_host/organizer.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/organizer.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +0 -2
- data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +10 -10
- data/app/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb +3 -3
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +2 -3
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb +4 -4
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb +3 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb +3 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_device/update.rb +2 -0
- data/app/interactors/foreman_netbox/sync_host/sync_tags/organizer.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +0 -2
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +8 -8
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb +3 -3
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb +4 -4
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +3 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb +3 -1
- data/app/lib/foreman_netbox/api.rb +2 -2
- data/app/models/orchestration/netbox.rb +3 -5
- data/app/services/foreman_netbox/cached_netbox_parameters.rb +11 -11
- data/app/services/foreman_netbox/netbox_parameters.rb +27 -27
- data/app/services/foreman_netbox/netbox_parameters_comparator.rb +12 -6
- data/db/migrate/20230303095650_fix_netbox_settings_category_to_dsl.rb +9 -0
- data/lib/foreman_netbox/engine.rb +32 -15
- data/lib/foreman_netbox/version.rb +1 -1
- data/lib/tasks/foreman_netbox_tasks.rake +0 -2
- data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +7 -7
- data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +7 -7
- data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +8 -8
- data/test/interactors/foreman_netbox/sync_host/organizer_test.rb +13 -13
- data/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb +6 -6
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +5 -5
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +8 -8
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +38 -8
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +5 -5
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +6 -6
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +8 -8
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +8 -8
- data/test/models/foreman_netbox/netbox_facet_test.rb +1 -1
- data/test/models/foreman_netbox/nics/base_test.rb +1 -1
- data/test/services/foreman_netbox/netbox_attributes_test.rb +16 -16
- data/test/services/foreman_netbox/netbox_parameters_comparator_test.rb +31 -31
- data/test/test_plugin_helper.rb +4 -9
- metadata +75 -117
- data/app/models/setting/netbox.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c6e291e619bba70de7b1c7c67832419452ef5342d2bd008961be87a2152ee86
|
4
|
+
data.tar.gz: 9bad853a3329b00878bfaea36939fa2ab02b0957540d2b2bae1b30781a7ddc0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3612479271e7bec9c1499e482691cae0e4e2f7aed0b3d8de93085d98630d3faef83fd82ba4200c377b4ab497ebba63106c6ef4542c28a4c6cecd0c4d638161c9
|
7
|
+
data.tar.gz: ca1bfcace00f154324c72738a75059f66103ad200548c5314e5303ce6be656d1e21a2627f95f4c648ecf26c8e821cd6a28ebc92d78c381c49b78dce0acc267b2
|
data/README.md
CHANGED
@@ -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
|
8
|
-
optional(:ip_addresses).array(ForemanNetbox::Params::IpAddressParams
|
9
|
-
optional(:interfaces).array(ForemanNetbox::Params::InterfaceParams
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
required(:
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
required(:
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
7
|
-
optional(:ip_addresses).array(ForemanNetbox::Params::IpAddressParams
|
8
|
-
optional(:interfaces).array(ForemanNetbox::Params::InterfaceParams
|
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)
|
@@ -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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
24
|
+
"#{Setting[:netbox_url]}/dcim/devices/#{device&.id}" if device&.id
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -12,9 +12,9 @@ module ForemanNetbox
|
|
12
12
|
end
|
13
13
|
|
14
14
|
organize SyncDeviceType::SyncManufacturer::Organizer,
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
SyncDeviceType::Find,
|
16
|
+
SyncDeviceType::Update,
|
17
|
+
SyncDeviceType::Create
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb
CHANGED
@@ -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
|
-
|
15
|
-
|
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
|
@@ -12,10 +12,10 @@ module ForemanNetbox
|
|
12
12
|
end
|
13
13
|
|
14
14
|
organize SyncInterfaces::Find,
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
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
|
@@ -13,9 +13,9 @@ module ForemanNetbox
|
|
13
13
|
end
|
14
14
|
|
15
15
|
organize SyncIpAddresses::Find,
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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
|
@@ -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
|
-
|
18
|
+
SyncTags::Create
|
19
19
|
end
|
20
20
|
end
|
21
21
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
26
|
+
"#{Setting[:netbox_url]}/virtualization/virtual-machines/#{context.virtual_machine&.id}"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb
CHANGED
@@ -12,10 +12,10 @@ module ForemanNetbox
|
|
12
12
|
end
|
13
13
|
|
14
14
|
organize SyncInterfaces::Find,
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
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
|
@@ -13,9 +13,9 @@ module ForemanNetbox
|
|
13
13
|
end
|
14
14
|
|
15
15
|
organize SyncIpAddresses::Find,
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
SyncIpAddresses::Delete,
|
17
|
+
SyncIpAddresses::Update,
|
18
|
+
SyncIpAddresses::Create
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb
CHANGED
@@ -22,7 +22,9 @@ module ForemanNetbox
|
|
22
22
|
|
23
23
|
return unless new_params
|
24
24
|
|
25
|
-
|
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
|
8
|
-
config.netbox.auth.token = Setting
|
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
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
98
|
+
return unless data.key?(:site)
|
99
99
|
|
100
100
|
result[:site] = data.fetch(:site, {}).slice(:name, :slug)
|
101
101
|
end
|