foreman_bootdisk 17.1.0 → 19.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -3
  3. data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +7 -2
  4. data/app/controllers/foreman_bootdisk/disks_controller.rb +70 -21
  5. data/app/controllers/foreman_bootdisk/subnet_disks_controller.rb +41 -0
  6. data/app/helpers/bootdisk_links_helper.rb +46 -0
  7. data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +30 -42
  8. data/app/helpers/concerns/foreman_bootdisk/pretty_error.rb +13 -0
  9. data/app/helpers/concerns/foreman_bootdisk/subnets_helper_ext.rb +45 -0
  10. data/app/helpers/disk_helper.rb +8 -0
  11. data/app/views/foreman_bootdisk/disks/help.html.erb +16 -4
  12. data/app/views/subnets/_bootdisk_action_buttons.erb +1 -0
  13. data/app/views/subnets/_bootdisk_title_buttons.erb +1 -0
  14. data/config/routes.rb +2 -1
  15. data/db/migrate/20140522185700_change_templatekind_to_bootdisk.rb +3 -3
  16. data/lib/foreman_bootdisk/engine.rb +11 -2
  17. data/lib/foreman_bootdisk/version.rb +1 -1
  18. data/locale/action_names.rb +2 -4
  19. data/locale/ca/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  20. data/locale/ca/foreman_bootdisk.edit.po +393 -0
  21. data/locale/ca/foreman_bootdisk.po +47 -11
  22. data/locale/ca/foreman_bootdisk.po.time_stamp +0 -0
  23. data/locale/de/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  24. data/locale/de/foreman_bootdisk.edit.po +398 -0
  25. data/locale/de/foreman_bootdisk.po +63 -26
  26. data/locale/de/foreman_bootdisk.po.time_stamp +0 -0
  27. data/locale/en/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  28. data/locale/en/foreman_bootdisk.edit.po +388 -0
  29. data/locale/en/foreman_bootdisk.po +45 -9
  30. data/locale/en/foreman_bootdisk.po.time_stamp +0 -0
  31. data/locale/en_GB/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  32. data/locale/en_GB/foreman_bootdisk.edit.po +394 -0
  33. data/locale/en_GB/foreman_bootdisk.po +47 -11
  34. data/locale/en_GB/foreman_bootdisk.po.time_stamp +0 -0
  35. data/locale/es/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  36. data/locale/es/foreman_bootdisk.edit.po +394 -0
  37. data/locale/es/foreman_bootdisk.po +69 -32
  38. data/locale/es/foreman_bootdisk.po.time_stamp +0 -0
  39. data/locale/foreman_bootdisk.pot +121 -63
  40. data/locale/fr/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  41. data/locale/fr/foreman_bootdisk.edit.po +394 -0
  42. data/locale/fr/foreman_bootdisk.po +80 -43
  43. data/locale/fr/foreman_bootdisk.po.time_stamp +0 -0
  44. data/locale/it/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  45. data/locale/it/foreman_bootdisk.edit.po +391 -0
  46. data/locale/it/foreman_bootdisk.po +47 -11
  47. data/locale/it/foreman_bootdisk.po.time_stamp +0 -0
  48. data/locale/ja/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  49. data/locale/ja/foreman_bootdisk.edit.po +393 -0
  50. data/locale/ja/foreman_bootdisk.po +70 -33
  51. data/locale/ja/foreman_bootdisk.po.time_stamp +0 -0
  52. data/locale/ko/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  53. data/locale/ko/foreman_bootdisk.edit.po +390 -0
  54. data/locale/ko/foreman_bootdisk.po +47 -11
  55. data/locale/ko/foreman_bootdisk.po.time_stamp +0 -0
  56. data/locale/pt_BR/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  57. data/locale/pt_BR/foreman_bootdisk.edit.po +394 -0
  58. data/locale/pt_BR/foreman_bootdisk.po +79 -43
  59. data/locale/pt_BR/foreman_bootdisk.po.time_stamp +0 -0
  60. data/locale/ru/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  61. data/locale/ru/foreman_bootdisk.edit.po +395 -0
  62. data/locale/ru/foreman_bootdisk.po +47 -11
  63. data/locale/ru/foreman_bootdisk.po.time_stamp +0 -0
  64. data/locale/sv_SE/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  65. data/locale/sv_SE/foreman_bootdisk.edit.po +392 -0
  66. data/locale/sv_SE/foreman_bootdisk.po +47 -11
  67. data/locale/sv_SE/foreman_bootdisk.po.time_stamp +0 -0
  68. data/locale/zh_CN/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  69. data/locale/zh_CN/foreman_bootdisk.edit.po +391 -0
  70. data/locale/zh_CN/foreman_bootdisk.po +113 -77
  71. data/locale/zh_CN/foreman_bootdisk.po.time_stamp +0 -0
  72. data/locale/zh_TW/LC_MESSAGES/foreman_bootdisk.mo +0 -0
  73. data/locale/zh_TW/foreman_bootdisk.edit.po +391 -0
  74. data/locale/zh_TW/foreman_bootdisk.po +47 -11
  75. data/locale/zh_TW/foreman_bootdisk.po.time_stamp +0 -0
  76. data/package.json +42 -0
  77. data/webpack/__mocks__/foremanReact/common/HOC.js +30 -0
  78. data/webpack/__mocks__/foremanReact/common/I18n.js +7 -0
  79. data/webpack/__mocks__/foremanReact/common/helpers.js +7 -0
  80. data/webpack/__mocks__/foremanReact/common/urlHelpers.js +8 -0
  81. data/webpack/__mocks__/foremanReact/constants.js +24 -0
  82. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +6 -0
  83. data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
  84. data/webpack/global_index.js +12 -0
  85. data/webpack/global_test_setup.js +11 -0
  86. data/webpack/index.js +0 -0
  87. data/webpack/src/extensions/constants.js +2 -0
  88. data/webpack/src/extensions/host/HostBootdiskButtons.js +71 -0
  89. data/webpack/src/extensions/host/HostBootdiskButtonsSelectors.js +27 -0
  90. data/webpack/src/extensions/host/__tests__/HostBootdiskButtonsSelectors.test.js +66 -0
  91. data/webpack/src/extensions/host/__tests__/__snapshots__/HostBootdiskButtonsSelectors.test.js.snap +30 -0
  92. metadata +54 -20
  93. data/.github/workflows/rubocop.yaml +0 -19
  94. data/.tx/config +0 -8
  95. data/AUTHORS +0 -34
  96. data/release-gem +0 -84
  97. data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +0 -97
  98. data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +0 -37
  99. data/test/functional/foreman_bootdisk/disks_controller_test.rb +0 -107
  100. data/test/models/host/managed_test.rb +0 -26
  101. data/test/test_plugin_helper.rb +0 -72
  102. data/test/unit/access_permissions_test.rb +0 -10
  103. data/test/unit/concerns/compute_resources/vmware_test.rb +0 -83
  104. data/test/unit/concerns/host_test.rb +0 -84
  105. data/test/unit/concerns/orchestration/compute_test.rb +0 -69
  106. data/test/unit/foreman_bootdisk/renderer_test.rb +0 -36
  107. data/test/unit/foreman_bootdisk/scope/bootdisk_test.rb +0 -31
  108. data/test/unit/foreman_bootdisk/scope/full_host_bootdisk_test.rb +0 -30
  109. data/test/unit/iso_generator_test.rb +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca80bb43629c291c9d6b27bb8c94ebd10fcc2e6e267378e4852ab42bdcee0088
