foreman_bootdisk 13.0.0 → 16.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS +29 -0
  3. data/CHANGES.md +4 -0
  4. data/README.md +19 -2
  5. data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +11 -9
  6. data/app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb +37 -31
  7. data/app/controllers/foreman_bootdisk/disks_controller.rb +20 -19
  8. data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +86 -45
  9. data/app/lib/foreman_bootdisk/scope/bootdisk.rb +2 -0
  10. data/app/lib/foreman_bootdisk/scope/full_host_bootdisk.rb +15 -0
  11. data/app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb +4 -2
  12. data/app/models/concerns/foreman_bootdisk/host_ext.rb +42 -30
  13. data/app/models/concerns/foreman_bootdisk/orchestration/compute.rb +14 -10
  14. data/app/models/setting/bootdisk.rb +21 -23
  15. data/app/services/foreman_bootdisk/iso_generator.rb +144 -104
  16. data/app/services/foreman_bootdisk/renderer.rb +17 -13
  17. data/app/views/foreman_bootdisk/generic_static_host.erb +34 -0
  18. data/app/views/foreman_bootdisk/host.erb +27 -11
  19. data/config/routes.rb +15 -13
  20. data/config/routes/mount_engine.rb +3 -1
  21. data/db/migrate/20130914211030_create_host_bootdisk_template.rb +4 -4
  22. data/db/migrate/20130915104500_edit_host_bootdisk_template_multinic.rb +4 -4
  23. data/db/migrate/20130915133321_create_kickstart_bootdisk_template.rb +4 -4
  24. data/db/migrate/20130915201457_create_generic_host_bootdisk_template.rb +4 -4
  25. data/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb +4 -4
  26. data/db/migrate/20140522185700_change_templatekind_to_bootdisk.rb +16 -14
  27. data/db/migrate/20171009225200_remove_duplicate_bootdisk_templates.rb +4 -2
  28. data/db/seeds.d/50-bootdisk_templates.rb +21 -36
  29. data/lib/foreman_bootdisk.rb +2 -0
  30. data/lib/foreman_bootdisk/engine.rb +26 -37
  31. data/lib/foreman_bootdisk/version.rb +3 -1
  32. data/lib/tasks/bootdisk.rake +34 -17
  33. data/locale/ca/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  34. data/locale/ca/foreman_bootdisk.po +31 -15
  35. data/locale/de/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  36. data/locale/de/foreman_bootdisk.po +39 -21
  37. data/locale/en/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  38. data/locale/en/foreman_bootdisk.po +24 -9
  39. data/locale/en_GB/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  40. data/locale/en_GB/foreman_bootdisk.po +30 -15
  41. data/locale/es/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  42. data/locale/es/foreman_bootdisk.po +48 -33
  43. data/locale/foreman_bootdisk.pot +80 -52
  44. data/locale/fr/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  45. data/locale/fr/foreman_bootdisk.po +30 -15
  46. data/locale/gemspec.rb +3 -1
  47. data/locale/it/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  48. data/locale/it/foreman_bootdisk.po +28 -13
  49. data/locale/ja/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  50. data/locale/ja/foreman_bootdisk.po +29 -14
  51. data/locale/ko/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  52. data/locale/ko/foreman_bootdisk.po +28 -13
  53. data/locale/pt_BR/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  54. data/locale/pt_BR/foreman_bootdisk.po +42 -26
  55. data/locale/ru/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  56. data/locale/ru/foreman_bootdisk.po +28 -13
  57. data/locale/sv_SE/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  58. data/locale/sv_SE/foreman_bootdisk.po +26 -11
  59. data/locale/zh_CN/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  60. data/locale/zh_CN/foreman_bootdisk.po +46 -31
  61. data/locale/zh_TW/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  62. data/locale/zh_TW/foreman_bootdisk.po +28 -13
  63. data/release-gem +84 -0
  64. data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +35 -33
  65. data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +9 -7
  66. data/test/functional/foreman_bootdisk/disks_controller_test.rb +27 -25
  67. data/test/models/host/managed_test.rb +17 -13
  68. data/test/test_plugin_helper.rb +11 -7
  69. data/test/unit/access_permissions_test.rb +2 -0
  70. data/test/unit/concerns/compute_resources/vmware_test.rb +67 -63
  71. data/test/unit/concerns/host_test.rb +64 -53
  72. data/test/unit/concerns/orchestration/compute_test.rb +41 -39
  73. data/test/unit/foreman_bootdisk/renderer_test.rb +3 -1
  74. data/test/unit/foreman_bootdisk/scope/bootdisk_test.rb +3 -1
  75. data/test/unit/foreman_bootdisk/scope/full_host_bootdisk_test.rb +30 -0
  76. data/test/unit/iso_generator_test.rb +67 -40
  77. metadata +65 -5
