foreman_bootdisk 16.0.0 → 18.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yaml +19 -0
  3. data/.tx/config +1 -1
  4. data/AUTHORS +9 -1
  5. data/README.md +11 -3
  6. data/app/controllers/concerns/allowed_actions.rb +16 -0
  7. data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +15 -8
  8. data/app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb +16 -4
  9. data/app/controllers/foreman_bootdisk/disks_controller.rb +29 -23
  10. data/app/controllers/foreman_bootdisk/subnet_disks_controller.rb +41 -0
  11. data/app/helpers/bootdisk_links_helper.rb +46 -0
  12. data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +58 -44
  13. data/app/helpers/concerns/foreman_bootdisk/pretty_error.rb +13 -0
  14. data/app/helpers/concerns/foreman_bootdisk/subnets_helper_ext.rb +45 -0
  15. data/app/helpers/disk_helper.rb +8 -0
  16. data/app/lib/foreman_bootdisk/scope/bootdisk.rb +28 -1
  17. data/app/lib/foreman_bootdisk/scope/full_host_bootdisk_efi.rb +15 -0
  18. data/app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb +10 -1
  19. data/app/models/concerns/foreman_bootdisk/host_ext.rb +13 -6
  20. data/app/models/concerns/foreman_bootdisk/orchestration/compute.rb +38 -22
  21. data/app/models/setting/bootdisk.rb +14 -1
  22. data/app/services/foreman_bootdisk/iso_generator.rb +134 -56
  23. data/app/services/foreman_bootdisk/renderer.rb +36 -19
  24. data/app/views/foreman_bootdisk/disks/help.html.erb +16 -4
  25. data/app/views/foreman_bootdisk/generic_efi_host.erb +68 -0
  26. data/app/views/foreman_bootdisk/host.erb +7 -0
  27. data/app/views/subnets/_bootdisk_action_buttons.erb +1 -0
  28. data/app/views/subnets/_bootdisk_title_buttons.erb +1 -0
  29. data/config/routes.rb +1 -1
  30. data/db/seeds.d/50-bootdisk_templates.rb +1 -0
  31. data/lib/foreman_bootdisk/engine.rb +18 -8
  32. data/lib/foreman_bootdisk/version.rb +1 -1
  33. data/lib/tasks/bootdisk.rake +10 -24
  34. data/locale/action_names.rb +5 -0
  35. data/locale/ca/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  36. data/locale/ca/foreman_bootdisk.po +76 -13
  37. data/locale/de/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  38. data/locale/de/foreman_bootdisk.po +81 -18
  39. data/locale/en/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  40. data/locale/en/foreman_bootdisk.po +71 -8
  41. data/locale/en_GB/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  42. data/locale/en_GB/foreman_bootdisk.po +79 -16
  43. data/locale/es/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  44. data/locale/es/foreman_bootdisk.po +92 -28
  45. data/locale/foreman_bootdisk.pot +164 -71
  46. data/locale/fr/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  47. data/locale/fr/foreman_bootdisk.po +100 -36
  48. data/locale/it/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  49. data/locale/it/foreman_bootdisk.po +78 -15
  50. data/locale/ja/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  51. data/locale/ja/foreman_bootdisk.po +90 -26
  52. data/locale/ko/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  53. data/locale/ko/foreman_bootdisk.po +79 -16
  54. data/locale/pt_BR/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  55. data/locale/pt_BR/foreman_bootdisk.po +99 -36
  56. data/locale/ru/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  57. data/locale/ru/foreman_bootdisk.po +79 -16
  58. data/locale/sv_SE/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  59. data/locale/sv_SE/foreman_bootdisk.po +75 -12
  60. data/locale/zh_CN/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  61. data/locale/zh_CN/foreman_bootdisk.po +131 -68
  62. data/locale/zh_TW/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  63. data/locale/zh_TW/foreman_bootdisk.po +79 -16
  64. data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +51 -17
  65. data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +23 -10
  66. data/test/functional/foreman_bootdisk/disks_controller_test.rb +60 -30
  67. data/test/functional/foreman_bootdisk/subnet_disks_controller_test.rb +51 -0
  68. data/test/test_plugin_helper.rb +21 -3
  69. data/test/unit/concerns/host_test.rb +12 -1
  70. data/test/unit/concerns/orchestration/compute_test.rb +32 -13
  71. data/test/unit/foreman_bootdisk/renderer_test.rb +1 -1
  72. data/test/unit/iso_generator_test.rb +6 -7
  73. metadata +21 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a69fd6de3a18c8670dfe431cf989b8c02f94b9aa48da2c17aa93e504d98f869