4
- data.tar.gz: 743d4a31beef4d80d6ab5b025cf6261bbbb11cb62eb82b65d8f7c5aaed58c9fb
3
+ metadata.gz: c39668300d2a5a68390be2bda58d3559441a09d1b25e1b7d061bde4231ee7e9c
4
+ data.tar.gz: 4068117bc381e9014aaa52d0b7ebb773d356c3307b2a08ec66a633b5455b22e1
5
5
  SHA512:
6
- metadata.gz: 1915d2f7f01f58ec795f343707fe7a6d24f49af0ce6fb6ee9577f3279749e74f5cfb74b7ee707f3eea0e972b92344bc7d10a30f7be9556bffe8be2a39315526d
7
- data.tar.gz: b21943b356b209d60ad7cd1bc655a81c042ef93534fb94f719c271688f64f42a2f2ea3ba21a10280b388861fd061d1e08df498de216dc233f27a92e10065c942
6
+ metadata.gz: a1b23054266e36961e187c1013a4d0efa63adb4a66b93cdfc23cb93796c41fe3cccc5f77cad15ede3023a26a7d99c28c2ab14c144ea661be0b4d800a8df82ebc
7
+ data.tar.gz: 5a55ed870b9c65bf6019695e1562fc28bf50672ef523d87170979374d5baed59d47c3be55e29fb177c88a44bfab5a7978f79f2482985c4f8fcd7e197c0b2060b
data/README.md CHANGED
@@ -228,7 +228,7 @@ The installation can continue on either the DHCP or static IP depending on how
228
228
  the OS iPXE template is configured, and could configure the assigned IP