@@ -1,30 +1,33 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module ForemanBootdisk
4
6
  class Renderer
5
7
  def generic_template_render(subnet = nil)
6
- if subnet.present?
7
- # rendering a subnet-level bootdisk requires tricking the renderer into thinking it has a
8
- # valid host, without a token, but with a tftp proxy
9
- host = Struct.new(:token, :provision_interface).new(
10
- nil,
11
- Struct.new(:subnet).new(subnet)
12
- )
13
- else
14
- host = Struct.new(:token, :subnet).new(nil, nil)
15
- end
8
+ host = if subnet.present?
9
+ # rendering a subnet-level bootdisk requires tricking the renderer into thinking it has a
10
+ # valid host, without a token, but with a tftp proxy
11
+ Struct.new(:token, :provision_interface, :content_source).new(
12
+ nil,
13
+ Struct.new(:subnet).new(subnet),
14
+ nil
15
+ )
16
+ else
17
+ Struct.new(:token, :subnet, :content_source).new(nil, nil, nil)
18
+ end
16
19
 
17
20
  render_template(template: generic_host_template, host: host)
18
21
  end
19
22
 
20
- def render_template(template: , host:)
23
+ def render_template(template:, host:, scope_class: renderer_scope)
21
24
  source = Foreman::Renderer.get_source(
22
25
  template: template,
23
26
  host: host
24
27
  )
25
28
  scope = Foreman::Renderer.get_scope(
26
29
  host: host,
27
- klass: renderer_scope
30
+ klass: scope_class
28
31
  )
29
32
  Foreman::Renderer.render(source, scope)
30
33
  end
@@ -36,8 +39,9 @@ module ForemanBootdisk
36
39
  end
37
40
 
38
41
  def generic_host_template
39
- template = ProvisioningTemplate.unscoped.find_by_name(Setting[:bootdisk_generic_host_template])
42
+ template = ProvisioningTemplate.unscoped.find_by(name: Setting[:bootdisk_generic_host_template])
40
43
  raise ::Foreman::Exception.new(N_('Unable to find template specified by %s setting'), 'bootdisk_generic_host_template') unless template
44
+
41
45
  template
42
46
  end
43
47
  end
@@ -0,0 +1,34 @@
1
+ #!ipxe
2
+ #
3
+ # Generic host template with interactive static IP configuration. Tokens
4
+ # must be disabled in order to access templates via MAC addresses.
5
+ #
6
+
7
+ <% (0..32).each do |i| -%>
8
+ :net<%= i %>
9
+ isset ${net<%= i -%>/mac} || goto configure
10
+ echo Found ${net<%= i -%>/mac} as net<%= i -%> on a ${net<%= i -%>/chip}
11
+ goto net<%= i+1 %>
12
+ <% end -%>
13
+
14
+ :configure
15
+ echo -n Interface (e.g. net0): && read interface
16
+ iseq ${interface} n && goto reboot ||
17
+ iseq ${interface} N && goto reboot ||
18
+
19
+ ifopen ${interface}
20
+ echo Please enter IPv4 details for ${interface}
21
+ echo
22
+
23
+ echo -n IP address: && read ${interface}/ip
24
+ echo -n Subnet mask: && read ${interface}/netmask
25
+ echo -n Default gateway: && read ${interface}/gateway
26
+ echo -n DNS server: && read dns
27
+
28
+ chain <%= bootdisk_chain_url %>${${interface}/mac} || goto reboot
29
+ exit 0
30
+
31
+ :reboot
32
+ echo Unable to continue, rebooting...
33
+ sleep 30
34
+ exit 1
@@ -7,9 +7,23 @@
7
7
  <%
8
8
  interface = @host.provision_interface
9
9
  bootdisk_raise(N_('Host has no provisioning interface defined')) unless interface