4
- data.tar.gz: 7354aff9025bfdd9f1acd3e312b2350268866b108a534dc3143b99ff731de1b9
3
+ metadata.gz: 4fcb24387c278c94c7958d2555049002680e100e3b29c95d6593bb38970849ec
4
+ data.tar.gz: 82445ab3eab98f326a922ecae03937d2a323d5422cc1b4521d98f8a6cc11593a
5
5
  SHA512:
6
- metadata.gz: 1fe67673899bbaf6b8588103341bf6f8436aecc7d761e574f9c835940d530eb199bbc29c44a61234710abd7ec00a76e2e89dc7ecbcb17211a0c7ff5df27d8c16
7
- data.tar.gz: 70838f0a73b4c1541bc728de2f0399aa3946da0714e31b05d1dee08a7254aa6be8c1cd0a3b769dcfa566b21963fd9fb0591792e23758c6ceeb4885a1a2a3ff20
6
+ metadata.gz: fcb7c5f6975000d376ae1795b392b6583bee6179cccd0b1c1f3893aa6109cabc391cae7904a8dfb8f4235d6898d57c6ad0c13cd1bc52b97216a382b7f992f752
7
+ data.tar.gz: 8fc3266a6933ca5bfc0b3e32547bd28c26926000ad8220a39b907402d441f1f49e271b58fc0ac3de2bc59e3db925e98ea91f6114944960c45524882a8a04b880
@@ -0,0 +1,19 @@
1
+ name: Rubocop
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ rubocop:
7
+ runs-on: ubuntu-latest
8
+ env:
9
+ BUNDLE_FOREMAN: '0'
10
+ BUNDLE_WITHOUT: development:test
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Setup Ruby
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.5
17
+ bundler-cache: true
18
+ - name: Run rubocop
19
+ run: bundle exec rubocop -P --format github
data/.tx/config CHANGED
@@ -1,7 +1,7 @@
1
1
  [main]
2
2
  host = https://www.transifex.com
3
3
 
4
- [foreman.bootdisk]
4
+ [foreman.foreman_bootdisk]
5
5
  file_filter = locale/<lang>/foreman_bootdisk.edit.po
6
6
  source_file = locale/foreman_bootdisk.pot
7
7
  source_lang = en
data/AUTHORS CHANGED
@@ -1,20 +1,29 @@
1
+ Adam Ruzicka
2
+ Bernhard Suttner
1
3
  Bryan Kearney
4
+ crito
5
+ Damon Maria
2
6
  Dominic Cleal
7
+ Dominik Matoulek
3
8
  Greg Sutcliffe
4
9
  Ido Kanner
5
10
  Jon Fautley
6
11
  Justin Sherrill
12
+ Leos Stejskal
7
13
  Lukas Zapletal
8
14
  Lukáš Zapletal
9
15
  Marek Hulan
10
16
  Marek Hulán
17
+ Markus Bucher
11
18
  Martin Bačovský
12
19
  Michael Hofer
13
20
  Michael Moll
14
21
  Ohad Levy
22
+ Oleh Fedorenko
15
23
  Ondrej Prazak
16
24
  Ondřej Ezr
17
25
  Ondřej Pražák
26
+ Pat Riehecky
18
27
  Robert Antoni Buj Gelonch
19
28
  Rohan21Lobo
20
29
  Ronald van Zantvoort
@@ -23,4 +32,3 @@ Sean O'Keeffe
23
32
  Stephen Benjamin
24
33
  Swapnil Abnave
25
34
  Timo Goebel
26
- crito
data/README.md CHANGED
@@ -50,6 +50,10 @@ gPXE images are unsupported due to lack of initrd support.
50
50
  | >= 1.19 | ~> 13.0 |
51
51
  | >= 1.20 | ~> 14.0 |
52
52
  | >= 1.21 | ~> 15.0 |
