foreman_netbox 1.1.1 → 1.2.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.
- checksums.yaml +4 -4
- 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/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_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/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/models/orchestration/netbox.rb +2 -4
- 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/lib/foreman_netbox/engine.rb +20 -20
- 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 +7 -7
- data/test/interactors/foreman_netbox/sync_host/organizer_test.rb +9 -9
- 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 +9 -9
- 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
- metadata +33 -111
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
|
@@ -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
|
@@ -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
|
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
|
@@ -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
|
@@ -6,15 +6,15 @@ module ForemanNetbox
|
|
6
6
|
UNKNOWN = 'Unknown'
|
7
7
|
DEFAULT_INTERFACE_TYPE = 'virtual'
|
8
8
|
CLUSTER_TYPES = {
|
9
|
-
|
9
|
+
'Foreman::Model::Vmware': {
|
10
10
|
name: 'VMware ESXi',
|
11
|
-
slug: 'vmware-esxi'
|
12
|
-
}
|
11
|
+
slug: 'vmware-esxi',
|
12
|
+
},
|
13
13
|
}.freeze
|
14
14
|
DEVICE_ROLE = {
|
15
15
|
name: 'SERVER',
|
16
16
|
color: '9e9e9e',
|
17
|
-
slug: 'server'
|
17
|
+
slug: 'server',
|
18
18
|
}.freeze
|
19
19
|
|
20
20
|
def self.call(host)
|
@@ -46,7 +46,7 @@ module ForemanNetbox
|
|
46
46
|
vcpus: compute_object&.cpus,
|
47
47
|
memory: compute_object&.memory_mb,
|
48
48
|
disk: compute_object&.volumes&.map(&:size_gb)&.reduce(&:+),
|
49
|
-
cluster: compute_object&.cluster
|
49
|
+
cluster: compute_object&.cluster,
|
50
50
|
}.compact
|
51
51
|
end
|
52
52
|
end
|
@@ -55,8 +55,8 @@ module ForemanNetbox
|
|
55
55
|
{
|
56
56
|
tenant: {
|
57
57
|
name: host.owner&.netbox_tenant_name,
|
58
|
-
slug: host.owner&.netbox_tenant_slug
|
59
|
-
}
|
58
|
+
slug: host.owner&.netbox_tenant_slug,
|
59
|
+
},
|
60
60
|
}
|
61
61
|
end
|
62
62
|
|
@@ -64,14 +64,14 @@ module ForemanNetbox
|
|
64
64
|
{
|
65
65
|
device: {
|
66
66
|
name: host.name,
|
67
|
-
serial: host.facts.deep_symbolize_keys[:serialnumber]
|
68
|
-
}
|
67
|
+
serial: host.facts.deep_symbolize_keys[:serialnumber],
|
68
|
+
},
|
69
69
|
}
|
70
70
|
end
|
71
71
|
|
72
72
|
def device_role
|
73
73
|
{
|
74
|
-
device_role: DEVICE_ROLE
|
74
|
+
device_role: DEVICE_ROLE,
|
75
75
|
}
|
76
76
|
end
|
77
77
|
|
@@ -81,8 +81,8 @@ module ForemanNetbox
|
|
81
81
|
{
|
82
82
|
device_type: {
|
83
83
|
model: model,
|
84
|
-
slug: model.parameterize
|
85
|
-
}
|
84
|
+
slug: model.parameterize,
|
85
|
+
},
|
86
86
|
}
|
87
87
|
end
|
88
88
|
|
@@ -92,8 +92,8 @@ module ForemanNetbox
|
|
92
92
|
{
|
93
93
|
manufacturer: {
|
94
94
|
name: name,
|
95
|
-
slug: cached_netbox_params.dig(:manufacturer, :slug) || name.parameterize
|
96
|
-
}
|
95
|
+
slug: cached_netbox_params.dig(:manufacturer, :slug) || name.parameterize,
|
96
|
+
},
|
97
97
|
}
|
98
98
|
end
|
99
99
|
|
@@ -101,8 +101,8 @@ module ForemanNetbox
|
|
101
101
|
{
|
102
102
|
site: {
|
103
103
|
name: host.location&.netbox_site_name,
|
104
|
-
slug: host.location&.netbox_site_slug
|
105
|
-
}
|
104
|
+
slug: host.location&.netbox_site_slug,
|
105
|
+
},
|
106
106
|
}
|
107
107
|
end
|
108
108
|
|
@@ -116,10 +116,10 @@ module ForemanNetbox
|
|
116
116
|
name: identifier || (mac_address && "Interface #{mac_address}"),
|
117
117
|
mac_address: mac_address,
|
118
118
|
type: {
|
119
|
-
value: DEFAULT_INTERFACE_TYPE
|
120
|
-
}
|
119
|
+
value: DEFAULT_INTERFACE_TYPE,
|
120
|
+
},
|
121
121
|
}
|
122
|
-
end
|
122
|
+
end,
|
123
123
|
}
|
124
124
|
end
|
125
125
|
|
@@ -129,7 +129,7 @@ module ForemanNetbox
|
|
129
129
|
ip_addresses: host.interfaces.map do |interface|
|
130
130
|
[
|
131
131
|
interface.ip && interface.subnet && "#{interface.ip}/#{interface.subnet.cidr}",
|
132
|
-
interface.ip6 && interface.subnet6 && "#{interface.ip6}/#{interface.subnet6.cidr}"
|
132
|
+
interface.ip6 && interface.subnet6 && "#{interface.ip6}/#{interface.subnet6.cidr}",
|
133
133
|
].compact.map do |ip_address|
|
134
134
|
identifier = interface.identifier.present? && interface.identifier
|
135
135
|
mac_address = interface.mac&.upcase
|
@@ -137,11 +137,11 @@ module ForemanNetbox
|
|
137
137
|
{
|
138
138
|
address: ip_address,
|
139
139
|
interface: {
|
140
|
-
name: identifier || (mac_address && "Interface #{mac_address}")
|
141
|
-
}
|
140
|
+
name: identifier || (mac_address && "Interface #{mac_address}"),
|
141
|
+
},
|
142
142
|
}
|
143
143
|
end
|
144
|
-
end.flatten
|
144
|
+
end.flatten,
|
145
145
|
}
|
146
146
|
end
|
147
147
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
@@ -152,15 +152,15 @@ module ForemanNetbox
|
|
152
152
|
:vcpus, :memory, :disk
|
153
153
|
).merge(
|
154
154
|
name: host.name
|
155
|
-
)
|
155
|
+
),
|
156
156
|
}
|
157
157
|
end
|
158
158
|
|
159
159
|
def cluster
|
160
160
|
{
|
161
161
|
cluster: {
|
162
|
-
name: netbox_compute_attributes[:cluster]
|
163
|
-
}.compact
|
162
|
+
name: netbox_compute_attributes[:cluster],
|
163
|
+
}.compact,
|
164
164
|
}
|
165
165
|
end
|
166
166
|
|
@@ -168,7 +168,7 @@ module ForemanNetbox
|
|
168
168
|
type = host.compute_resource&.type&.to_sym
|
169
169
|
|
170
170
|
{
|
171
|
-
cluster_type: CLUSTER_TYPES.fetch(type, nil)
|
171
|
+
cluster_type: CLUSTER_TYPES.fetch(type, nil),
|
172
172
|
}
|
173
173
|
end
|
174
174
|
end
|