229
229
  address statically for the installed system via the kickstart file.
230
230
 
231
- 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
232
232
  "Boot disk" button and select "Generic image".
233
233
 
234
234
  To generate using the Hammer CLI, install the [hammer_cli_foreman_bootdisk](https://github.com/theforeman/hammer_cli_foreman_bootdisk)
@@ -269,8 +269,7 @@ the "Templates" module enabled and configured.
269
269
 
270
270
  This image is generic for all hosts with a provisioning NIC on that subnet.
271
271
 
272
- To generate the image from the web interface, view a host page, click the
273
- "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.
274
273
 
275
274
  To generate using the Hammer CLI, install the [hammer_cli_foreman_bootdisk](https://github.com/theforeman/hammer_cli_foreman_bootdisk)
276
275
  plugin and run:
@@ -37,8 +37,13 @@ module ForemanBootdisk
37
37
  host = @disk
38
38
  if params[:full]
39
39
  return unless bootdisk_type_allowed?('full_host')
40
- ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
41
- send_file(iso, filename: "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso")
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
42
47
  end
43
48
  else
44
49
  return unless bootdisk_type_allowed?
@@ -5,9 +5,13 @@ require 'uri'
5
5
  module ForemanBootdisk
6
6
  class DisksController < ::ApplicationController
7
7
  include AllowedActions
8
+ include PrettyError
8
9
 
9
- before_action :bootdisk_type_allowed?, except: :help
10
- before_action :find_resource, only: %w[host full_host subnet]
10
+ helper DiskHelper
11
+
12
+ before_action :bootdisk_type_allowed?, except: %i[help bootdisk_options]
13
+
14
+ before_action :find_resource, only: %w[host full_host bootdisk_options]
11
15
 
12
16
  # as this engine is isolated, we need to include url helpers from core explicitly
13
17
  # to render help page layout
@@ -39,6 +43,8 @@ module ForemanBootdisk
39
43
  return
40
44
  end
41
45
 
46
+ prolong_token(host)
47
+
42
48
  ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
43
49
  send_file(iso, filename: "#{host.name}.iso")
44
50
  end
@@ -46,33 +52,39 @@ module ForemanBootdisk
46
52
 
47
53
  def full_host
48
54
  host = @disk
49
- ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
50
- send_file(iso, filename: "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso")
51
- end
52
- end
53
55
 
54
- def subnet
55
- host = @disk
56
+ prolong_token(host)
56
57
  begin
57
- subnet = host.try(:subnet) || raise(::Foreman::Exception.new(N_('Subnet is not assigned to the host %s'), host.name))
58
- subnet.tftp || raise(::Foreman::Exception.new(N_('TFTP feature not enabled for subnet %s'), subnet.name))
59
- subnet.httpboot || ForemanBootdisk.logger.warn('HTTPBOOT feature is not enabled for subnet %s, UEFI may not be available for bootdisk' % subnet.name)
60
-
61
- tmpl_bios = ForemanBootdisk::Renderer.new.generic_template_render(subnet)
62
- tmpl_efi = ForemanBootdisk::Renderer.new.generic_efi_template_render(subnet)
63
- rescue StandardError => e
64
- 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.')
65
64
  redirect_back(fallback_location: '/')
66
- return
67
- end
68
-
69
- ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl_bios, grub: tmpl_efi) do |iso|
70
- send_file(iso, filename: "bootdisk_subnet_#{subnet.name}.iso")
71
65
  end
72
66
  end
73
67
 
74
68
  def help; end
75
69
 
70
+ def bootdisk_options
71
+ host = @disk
72
+
73
+ return not_found unless host
74
+
75
+ respond_to do |format|
76
+ format.json do
77
+ render json: {
78
+ bootdiskOptions: {
79
+ bootdiskDownloadable: !!host&.bootdisk_downloadable?,
80
+ architectureName: host&.architecture&.name,
81
+ actions: bootdisk_allowed_actions(host),
82
+ },
83
+ }, status: :ok
84
+ end
85
+ end
86
+ end
87
+
76
88
  private
77
89
 
78
90
  def resource_scope(_controller = controller_name)
@@ -84,5 +96,42 @@ module ForemanBootdisk
84
96
  error("#{msg}: #{exception.message}")
85
97
  ::Foreman::Logging.exception(msg, exception)
86
98
  end
99
+
100
+ def prolong_token(host)
101
+ return if Setting[:token_duration] == 0 || host.token.nil?
102
+
103
+ # update build token
104
+ token = host.token
105
+ token.update(expires: Time.zone.now + Setting[:token_duration].minutes)
106
+ end
107
+
108
+ def bootdisk_allowed_actions(host)
109
+ return [] unless host&.bootdisk_downloadable?
110
+
111
+ allowed = %w[host full_host].each_with_object([]) do |action, actions|
112
+ opts = {
113
+ controller: 'foreman_bootdisk/disks',
114
+ action: action,
115
+ id: host
116
+ }
117
+ next unless User.current.allowed_to?(opts) && Setting::Bootdisk.allowed_types.include?(action)
118
+
119
+ hostname = host.name.split('.')[0]
120
+ title = action == 'host' ? _("Host '%s' image") % hostname : _("Full host '%s' image") % hostname
121
+ disable_full_host = action == 'full_host' && !host.build?
122
+ actions << {
123
+ title: title,
124
+ link: "/bootdisk/disks/#{action}s/#{host.id}",
125
+ disabled: disable_full_host ? true : false,
126
+ description: disable_full_host ? _('Host is not in build mode') : nil
127
+ }
128
+ end
129
+ return allowed unless User.current.allowed_to?({controller: 'foreman_bootdisk/disks', action: 'help'})
130
+
131
+ allowed.push({
132
+ title: _('Boot disk help'),
133
+ link: '/bootdisk/disks/help'
134
+ })
135
+ end
87
136
  end
88
137
  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,16 +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
- host_action_buttons(host)
12
- )
13
- )
14
- )
9
+ bootdisk_title_action_buttons(host_action_buttons(host))
15
10
  else