53
+ | >= 1.23 | ~> 16.0 |
54
+ | >= 1.24 | ~> 16.1 |
55
+ | >= 2.0 | ~> 16.1 |
56
+ | >= 2.1 | ~> 17.0 |
53
57
 
54
58
  # Usage
55
59
 
@@ -119,6 +123,7 @@ TFTP settings are needed.
119
123
  <th>DHCP reservation</th>
120
124
  <th>Pre-register host</th>
121
125
  <th>OS-specific</th>
126
+ <th>EFI supported</th>
122
127
  </tr>
123
128
  <tr>
124
129
  <td>Per-host image</td>
@@ -127,6 +132,7 @@ TFTP settings are needed.
127
132
  <td>No</td>
128
133
  <td>Yes</td>
129
134
  <td>No</td>
135
+ <td>No</td>
130
136
  </tr>
131
137
  <tr>
132
138
  <td>Full host image</td>
@@ -135,6 +141,7 @@ TFTP settings are needed.
135
141
  <td>No</td>
136
142
  <td>Yes</td>
137
143
  <td>Yes</td>
144
+ <td>Yes</td>
138
145
  </tr>
139
146
  <tr>
140
147
  <td>Generic image</td>
@@ -143,6 +150,7 @@ TFTP settings are needed.
143
150
  <td>No</td>
144
151
  <td>Yes</td>
145
152
  <td>No</td>
153
+ <td>No</td>
146
154
  </tr>
147
155
  <tr>
148
156
  <td>Subnet image</td>
@@ -151,6 +159,7 @@ TFTP settings are needed.
151
159
  <td>No</td>
152
160
  <td>Yes</td>
153
161
  <td>No</td>
162
+ <td>Yes</td>
154
163
  </tr>
155
164
  </table>
156
165
 
@@ -219,7 +228,7 @@ The installation can continue on either the DHCP or static IP depending on how
219
228
  the OS iPXE template is configured, and could configure the assigned IP
220
229
  address statically for the installed system via the kickstart file.
221
230
 
222
- To generate the image from the web interface, view a host page, click the
231
+ To generate the image from the web interface, view a subnet page, click the
223
232
  "Boot disk" button and select "Generic image".
224
233
 