10
- bootdisk_raise(N_('Host has no IP address defined')) if interface.ip.nil? || interface.ip.empty?
11
- bootdisk_raise(N_('Host has no subnet defined')) unless interface.subnet
10
+ bootdisk_raise(N_('Host has no IPv4 or IPv6 address defined')) unless interface.ip.present? || interface.ip6.present?
11
+ bootdisk_raise(N_('Host has no subnet defined')) unless interface.subnet || interface.subnet6
12
12
  bootdisk_raise(N_('Host has no domain defined')) unless interface.domain
13
+ if interface.ip.present? && interface.subnet
14
+ ip = interface.ip
15
+ subnet = interface.subnet
16
+ elsif interface.ip6.present? && interface.subnet6
17
+ ip = interface.ip6
18
+ subnet = interface.subnet6
19
+ bootdisk_raise(N_('Host bootdisk does not work with static IPv6'))
20
+ else
21
+ bootdisk_raise(N_('Both IP and Subnet must be set'))
22
+ end
23
+
24
+ mask = subnet.mask
25
+ gw = subnet.gateway
26
+ dns = subnet.dns_servers.first
13
27
  %>
14
28
 
15
29
  echo Foreman Bootdisk: Host image (<%= @host.name %>)
@@ -25,20 +39,22 @@ goto loop_success
25
39
  <% end -%>
26
40
 
27
41
  :loop_success
28
- echo Configuring net${idx} for static IP address <%= interface.ip %>
42
+ echo Configuring net${idx} for static IP address <%= ip %>
29
43
  ifopen net${idx}
30
- set netX/ip <%= interface.ip %>
31
- set netX/netmask <%= interface.subnet.mask %>
32
- <% if interface.subnet.gateway.present? %>
33
- set netX/gateway <%= interface.subnet.gateway %>
44
+ # netX = last opened NIC
45
+ set netX/ip <%= ip %>
46
+ set netX/netmask <%= mask %>
47
+ <% if gw.present? %>
48
+ set netX/gateway <%= gw %>
34
49
  <% end %>
35
50
  ifstat net${idx}
36
51
  route
37
52
 
38
- <% if interface.subnet.dns_primary.present? %>
39
- # Note, iPXE can only use one DNS server
40
- echo Using DNS <%= interface.subnet.dns_primary %>
41
- set dns <%= interface.subnet.dns_primary %>
53
+ # Note: When multiple DNS servers are specified, only the first
54
+ # server will be used. See: http://ipxe.org/cfg/dns
55
+ <% if dns.present? -%>
56
+ echo Using DNS <%= dns %>
57
+ set dns <%= dns %>
42
58
  set domain <%= interface.domain.to_s %>
43
59
  <% end %>
44
60
 
@@ -1,20 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ForemanBootdisk::Engine.routes.draw do
2
- resources :disks, :only => [] do
3
- get 'generic', :on => :collection
4
- get 'help', :on => :collection
5
- constraints(:id => /[^\/]+/) do
6
- get 'hosts/:id', :on => :collection, :to => 'disks#host'
7
- get 'full_hosts/:id', :on => :collection, :to => 'disks#full_host'
8
- get 'subnet/:id', :on => :collection, :to => 'disks#subnet'
4
+ resources :disks, only: [] do
5
+ get 'generic', on: :collection
6
+ get 'help', on: :collection
7
+ constraints(id: %r{[^/]+}) do
8
+ get 'hosts/:id', on: :collection, to: 'disks#host'
9
+ get 'full_hosts/:id', on: :collection, to: 'disks#full_host'
10
+ get 'subnet/:id', on: :collection, to: 'disks#subnet'
9
11
  end
10
12
  end
11
13
 
12
- namespace :api, :defaults => {:format => 'json'} do
13
- scope "(:apiv)", :module => :v2, :defaults => {:apiv => 'v2'}, :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2, :default => true) do
14
- get 'generic', :to => 'disks#generic'
15
- constraints(:id => /[^\/]+/) do
16
- get 'hosts/:id', :to => 'disks#host'
17
- get 'subnets/:id', :to => 'subnet_disks#subnet'
14
+ namespace :api, defaults: { format: 'json' } do
15
+ scope '(:apiv)', module: :v2, defaults: { apiv: 'v2' }, apiv: /v1|v2/, constraints: ApiConstraints.new(version: 2, default: true) do
16
+ get 'generic', to: 'disks#generic'
17
+ constraints(id: %r{[^/]+}) do
18
+ get 'hosts/:id', to: 'disks#host'
19
+ get 'subnets/:id', to: 'subnet_disks#subnet'
18
20
  end