16
11
  bootdisk_button_disabled(host)
17
12
  end
@@ -69,55 +64,48 @@ module ForemanBootdisk
69
64
 
70
65
  host_image_link = display_bootdisk_link_if_authorized(
71
66
  _("Host '%s' image") % host.name.split('.')[0],
72
- {
73
- controller: 'foreman_bootdisk/disks',
74
- action: 'host',
75
- id: host
67
+ {
68
+ controller: 'foreman_bootdisk/disks',
69
+ action: 'host',
70
+ id: host
76
71
  },
77
72
  class: 'la'
78
73
  )
79
74
 
80
75
  full_host_image_link = display_bootdisk_link_if_authorized(
81
76
  _("Full host '%s' image") % host.name.split('.')[0],
82
- {
83
- controller: 'foreman_bootdisk/disks',
84
- action: 'full_host',
85
- id: host
77
+ {
78
+ controller: 'foreman_bootdisk/disks',
79
+ action: 'full_host',
80
+ id: host
86
81
  },
87
82
  class: 'la'
88
83
  )
89
84
 
90
- generic_image_link = display_bootdisk_link_if_authorized(
91
- _('Generic image'),
92
- {
93
- controller: 'foreman_bootdisk/disks',
94
- action: 'generic'
95
- },
96
- class: 'la'
97
- )
98
-
99
- help_link = display_bootdisk_link_if_authorized(
100
- _('Help'),
101
- {
102
- controller: 'foreman_bootdisk/disks',
103
- action: 'help'
104
- },
105
- class: 'la'
106
- )
107
-
108
- divider = tag(:li, '', class: 'divider')
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
109
95
 
110
96
  actions << host_image_link if allowed_actions.include?('host')
111
- actions << full_host_image_link if allowed_actions.include?('full_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
112
104
 
113
- subnet_link = display_bootdisk_for_subnet(host)
114
- actions << divider if allowed_actions.include?('generic') || (allowed_actions.include?('subnet') && subnet_link.present?)
115
105
 
116
- actions << generic_image_link if allowed_actions.include?('generic')
117
- actions << subnet_link if allowed_actions.include?('subnet')
106
+ actions << divider if (host_image_link.present? && allowed_actions.include?('host')) || (full_host_image_link.present? && allowed_actions.include?('full_host'))
118
107
 
119
- actions << divider
120
- actions << help_link
108
+ actions << bootdisk_help_link
121
109
 
122
110
  actions
123
111
  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
@@ -9,7 +9,12 @@
9
9
  <%= _('All images are usable as either ISOs or as disk images, including being written to a USB disk with `dd`.') %>
10
10
  </p>
11
11
 
12
- <h2><%= _('Host image') %></h2>
12
+ <h2><%= _('Host images') %></h2>
13
+ <p>
14
+ <%= _('These images are used for host. You can find them at host detail page.') %>
15
+ </p>
16
+
17
+ <h3><%= _('Host image') %><%= mark_disabled_bootdisk_type('host') %></h3>
13
18
  <p>
14
19
  <%= _("Per-host images contain data about a particular host registered in Foreman and set up fully static networking, avoiding the requirement for DHCP. After networking is configured, they chainload from Foreman, picking up the current OS configuration and build state from the server.") %>
15
20
  </p>
@@ -17,12 +22,17 @@
17
22
  <%= _("Once chainloaded, the OS bootloader and installer are downloaded directly from the installation media configured in Foreman, and the provisioning script (kickstart/preseed) is downloaded from Foreman.") %>
18
23
  </p>
19
24
 
20
- <h2><%= _('Full host image') %></h2>
25
+ <h3><%= _('Full host image') %><%= mark_disabled_bootdisk_type('full_host') %></h3>
21
26
  <p>
22
27
  <%= _('A variant of the per-host image which contains the OS bootloader embedded inside the disk. This may be useful if chainloading fails on certain hardware, but has the downside that the image must be regenerated for any change in the OS, bootloader or PXELinux templates.') %>
23
28
  </p>
24
29
 
25
- <h2><%= _('Generic image') %></h2>
30
+ <h2><%= _('Generic images') %></h2>
31
+ <p>
32
+ <%= _('These images are more generic than previous images. You can find them at subnet index page.') %>
33
+ </p>
34
+
35
+ <h3><%= _('Generic image') %><%= mark_disabled_bootdisk_type('generic') %></h3>
26
36
  <p>
27
37
  <%= _('Generic images are a reusable disk image that works for any host registered in Foreman. It requires a basic DHCP and DNS service to function and contact the server, but does not require DHCP reservations or static IP addresses.') %>
28
38
  </p>
@@ -30,11 +40,13 @@
30
40
  <%= _('The OS install continues using the installation media configured in Foreman, and it will typically configure static networking, depending on how the OS iPXE template is configured.') %>
31
41
  </p>
32
42
 
33
- <h2><%= _('Subnet image') %></h2>
43
+ <h3><%= _('Subnet image') %><%= mark_disabled_bootdisk_type('subnet') %></h3>
34
44
  <p>
35
45
  <%= _('Subnet images are similar to generic images, but chain-loading is done via the TFTP Smart Proxy assigned to the Subnet of the host. The smart proxy must have the "Templates" module enabled and configured.') %>
36
46
  </p>
37
47
  <p>
38
48
  <%= _('This image is generic for all hosts with a provisioning NIC on that subnet.') %>
39
49
  </p>
50
+
51
+ <p><%= _('* - These bootdisk types were disabled, you can enable them in Administer - Settings.') %></p>
40
52
  </div>
@@ -0,0 +1 @@
1
+ <%= display_bootdisk_for_subnet(subject) %>
@@ -0,0 +1 @@
1
+ <%= display_bootdisk_title_buttons %>
data/config/routes.rb CHANGED
@@ -7,7 +7,8 @@ ForemanBootdisk::Engine.routes.draw do
7
7
  constraints(id: %r{[^/]+}) do
8
8
  get 'hosts/:id', on: :collection, to: 'disks#host'
9
9
  get 'full_hosts/:id', on: :collection, to: 'disks#full_host'
10
- get 'subnet/:id', on: :collection, to: 'disks#subnet'
10
+ get 'subnet/:id', on: :collection, to: 'subnet_disks#subnet'
11
+ get 'bootdisk_options/:id', on: :collection, to: 'disks#bootdisk_options'
11
12
  end
12
13
  end
13
14
 
@@ -2,10 +2,10 @@
2
2
 
3
3
  class ChangeTemplatekindToBootdisk < ActiveRecord::Migration[4.2]
4
4
  class FakeConfigTemplate < ApplicationRecord
5
- self.table_name = if ActiveRecord::Base.connection.migration_context.get_all_versions.include?(20_150_514_072_626)
6
- 'templates'
7
- else
5
+ self.table_name = if defined? ConfigTemplate
8
6
  'config_templates'
7
+ else
8
+ 'templates'
9
9
  end
10
10
  end
11
11
 
@@ -38,10 +38,13 @@ module ForemanBootdisk
38
38
 
39
39
  initializer 'foreman_bootdisk.register_plugin', before: :finisher_hook do |_app|
40
40
  Foreman::Plugin.register :foreman_bootdisk do
41
- requires_foreman '>= 2.1'
41
+ requires_foreman '>= 3.1'
42
+ # Add Global files for extending foreman-core components and routes
43
+ register_global_js_file 'global'
42
44
 
43
45
  security_block :bootdisk do |_map|
44
- permission :download_bootdisk, 'foreman_bootdisk/disks': %i[generic host full_host subnet help],
46
+ permission :download_bootdisk, 'foreman_bootdisk/disks': %i[generic host full_host help bootdisk_options],
47
+ 'foreman_bootdisk/subnet_disks': [:subnet],
45
48
  'foreman_bootdisk/api/v2/disks': %i[generic host],
46
49
  'foreman_bootdisk/api/v2/subnet_disks': [:subnet]
47
50
  end
@@ -57,6 +60,11 @@ module ForemanBootdisk
57
60
  provision_method 'bootdisk', N_('Boot disk based')
58
61
  template_labels 'Bootdisk' => N_('Boot disk embedded template')
59
62
  allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise
63
+
64
+ extend_page "subnets/index" do |cx|
65
+ cx.add_pagelet :subnet_index_action_buttons, name: 'Bootdisk', partial: 'subnets/bootdisk_action_buttons'
66
+ cx.add_pagelet :subnet_index_title_buttons, name: 'Bootdisk', partial: 'subnets/bootdisk_title_buttons'
67
+ end
60
68
  end
61
69
  end
62
70
 
@@ -71,6 +79,7 @@ module ForemanBootdisk
71
79
  Host::Managed.prepend ForemanBootdisk::HostExt
72
80
  Host::Managed.include ForemanBootdisk::Orchestration::Compute if SETTINGS[:unattended]
73
81
  HostsHelper.prepend ForemanBootdisk::HostsHelperExt
82
+ SubnetsHelper.prepend ForemanBootdisk::SubnetsHelperExt
74
83
  Foreman::Model::Vmware.prepend ForemanBootdisk::ComputeResources::Vmware if Foreman::Model::Vmware.available?
75
84
  rescue StandardError => e
76
85
  Rails.logger.warn "#{ForemanBootdisk::ENGINE_NAME}: skipping engine hook (#{e})"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanBootdisk
4
- VERSION = '17.1.0'
4
+ VERSION = '19.0.1'
5
5
  end
@@ -1,7 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
1
  # Autogenerated!
4
2
  _("Remote action:")
5
- _("Import facts")
6
3
  _("Import Puppet classes")
7
- _("Action with sub plans")
4
+ _("Import facts")
5
+ _("Action with sub plans")