225
234
  To generate using the Hammer CLI, install the [hammer_cli_foreman_bootdisk](https://github.com/theforeman/hammer_cli_foreman_bootdisk)
@@ -260,8 +269,7 @@ the "Templates" module enabled and configured.
260
269
 
261
270
  This image is generic for all hosts with a provisioning NIC on that subnet.
262
271
 
263
- To generate the image from the web interface, view a host page, click the
264
- "Boot disk" button and select "Subnet image".
272
+ To generate the image from the web interface, view a subnet page and select "Subnet image" from subnet action buttons.
265
273
 
266
274
  To generate using the Hammer CLI, install the [hammer_cli_foreman_bootdisk](https://github.com/theforeman/hammer_cli_foreman_bootdisk)
267
275
  plugin and run:
@@ -0,0 +1,16 @@
1
+ module AllowedActions
2
+ extend ActiveSupport::Concern
3
+
4
+ def bootdisk_type_allowed?(action = params[:action])
5
+ return true if Setting::Bootdisk.allowed_types&.include?(action)
6
+
7
+ message = _('This type of bootdisk is not allowed. Please contact administrator.')
8
+ if api_request?
9
+ render_error :custom_error, status: :unprocessable_entity, locals: { message: message}
10
+ else
11
+ error(message)
12
+ redirect_back(fallback_location: '/')
13
+ end
14
+ false
15
+ end
16
+ end
@@ -7,11 +7,13 @@ module ForemanBootdisk
7
7
  module V2
8
8
  class DisksController < ::Api::V2::BaseController
9
9
  include ::Api::Version2
10
+ include AllowedActions
10
11
 
11
12
  resource_description do
12
13
  api_base_url '/bootdisk/api'
13
14
  end
14
15
 
16
+ before_action :bootdisk_type_allowed?, only: :generic
15
17
  before_action :find_resource, only: :host
16
18
  skip_after_action :log_response_body
17
19
 
@@ -21,9 +23,10 @@ module ForemanBootdisk
21
23
 
22
24
  api :GET, '/generic', N_('Download generic image')
23
25
  def generic
26
+ # EFI not supported for iPXE generic bootdisk
24
27
  tmpl = ForemanBootdisk::Renderer.new.generic_template_render
25
28
  ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
26
- send_data read_file(iso), filename: "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso"
29
+ send_file(iso, filename: "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso")
27
30
  end
28
31
  end
29
32
 
@@ -33,23 +36,27 @@ module ForemanBootdisk
33
36
  def host
34
37
  host = @disk
35
38
  if params[:full]
36
- ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
37
- send_data read_file(iso), filename: "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso"
39
+ return unless bootdisk_type_allowed?('full_host')
40
+ begin
41
+ ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
42
+ send_file(iso, filename: "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso")
43
+ end
44
+ rescue ::Foreman::Exception => e
45
+ raise e unless e.code == 'ERF42-2893'
46
+ render_error json: { error: _('Host is not in build mode')}, status: :method_not_allowed
38
47
  end
39
48
  else
49
+ return unless bootdisk_type_allowed?
50
+ # EFI not supported for iPXE host bootdisk
40
51
  tmpl = host.bootdisk_template_render
41
52
  ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
42
- send_data read_file(iso), filename: "#{host.name}.iso"
53
+ send_file(iso, filename: "#{host.name}.iso")
43
54
  end
44
55
  end
45
56
  end
46
57
 
47
58
  private
48
59
 
49
- def read_file(filename)
50
- File.read(filename)
51
- end
52
-
53
60
  def resource_scope
54
61
  Host::Managed.authorized('view_hosts')
55
62
  end
@@ -7,11 +7,14 @@ module ForemanBootdisk
7
7
  module V2
8
8
  class SubnetDisksController < ::Api::V2::BaseController
9
9
  include ::Api::Version2
10
+ include AllowedActions
10
11
 
11
12
  resource_description do
12
13
  api_base_url '/bootdisk/api'
13
14
  end
14
15
 
16
+ rescue_from ActiveRecord::RecordNotFound, :with => :subnet_not_found
17
+ before_action :bootdisk_type_allowed?, only: :subnet
15
18
  before_action :find_resource, only: :subnet
16
19
 
17
20
  skip_after_action :log_response_body
@@ -25,10 +28,15 @@ module ForemanBootdisk
25
28
  def subnet
26
29
  subnet = @subnet_disk
27
30
  subnet.tftp || raise(::Foreman::Exception.new(N_('TFTP feature not enabled for subnet %s'), subnet.name))
28
- tmpl = ForemanBootdisk::Renderer.new.generic_template_render(subnet)
29
- ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
30
- name = subnet.name
31
- send_data File.read(iso), filename: "bootdisk_subnet_#{name}.iso"
31
+ tmpl_bios = ForemanBootdisk::Renderer.new.generic_template_render(subnet)
32
+ tmpl_efi = nil
33
+ if subnet.httpboot
34
+ tmpl_efi = ForemanBootdisk::Renderer.new.generic_efi_template_render(subnet)
35
+ else
36
+ ForemanBootdisk.logger.warn('HTTPBOOT feature is not enabled for subnet %s, UEFI may not be available for bootdisk' % subnet.name)
37
+ end
38
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl_bios, grub: tmpl_efi) do |temp_iso_filename|
39
+ send_file(temp_iso_filename, filename: subnet.name)
32
40
  end
33
41
  end
34
42
 
@@ -37,6 +45,10 @@ module ForemanBootdisk
37
45
  def resource_scope
38
46
  Subnet.authorized('view_subnets')
39
47
  end
48
+
49
+ def subnet_not_found
50
+ not_found ("Subnet not found by id '%s'") % params[:id]
51
+ end
40
52
  end
41
53
  end
42
54
  end
@@ -4,7 +4,14 @@ require 'uri'
4
4
 
5
5
  module ForemanBootdisk
6
6
  class DisksController < ::ApplicationController
7
- before_action :find_resource, only: %w[host full_host subnet]
7
+ include AllowedActions
8
+ include PrettyError
9
+
10
+ helper DiskHelper
11
+
12
+ before_action :bootdisk_type_allowed?, except: :help
13
+
14
+ before_action :find_resource, only: %w[host full_host]
8
15
 
9
16
  # as this engine is isolated, we need to include url helpers from core explicitly
10
17
  # to render help page layout
@@ -12,6 +19,7 @@ module ForemanBootdisk
12
19
 
13
20
  def generic
14
21
  begin
22
+ # EFI not supported for iPXE generic bootdisk
15
23
  tmpl = ForemanBootdisk::Renderer.new.generic_template_render
16
24
  rescue StandardError => e
17
25
  error_rendering(e)
@@ -20,13 +28,14 @@ module ForemanBootdisk
20
28
  end
21
29
 
22
30
  ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
23
- send_data read_file(iso), filename: "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso"
31
+ send_file(iso, filename: "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso")
24
32
  end
25
33
  end
26
34
 
27
35
  def host
28
36
  host = @disk
29
37
  begin
38
+ # EFI not supported for iPXE host bootdisk
30
39
  tmpl = host.bootdisk_template_render
31
40
  rescue StandardError => e
32
41
  error_rendering(e)
@@ -34,32 +43,25 @@ module ForemanBootdisk
34
43
  return
35
44
  end
36
45
 
46
+ prolong_token(host)
47
+
37
48
  ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
38
- send_data read_file(iso), filename: "#{host.name}.iso"
49
+ send_file(iso, filename: "#{host.name}.iso")
39
50
  end
40
51
  end
41
52
 
42
53
  def full_host
43
54
  host = @disk
44
- ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
45
- send_data read_file(iso), filename: "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso"
46
- end
47
- end
48
55
 
49
- def subnet
50
- host = @disk
56
+ prolong_token(host)
51
57
  begin
52
- subnet = host.try(:subnet) || raise(::Foreman::Exception.new(N_('Subnet is not assigned to the host %s'), host.name))
53
- subnet.tftp || raise(::Foreman::Exception.new(N_('TFTP feature not enabled for subnet %s'), subnet.name))
54
- tmpl = ForemanBootdisk::Renderer.new.generic_template_render(subnet)
55
- rescue StandardError => e
56
- error_rendering(e)
58
+ ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
59
+ send_file(iso, filename: "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso")
60
+ end
61
+ rescue ::Foreman::Exception => e
62
+ raise e unless e.code == 'ERF42-2893'
63
+ error _('Host is not in build mode.')
57
64
  redirect_back(fallback_location: '/')
58
- return
59
- end
60
-
61
- ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
62
- send_data read_file(iso), filename: "bootdisk_subnet_#{subnet.name}.iso"
63
65
  end
64
66
  end
65
67
 
@@ -67,10 +69,6 @@ module ForemanBootdisk
67
69
 
68
70
  private
69
71
 
70
- def read_file(filename)
71
- File.read(filename)
72
- end
73
-
74
72
  def resource_scope(_controller = controller_name)
75
73
  Host::Managed.authorized(:view_hosts)
76
74
  end
@@ -80,5 +78,13 @@ module ForemanBootdisk
80
78
  error("#{msg}: #{exception.message}")
81
79
  ::Foreman::Logging.exception(msg, exception)
82
80
  end
81
+
82
+ def prolong_token(host)
83
+ return if Setting[:token_duration] == 0 || host.token.nil?
84
+
85
+ # update build token
86
+ token = host.token
87
+ token.update(expires: Time.zone.now + Setting[:token_duration].minutes)
88
+ end
83
89
  end
84
90
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanBootdisk
4
+ class SubnetDisksController < ::ApplicationController
5
+ include PrettyError
6
+
7
+ before_action :find_resource, only: :subnet
8
+
9
+ # as this engine is isolated, we need to include url helpers from core explicitly
10
+ # to render help page layout
11
+ include Rails.application.routes.url_helpers
12
+
13
+ def subnet
14
+ begin
15
+ @subnet.tftp || raise(::Foreman::Exception.new(N_('TFTP feature not enabled for subnet %s'), @subnet.name))
16
+ @subnet.httpboot || ForemanBootdisk.logger.warn('HTTPBOOT feature is not enabled for subnet %s, UEFI may not be available for bootdisk' % @subnet.name)
17
+
18
+ tmpl_bios = ForemanBootdisk::Renderer.new.generic_template_render(@subnet)
19
+ tmpl_efi = ForemanBootdisk::Renderer.new.generic_efi_template_render(@subnet)
20
+ rescue StandardError => e
21
+ error_rendering(e)
22
+ redirect_back(fallback_location: '/')
23
+ return
24
+ end
25
+
26
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl_bios, grub: tmpl_efi) do |iso|
27
+ send_file(iso, filename: "bootdisk_subnet_#{@subnet.name}.iso")
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def resource_scope(_controller = controller_name)
34
+ Subnet.authorized(:view_subnets)
35
+ end
36
+
37
+ def find_resource
38
+ @subnet = Subnet.find(params[:id])
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BootdiskLinksHelper
4
+ # Core Foreman helpers can't look up a URL against a mounted engine
5
+ def display_bootdisk_link_if_authorized(name, options = {}, html_options = {})
6
+ if bootdisk_authorized_for(options)
7
+ link_to(name, bootdisk_url(options), html_options)
8
+ else
9
+ ''
10
+ end
11
+ end
12
+
13
+ def bootdisk_url(options)
14
+ ForemanBootdisk::Engine.routes.url_for(options.merge(only_path: true, script_name: foreman_bootdisk_path))
15
+ end
16
+
17
+ def bootdisk_authorized_for(options)
18
+ User.current.allowed_to?(options)
19
+ end
20
+
21
+ def divider
22
+ tag(:li, class: 'divider')
23
+ end
24
+
25
+ def bootdisk_help_link
26
+ display_bootdisk_link_if_authorized(
27
+ _('Boot disk Help'),
28
+ {
29
+ controller: 'foreman_bootdisk/disks',
30
+ action: 'help'
31
+ },
32
+ class: 'la'
33
+ )
34
+ end
35
+
36
+ def bootdisk_title_action_buttons(actions)
37
+ title_actions(
38
+ button_group(
39
+ select_action_button(
40
+ _('Boot disk'), { class: 'btn btn-group' },
41
+ actions
42
+ )
43
+ )
44
+ )
45
+ end
46
+ end
@@ -2,51 +2,11 @@
2
2
 