19
21
  end
20
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Foreman::Application.routes.draw do
2
- mount ForemanBootdisk::Engine, :at => "/bootdisk"
4
+ mount ForemanBootdisk::Engine, at: '/bootdisk'
3
5
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateHostBootdiskTemplate < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class EditHostBootdiskTemplateMultinic < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateKickstartBootdiskTemplate < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateGenericHostBootdiskTemplate < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class EditHostBootdiskTemplateDnsSecondary < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,29 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ChangeTemplatekindToBootdisk < ActiveRecord::Migration[4.2]
2
4
  class FakeConfigTemplate < ApplicationRecord
3
- if ActiveRecord::Base.connection.migration_context.get_all_versions.include?(20150514072626)
4
- self.table_name = 'templates'
5
- else
6
- self.table_name = 'config_templates'
7
- end
5
+ self.table_name = if ActiveRecord::Base.connection.migration_context.get_all_versions.include?(20_150_514_072_626)
6
+ 'templates'
7
+ else
8
+ 'config_templates'
9
+ end
8
10
  end
9
11
 
10
12
  def self.up
11
- kind = TemplateKind.where(:name => 'Bootdisk').first_or_create
13
+ kind = TemplateKind.where(name: 'Bootdisk').first_or_create
12
14
 
13
- tmpl_h = Setting.find_by_name('bootdisk_host_template').try(:value)
14
- tmpl_g = Setting.find_by_name('bootdisk_generic_host_template').try(:value)
15
+ tmpl_h = Setting.find_by(name: 'bootdisk_host_template').try(:value)
16
+ tmpl_g = Setting.find_by(name: 'bootdisk_generic_host_template').try(:value)
15
17
 
16
18
  (FakeConfigTemplate.unscoped.where('name LIKE ?', '%Boot disk%') |
17
- FakeConfigTemplate.unscoped.where(:name => [tmpl_h, tmpl_g].compact)).each do |tmpl|
19
+ FakeConfigTemplate.unscoped.where(name: [tmpl_h, tmpl_g].compact)).each do |tmpl|
18
20
  tmpl.update_attribute(:template_kind_id, kind.id)
19
21
  end
20
22
  end
21
23
 
22
24
  def self.down
23
- old_kind = TemplateKind.find_by_name('Bootdisk')
24
- new_kind = TemplateKind.find_by_name('iPXE')
25
- if old_kind.present? && new_kind.present?
26
- FakeConfigTemplate.unscoped.where(:template_kind_id => old_kind.id).update_all(:template_kind_id => new_kind.id)
27
- end
25
+ old_kind = TemplateKind.find_by(name: 'Bootdisk')
26
+ new_kind = TemplateKind.find_by(name: 'iPXE')
27
+ return unless old_kind.present? && new_kind.present?
28
+
29
+ FakeConfigTemplate.unscoped.where(template_kind_id: old_kind.id).update_all(template_kind_id: new_kind.id)
28
30
  end
29
31
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RemoveDuplicateBootdiskTemplates < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  template_names = ['Boot disk iPXE - host', 'Boot disk iPXE - generic host']
4
6
  template_names.each do |template_name|
5
- duplicate_template_ids = ProvisioningTemplate.unscoped.where(:name => template_name, :locked => true).order(:created_at => :asc).pluck(:id).drop(1)
6
- ProvisioningTemplate.unscoped.where(:id => duplicate_template_ids).destroy_all if duplicate_template_ids.any?
7
+ duplicate_template_ids = ProvisioningTemplate.unscoped.where(name: template_name, locked: true).order(created_at: :asc).pluck(:id).drop(1)
8
+ ProvisioningTemplate.unscoped.where(id: duplicate_template_ids).destroy_all if duplicate_template_ids.any?
7
9
  end
8
10
  end
9
11
  end
@@ -1,46 +1,31 @@
1
- kind = TemplateKind.unscoped.where(:name => 'Bootdisk').first_or_create
1
+ # frozen_string_literal: true
2
2
 
3
- organizations = Organization.all
4
- locations = Location.all
5
- created = []
6
-
7
- ProvisioningTemplate.without_auditing do
8
- content = File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', 'host.erb'))
9
- created << 'Boot disk iPXE - host' unless ProvisioningTemplate.find_by_name('Boot disk iPXE - host')
10
- tmpl = ProvisioningTemplate.unscoped.where(:name => 'Boot disk iPXE - host').first_or_create do |template|
11
- template.attributes = {
12
- :template_kind_id => kind.id,
13
- :snippet => false,
14
- :template => content
15
- }
16
- end
17
- tmpl.attributes = {
18
- :template => content,
19
- :default => true,
20
- :vendor => "Foreman boot disk",
21
- }
22
- tmpl.locked = true
23
- tmpl.save!(:validate => false) if tmpl.changes.present?
3
+ def read_bootdisk_template(filename)
4
+ File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', filename))
5
+ end
24
6
 
25
- content = File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', 'generic_host.erb'))
26
- created << 'Boot disk iPXE - generic host' unless ProvisioningTemplate.find_by_name('Boot disk iPXE - generic host')
27
- tmpl = ProvisioningTemplate.unscoped.where(:name => 'Boot disk iPXE - generic host').first_or_create do |template|
7
+ def ensure_bootdisk_template(name, content)
8
+ kind = TemplateKind.unscoped.where(name: 'Bootdisk').first_or_create
9
+ tmpl = ProvisioningTemplate.unscoped.where(name: name).first_or_create do |template|
28
10
  template.attributes = {
29
- :template_kind_id => kind.id,
30
- :snippet => false,
31
- :template => content
11
+ template_kind_id: kind.id,
12
+ snippet: false,
13
+ template: content
32
14
  }
33
15
  end
34
16
  tmpl.attributes = {
35
- :template => content,
36
- :default => true,
37
- :vendor => "Foreman boot disk",
17
+ template: content,
18
+ default: true,
19
+ vendor: "Foreman boot disk"
38
20
  }
39
21
  tmpl.locked = true
40
- tmpl.save!(:validate => false) if tmpl.changes.present?
22
+ tmpl.organizations = Organization.unscoped.all if SETTINGS[:organizations_enabled]
23
+ tmpl.locations = Location.unscoped.all if SETTINGS[:locations_enabled]
24
+ tmpl.save!(validate: false) if tmpl.changes.present?
25
+ end
41
26
 
42
- ProvisioningTemplate.unscoped.where(:name => created, :default => true).each do |tmpl|
43
- tmpl.organizations = organizations if SETTINGS[:organizations_enabled]
44
- tmpl.locations = locations if SETTINGS[:locations_enabled]
45
- end
27
+ ProvisioningTemplate.without_auditing do
28
+ ensure_bootdisk_template("Boot disk iPXE - host", read_bootdisk_template("host.erb"))
29
+ ensure_bootdisk_template("Boot disk iPXE - generic host", read_bootdisk_template("generic_host.erb"))
30
+ ensure_bootdisk_template("Boot disk iPXE - generic static host", read_bootdisk_template("generic_static_host.erb"))
46
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_bootdisk/version'
2
4
  require 'foreman_bootdisk/engine'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_bootdisk'
2
4
  require 'fast_gettext'
3
5
  require 'gettext_i18n_rails'
@@ -15,49 +17,36 @@ module ForemanBootdisk
15
17
  app.routes_reloader.paths << "#{ForemanBootdisk::Engine.root}/config/routes/mount_engine.rb"
16
18
  end
17
19
 
18
- initializer 'foreman_bootdisk.load_default_settings', :before => :load_config_initializers do |app|
19
- require_dependency File.expand_path("../../../app/models/setting/bootdisk.rb", __FILE__) if (Setting.table_exists? rescue(false))
20
+ initializer 'foreman_bootdisk.load_default_settings', before: :load_config_initializers do |_app|
21
+ table_exists = begin
22
+ Setting.table_exists?
23
+ rescue StandardError
24
+ false
25
+ end
26
+ require_dependency File.expand_path('../../app/models/setting/bootdisk.rb', __dir__) if table_exists
20
27
  end
21
28
 
22
- initializer "foreman_bootdisk.load_app_instance_data" do |app|
29
+ initializer 'foreman_bootdisk.load_app_instance_data' do |app|
23
30
  ForemanBootdisk::Engine.paths['db/migrate'].existent.each do |path|