3
3
  module ForemanBootdisk
4
4
  module HostsHelperExt
5
+ include BootdiskLinksHelper
6
+
5
7
  def host_title_actions(host)
6
8
  if host.bootdisk_downloadable?
7
- title_actions(
8
- button_group(
9
- select_action_button(
10
- _('Boot disk'), { class: 'btn btn-group' },
11
- display_bootdisk_link_if_authorized(
12
- _("Host '%s' image") % host.name.split('.')[0],
13
- {
14
- controller: 'foreman_bootdisk/disks',
15
- action: 'host',
16
- id: host
17
- },
18
- class: 'la'
19
- ),
20
- display_bootdisk_link_if_authorized(
21
- _("Full host '%s' image") % host.name.split('.')[0],
22
- {
23
- controller: 'foreman_bootdisk/disks',
24
- action: 'full_host',
25
- id: host
26
- },
27
- class: 'la'
28
- ),
29
- content_tag(:li, '', class: 'divider'),
30
- display_bootdisk_link_if_authorized(
31
- _('Generic image'),
32
- {
33
- controller: 'foreman_bootdisk/disks',
34
- action: 'generic'
35
- },
36
- class: 'la'
37
- ),
38
- display_bootdisk_for_subnet(host),
39
- content_tag(:li, '', class: 'divider'),
40
- display_bootdisk_link_if_authorized(
41
- _('Help'), {
42
- controller: 'foreman_bootdisk/disks',
43
- action: 'help'
44
- },
45
- class: 'la'
46
- )
47
- )
48
- )
49
- )
9
+ bootdisk_title_action_buttons(host_action_buttons(host))
50
10
  else