24
31
  app.config.paths['db/migrate'] << path
25
32
  end
26
33
  end
27
34
 
28
- initializer "foreman_bootdisk.apipie" do
35
+ initializer 'foreman_bootdisk.apipie' do
29
36
  Apipie.configuration.checksum_path += ['/bootdisk/api/']
30
37
  end
31
38
 
32
- # Precompile any JS or CSS files under app/assets/
33
- # If requiring files from each other, list them explicitly here to avoid precompiling the same
34
- # content twice.
35
- assets_to_precompile =
36
- Dir.chdir(root) do
37
- Dir['app/assets/javascripts/**/*', 'app/assets/stylesheets/**/*'].map do |f|
38
- f.split(File::SEPARATOR, 4).last
39
- end
40
- end
41
-
42
- initializer 'foreman_bootdisk.assets.precompile' do |app|
43
- app.config.assets.precompile += assets_to_precompile
44
- end
45
-
46
- initializer 'foreman_bootdisk.configure_assets', group: :assets do
47
- SETTINGS[:foreman_bootdisk] = { assets: { precompile: assets_to_precompile } }
48
- end
49
-
50
- initializer 'foreman_bootdisk.register_plugin', :before => :finisher_hook do |app|
39
+ initializer 'foreman_bootdisk.register_plugin', before: :finisher_hook do |_app|
51
40
  Foreman::Plugin.register :foreman_bootdisk do
52
- requires_foreman '>= 1.18'
41
+ requires_foreman '>= 1.24'
53
42
 
54
- security_block :bootdisk do |map|
55
- permission :download_bootdisk, {:'foreman_bootdisk/disks' => [:generic, :host, :full_host, :subnet, :help],
56
- :'foreman_bootdisk/api/v2/disks' => [:generic, :host],
57
- :'foreman_bootdisk/api/v2/subnet_disks' => [:subnet]}
43
+ security_block :bootdisk do |_map|
44
+ permission :download_bootdisk, 'foreman_bootdisk/disks': %i[generic host full_host subnet help],
45
+ 'foreman_bootdisk/api/v2/disks': %i[generic host],
46
+ 'foreman_bootdisk/api/v2/subnet_disks': [:subnet]
58
47
  end
59
48
 
60
- role "Boot disk access", [:download_bootdisk]
49
+ role 'Boot disk access', [:download_bootdisk], 'Role granting permissions to download bootdisks'
61
50
 
62
51
  add_all_permissions_to_default_roles
63
52
 
@@ -68,20 +57,20 @@ module ForemanBootdisk
68
57
  end
69
58
  end
70
59
 
71
- initializer 'foreman_bootdisk.register_gettext', :after => :load_config_initializers do |app|
72
- locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
60
+ initializer 'foreman_bootdisk.register_gettext', after: :load_config_initializers do |_app|
61
+ locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
73
62
  locale_domain = 'foreman_bootdisk'
74
63
  Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
75
64
  end
76
65
 
77
66
  config.to_prepare do
78
67
  begin
79
- Host::Managed.send(:prepend, ForemanBootdisk::HostExt)
80
- Host::Managed.send(:include, ForemanBootdisk::Orchestration::Compute) if SETTINGS[:unattended]
81
- HostsHelper.send(:prepend, ForemanBootdisk::HostsHelperExt)
82
- Foreman::Model::Vmware.send(:prepend, ForemanBootdisk::ComputeResources::Vmware) if Foreman::Model::Vmware.available?
83
- rescue => e
84
- puts "#{ForemanBootdisk::ENGINE_NAME}: skipping engine hook (#{e.to_s})"
68
+ Host::Managed.prepend ForemanBootdisk::HostExt
69
+ Host::Managed.include ForemanBootdisk::Orchestration::Compute if SETTINGS[:unattended]
70
+ HostsHelper.prepend ForemanBootdisk::HostsHelperExt
71
+ Foreman::Model::Vmware.prepend ForemanBootdisk::ComputeResources::Vmware if Foreman::Model::Vmware.available?
72
+ rescue StandardError => e
73
+ Rails.logger.warn "#{ForemanBootdisk::ENGINE_NAME}: skipping engine hook (#{e})"
85
74
  end
86
75
  end
87
76
  end