51
11
  bootdisk_button_disabled(host)
52
12
  end
@@ -65,7 +25,7 @@ module ForemanBootdisk
65
25
 
66
26
  # need to wrap this one in a test for template proxy presence
67
27
  def display_bootdisk_for_subnet(host)
68
- if (proxy = host.try(:subnet).try(:tftp)) && proxy.has_feature?('Templates')
28
+ if (proxy = host.try(:subnet).try(:tftp) || host.try(:subnet).try(:httpboot)) && proxy.has_feature?('Templates')
69
29
  display_bootdisk_link_if_authorized(
70
30
  _("Subnet '%s' generic image") % host.subnet.name, {
71
31
  controller: 'foreman_bootdisk/disks',
@@ -95,5 +55,59 @@ module ForemanBootdisk
95
55
  def bootdisk_authorized_for(options)
96
56
  User.current.allowed_to?(options)
97
57
  end
58
+
59
+ def host_action_buttons(host)
60
+ actions = []
61
+
62
+ allowed_actions = Setting::Bootdisk.allowed_types
63
+ return '' unless allowed_actions
64
+
65
+ host_image_link = display_bootdisk_link_if_authorized(
66
+ _("Host '%s' image") % host.name.split('.')[0],
67
+ {
68
+ controller: 'foreman_bootdisk/disks',
69
+ action: 'host',
70
+ id: host
71
+ },
72
+ class: 'la'
73
+ )
74
+
75
+ full_host_image_link = display_bootdisk_link_if_authorized(
76
+ _("Full host '%s' image") % host.name.split('.')[0],
77
+ {
78
+ controller: 'foreman_bootdisk/disks',
79
+ action: 'full_host',
80
+ id: host
81
+ },
82
+ class: 'la'
83
+ )
84
+
85
+ full_host_blind_link = if bootdisk_authorized_for({controller: 'foreman_bootdisk/disks', action: 'full_host', id: host})
86
+ link_to(_("Full host '%s' image") % host.name.split('.')[0],
87
+ '#',
88
+ class: 'la btn btn-info',
89
+ disabled: true,
90
+ title: _('Host is not in build mode')
91
+ )
92
+ else
93
+ ''
94
+ end
95
+
96
+ actions << host_image_link if allowed_actions.include?('host')
97
+ if allowed_actions.include?('full_host')
98
+ if host.build?
99
+ actions << full_host_image_link
100
+ else
101
+ actions << full_host_blind_link
102
+ end
103
+ end
104
+
105
+
106
+ actions << divider if (host_image_link.present? && allowed_actions.include?('host')) || (full_host_image_link.present? && allowed_actions.include?('full_host'))
107
+
108
+ actions << bootdisk_help_link
109
+
110
+ actions
111
+ end
98
112
  end
99
113
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanBootdisk
4
+ module PrettyError
5
+ extend ActiveSupport::Concern
6
+
7
+ def error_rendering(exception)
8
+ msg = _('Failed to render boot disk template')
9
+ error("#{msg}: #{exception.message}")
10
+ ::Foreman::Logging.exception(msg, exception)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanBootdisk
4
+ module SubnetsHelperExt
5
+ include BootdiskLinksHelper
6
+
7
+ def display_bootdisk_for_subnet(subnet)
8
+ if (proxy = subnet.tftp || subnet.httpboot) && proxy.has_feature?('Templates') && Setting::Bootdisk.allowed_types.include?('subnet')
9
+ display_bootdisk_link_if_authorized(
10
+ _("Subnet generic image"), {
11
+ controller: 'foreman_bootdisk/subnet_disks',
12
+ action: 'subnet',
13
+ id: subnet.id
14
+ },
15
+ class: 'la'
16
+ )
17
+ else
18
+ ''
19
+ end
20
+ end
21
+
22
+ def display_bootdisk_title_buttons
23
+
24
+ actions = []
25
+
26
+ generic_image_link = display_bootdisk_link_if_authorized(
27
+ _('Generic image'),
28
+ {
29
+ controller: 'foreman_bootdisk/disks',
30
+ action: 'generic'
31
+ },
32
+ class: 'la'
33
+ )
34
+
35
+ if Setting::Bootdisk.allowed_types&.include?('generic')
36
+ actions << generic_image_link
37
+ actions << divider
38
+ end
39
+
40
+ actions << bootdisk_help_link
41
+
42
+ bootdisk_title_action_buttons(actions)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DiskHelper
4
+ def mark_disabled_bootdisk_type(type)
5
+ return '' if Setting::Bootdisk.allowed_types&.include?(type)
6
+ '*'
7
+ end
8
+ end