foreman_bootdisk 13.0.0 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +4 -0
  3. data/README.md +3 -2
  4. data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +11 -9
  5. data/app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb +37 -31
  6. data/app/controllers/foreman_bootdisk/disks_controller.rb +20 -19
  7. data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +86 -45
  8. data/app/lib/foreman_bootdisk/scope/bootdisk.rb +2 -0
  9. data/app/lib/foreman_bootdisk/scope/full_host_bootdisk.rb +15 -0
  10. data/app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb +4 -2
  11. data/app/models/concerns/foreman_bootdisk/host_ext.rb +43 -31
  12. data/app/models/concerns/foreman_bootdisk/orchestration/compute.rb +14 -10
  13. data/app/models/setting/bootdisk.rb +28 -23
  14. data/app/services/foreman_bootdisk/iso_generator.rb +127 -104
  15. data/app/services/foreman_bootdisk/renderer.rb +16 -13
  16. data/config/routes.rb +15 -13
  17. data/config/routes/mount_engine.rb +3 -1
  18. data/db/migrate/20130914211030_create_host_bootdisk_template.rb +4 -4
  19. data/db/migrate/20130915104500_edit_host_bootdisk_template_multinic.rb +4 -4
  20. data/db/migrate/20130915133321_create_kickstart_bootdisk_template.rb +4 -4
  21. data/db/migrate/20130915201457_create_generic_host_bootdisk_template.rb +4 -4
  22. data/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb +4 -4
  23. data/db/migrate/20140522185700_change_templatekind_to_bootdisk.rb +16 -14
  24. data/db/migrate/20171009225200_remove_duplicate_bootdisk_templates.rb +4 -2
  25. data/db/seeds.d/50-bootdisk_templates.rb +24 -22
  26. data/lib/foreman_bootdisk.rb +2 -0
  27. data/lib/foreman_bootdisk/engine.rb +22 -33
  28. data/lib/foreman_bootdisk/version.rb +3 -1
  29. data/lib/tasks/bootdisk.rake +34 -17
  30. data/locale/gemspec.rb +3 -1
  31. data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +35 -33
  32. data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +9 -7
  33. data/test/functional/foreman_bootdisk/disks_controller_test.rb +27 -25
  34. data/test/models/host/managed_test.rb +17 -13
  35. data/test/test_plugin_helper.rb +9 -7
  36. data/test/unit/access_permissions_test.rb +2 -0
  37. data/test/unit/concerns/compute_resources/vmware_test.rb +67 -63
  38. data/test/unit/concerns/host_test.rb +54 -54
  39. data/test/unit/concerns/orchestration/compute_test.rb +41 -39
  40. data/test/unit/foreman_bootdisk/renderer_test.rb +3 -1
  41. data/test/unit/foreman_bootdisk/scope/bootdisk_test.rb +3 -1
  42. data/test/unit/foreman_bootdisk/scope/full_host_bootdisk_test.rb +30 -0
  43. data/test/unit/iso_generator_test.rb +57 -40
  44. metadata +19 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d43b8549de63eaac53bdccedfed1db1c8c96f9481ee411724686686476e01767
4
- data.tar.gz: 30d918f87198e96711e2d75506127bb7ded00cafef415e5eaa176c24810f1a94
3
+ metadata.gz: dd7cc51c2b0f332b25d13f49d22c813c0ed28fb9b6e34238a7f44cfd40eddda1
4
+ data.tar.gz: f46b68427bbd016563ef186a9ed2cacbaf8f271c8da421db5f7eefb21eb363c6
5
5
  SHA512:
6
- metadata.gz: c8d73855b7dbf1f7ed717883a56813917d1fba38ca226cf77fa0c73005b38e44220563bd411c112c636182ba328d52ef336b912c80c7c356f29a4d8bb29687ab
7
- data.tar.gz: 832d7248d4bc1364f17507dad46325cd929e719790d3ebe08529459a21762d557987d908c5fca82d632bd8e522df3f4a1ba34b49a24faff60a0f5ebc0c6b5251
6
+ metadata.gz: cefbdba361acd20cdfb1a9137010da3290b8170fe9bf8bafc9f786f514acb7b81a5b448f4b8f794d5416800f5cdcf3faad55693efd6672fbe454375ae84ecf3c
7
+ data.tar.gz: b00a6e9af217a60d776508e3e076077729ebd0360cf3bdb246a71be9e307abeef10bc42c46a68f23834153a8fa86123eeb14cfafe007aa29c77b38087a3f612f
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v14.0.0
4
+ * use new medium provider framework
5
+ * droped some unused code
6
+
3
7
  ## v13.0.0
4
8
  * static credentials failover
5
9
  * Rails 5.2 support
data/README.md CHANGED
@@ -47,8 +47,9 @@ gPXE images are unsupported due to lack of initrd support.
47
47
  | >= 1.15 | ~> 10.0 |
48
48
  | >= 1.17 | ~> 11.0 |
49
49
  | >= 1.18 | ~> 12.0 |
50
- | >= 1.19 | ~> 12.0 |
51
- | >= 1.20 | ~> 13.0 |
50
+ | >= 1.19 | ~> 13.0 |
51
+ | >= 1.20 | ~> 14.0 |
52
+ | >= 1.21 | ~> 15.0 |
52
53
 
53
54
  # Usage
54
55
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module ForemanBootdisk
@@ -7,10 +9,10 @@ module ForemanBootdisk
7
9
  include ::Api::Version2
8
10
 
9
11
  resource_description do
10
- api_base_url "/bootdisk/api"
12
+ api_base_url '/bootdisk/api'
11
13
  end
12
14
 
13
- before_action :find_resource, :only => :host
15
+ before_action :find_resource, only: :host
14
16
  skip_after_action :log_response_body
15
17
 
16
18
  # no-op, but required for apipie documentation
@@ -20,24 +22,24 @@ module ForemanBootdisk
20
22
  api :GET, '/generic', N_('Download generic image')
21
23
  def generic
22
24
  tmpl = ForemanBootdisk::Renderer.new.generic_template_render
23
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl) do |iso|
24
- send_data read_file(iso), :filename => "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso"
25
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
26
+ send_data read_file(iso), filename: "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso"
25
27
  end
26
28
  end
27
29
 
28
30
  api :GET, '/hosts/:host_id', N_('Download host image')
29
- param :full, :bool, :required => false, :desc => N_('True for full, false for basic reusable image')
30
- param :host_id, :identifier_dottable, :required => true
31
+ param :full, :bool, required: false, desc: N_('True for full, false for basic reusable image')
32
+ param :host_id, :identifier_dottable, required: true
31
33
  def host
32
34
  host = @disk
33
35
  if params[:full]
34
36
  ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
35
- send_data read_file(iso), :filename => "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso"
37
+ send_data read_file(iso), filename: "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso"
36
38
  end
37
39
  else
38
40
  tmpl = host.bootdisk_template_render
39
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl) do |iso|
40
- send_data read_file(iso), :filename => "#{host.name}.iso"
41
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
42
+ send_data read_file(iso), filename: "#{host.name}.iso"
41
43
  end
42
44
  end
43
45
  end
@@ -1,37 +1,43 @@
1
- require 'uri'
2
-
3
- module ForemanBootdisk::Api::V2
4
- class SubnetDisksController < ::Api::V2::BaseController
5
- include ::Api::Version2
6
-
7
- resource_description do
8
- api_base_url "/bootdisk/api"
9
- end
10
-
11
- before_action :find_resource, :only => :subnet
1
+ # frozen_string_literal: true
12
2
 
13
- skip_after_action :log_response_body
14
-
15
- # no-op, but required for apipie documentation
16
- api :GET, '', N_('Subnet boot disks')
17
- def index; end
3
+ require 'uri'
18
4
 
19
- api :GET, '/subnets/:subnet_id', N_('Download subnet generic image')
20
- param :subnet_id, :identifier_dottable, :required => true
21
- def subnet
22
- subnet = @subnet_disk
23
- subnet.tftp || raise(::Foreman::Exception.new(N_("TFTP feature not enabled for subnet %s"), subnet.name))
24
- tmpl = ForemanBootdisk::Renderer.new.generic_template_render(subnet)
25
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl) do |iso|
26
- name=subnet.name
27
- send_data File.read(iso), :filename => "bootdisk_subnet_#{name}.iso"
5
+ module ForemanBootdisk
6
+ module Api
7
+ module V2
8
+ class SubnetDisksController < ::Api::V2::BaseController
9
+ include ::Api::Version2
10
+
11
+ resource_description do
12
+ api_base_url '/bootdisk/api'
13
+ end
14
+
15
+ before_action :find_resource, only: :subnet
16
+
17
+ skip_after_action :log_response_body
18
+
19
+ # no-op, but required for apipie documentation
20
+ api :GET, '', N_('Subnet boot disks')
21
+ def index; end
22
+
23
+ api :GET, '/subnets/:subnet_id', N_('Download subnet generic image')
24
+ param :subnet_id, :identifier_dottable, required: true
25
+ def subnet
26
+ subnet = @subnet_disk
27
+ 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"
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def resource_scope
38
+ Subnet.authorized('view_subnets')
39
+ end
28
40
  end
29
41
  end
30
-
31
- private
32
-
33
- def resource_scope
34
- Subnet.authorized('view_subnets')
35
- end
36
42
  end
37
43
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module ForemanBootdisk
4
6
  class DisksController < ::ApplicationController
5
- before_action :find_resource, :only => %w[host full_host subnet]
7
+ before_action :find_resource, only: %w[host full_host subnet]
6
8
 
7
9
  # as this engine is isolated, we need to include url helpers from core explicitly
8
10
  # to render help page layout
@@ -11,14 +13,14 @@ module ForemanBootdisk
11
13
  def generic
12
14
  begin
13
15
  tmpl = ForemanBootdisk::Renderer.new.generic_template_render
14
- rescue => e
16
+ rescue StandardError => e
15
17
  error_rendering(e)
16
18
  redirect_back(fallback_location: '/')
17
19
  return
18
20
  end
19
21
 
20
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl) do |iso|
21
- send_data read_file(iso), :filename => "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso"
22
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
23
+ send_data read_file(iso), filename: "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso"
22
24
  end
23
25
  end
24
26
 
@@ -26,43 +28,42 @@ module ForemanBootdisk
26
28
  host = @disk
27
29
  begin
28
30
  tmpl = host.bootdisk_template_render
29
- rescue => e
31
+ rescue StandardError => e
30
32
  error_rendering(e)
31
33
  redirect_back(fallback_location: '/')
32
34
  return
33
35
  end
34
36
 
35
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl) do |iso|
36
- send_data read_file(iso), :filename => "#{host.name}.iso"
37
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
38
+ send_data read_file(iso), filename: "#{host.name}.iso"
37
39
  end
38
40
  end
39
41
 
40
42
  def full_host
41
43
  host = @disk
42
44
  ForemanBootdisk::ISOGenerator.generate_full_host(host) do |iso|
43
- send_data read_file(iso), :filename => "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso"
45
+ send_data read_file(iso), filename: "#{host.name}#{ForemanBootdisk::ISOGenerator.token_expiry(host)}.iso"
44
46
  end
45
47
  end
46
48
 
47
49
  def subnet
48
50
  host = @disk
49
51
  begin
50
- subnet = host.try(:subnet) || raise(::Foreman::Exception.new(N_("Subnet is not assigned to the host %s"), host.name))
51
- subnet.tftp || raise(::Foreman::Exception.new(N_("TFTP feature not enabled for subnet %s"), subnet.name))
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))
52
54
  tmpl = ForemanBootdisk::Renderer.new.generic_template_render(subnet)
53
- rescue => e
55
+ rescue StandardError => e
54
56
  error_rendering(e)
55
57
  redirect_back(fallback_location: '/')
56
58
  return
57
59
  end
58
60
 
59
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl) do |iso|
60
- send_data read_file(iso), :filename => "bootdisk_subnet_#{subnet.name}.iso"
61
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl) do |iso|
62
+ send_data read_file(iso), filename: "bootdisk_subnet_#{subnet.name}.iso"
61
63
  end
62
64
  end
63
65
 
64
- def help
65
- end
66
+ def help; end
66
67
 
67
68
  private
68
69
 
@@ -70,14 +71,14 @@ module ForemanBootdisk
70
71
  File.read(filename)
71
72
  end
72
73
 
73
- def resource_scope(controller = controller_name)
74
+ def resource_scope(_controller = controller_name)
74
75
  Host::Managed.authorized(:view_hosts)
75
76
  end
76
77
 
77
- def error_rendering(e)
78
+ def error_rendering(exception)
78
79
  msg = _('Failed to render boot disk template')
79
- error("#{msg}: #{e.message}")
80
- ::Foreman::Logging.exception(msg, e)
80
+ error("#{msg}: #{exception.message}")
81
+ ::Foreman::Logging.exception(msg, exception)
81
82
  end
82
83
  end
83
84
  end
@@ -1,58 +1,99 @@
1
- module ForemanBootdisk::HostsHelperExt
2
- def host_title_actions(*args)
3
- if @host.bootdisk_downloadable?
4
- title_actions(
5
- button_group(
6
- select_action_button(_('Boot disk'), {:class => 'btn btn-group'},
7
- display_bootdisk_link_if_authorized(_("Host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'host', :id => @host}, :class=>'la'),
8
- display_bootdisk_link_if_authorized(_("Full host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'full_host', :id => @host}, :class=>'la'),
9
- content_tag(:li, "", :class => "divider"),
10
- display_bootdisk_link_if_authorized(_("Generic image"), {:controller => 'foreman_bootdisk/disks', :action => 'generic'}, :class=>'la'),
11
- display_bootdisk_for_subnet,
12
- content_tag(:li, "", :class => "divider"),
13
- display_bootdisk_link_if_authorized(_("Help"), {:controller => 'foreman_bootdisk/disks', :action => 'help'}, :class=>'la')
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanBootdisk
4
+ module HostsHelperExt
5
+ def host_title_actions(*args)
6
+ 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,
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
+ )
14
48
  )
15
49
  )
16
- )
17
- else
18
- bootdisk_button_disabled
19
- end
50
+ else
51
+ bootdisk_button_disabled
52
+ end
20
53
 
21
- super
22
- end
54
+ super
55
+ end
23
56
 
24
- def bootdisk_button_disabled
25
- title_actions(
26
- button_group(
27
- link_to(_("Boot disk"), '#', :disabled => true, :class => 'btn btn-default',
28
- :title => _("Boot disk download not available for %s architecture") % @host.architecture.name)
57
+ def bootdisk_button_disabled
58
+ title_actions(
59
+ button_group(
60
+ link_to(_('Boot disk'), '#', disabled: true, class: 'btn btn-default',
61
+ title: _('Boot disk download not available for %s architecture') % @host.architecture.name)
62
+ )
29
63
  )
30
- )
31
- end
64
+ end
32
65
 
33
- # need to wrap this one in a test for template proxy presence
34
- def display_bootdisk_for_subnet
35
- if (proxy = @host.try(:subnet).try(:tftp)) && proxy.has_feature?('Templates')
36
- display_bootdisk_link_if_authorized(_("Subnet '%s' generic image") % @host.subnet.name, {:controller => 'foreman_bootdisk/disks', :action => 'subnet', :id => @host}, :class=>'la')
37
- else
38
- ""
66
+ # need to wrap this one in a test for template proxy presence
67
+ def display_bootdisk_for_subnet
68
+ if (proxy = @host.try(:subnet).try(:tftp)) && proxy.has_feature?('Templates')
69
+ display_bootdisk_link_if_authorized(
70
+ _("Subnet '%s' generic image") % @host.subnet.name, {
71
+ controller: 'foreman_bootdisk/disks',
72
+ action: 'subnet',
73
+ id: @host
74
+ },
75
+ class: 'la'
76
+ )
77
+ else
78
+ ''
79
+ end
39
80
  end
40
- end
41
81
 
42
- # Core Foreman helpers can't look up a URL against a mounted engine
43
- def display_bootdisk_link_if_authorized(name, options = {}, html_options = {})
44
- if bootdisk_authorized_for(options)
45
- link_to(name, bootdisk_url(options), html_options)
46
- else
47
- ""
82
+ # Core Foreman helpers can't look up a URL against a mounted engine
83
+ def display_bootdisk_link_if_authorized(name, options = {}, html_options = {})
84
+ if bootdisk_authorized_for(options)
85
+ link_to(name, bootdisk_url(options), html_options)
86
+ else
87
+ ''
88
+ end
48
89
  end
49
- end
50
90
 
51
- def bootdisk_url(options)
52
- ForemanBootdisk::Engine.routes.url_for(options.merge(:only_path => true, :script_name => foreman_bootdisk_path))
53
- end
91
+ def bootdisk_url(options)
92
+ ForemanBootdisk::Engine.routes.url_for(options.merge(only_path: true, script_name: foreman_bootdisk_path))
93
+ end
54
94
 
55
- def bootdisk_authorized_for(options)
56
- User.current.allowed_to?(options)
95
+ def bootdisk_authorized_for(options)
96
+ User.current.allowed_to?(options)
97
+ end
57
98
  end
58
99
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanBootdisk
2
4
  module Scope
3
5
  class Bootdisk < ::Foreman::Renderer::Scope::Provisioning
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanBootdisk
4
+ module Scope
5
+ class FullHostBootdisk < Bootdisk
6
+ def kernel(medium_provider)
7
+ ForemanBootdisk::ISOGenerator.iso9660_filename(super)
8
+ end
9
+
10
+ def initrd(medium_provider)
11
+ ForemanBootdisk::ISOGenerator.iso9660_filename(super)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanBootdisk
2
4
  module ComputeResources
3
5
  module Vmware
@@ -6,10 +8,10 @@ module ForemanBootdisk
6
8
  end
7
9
 
8
10
  def parse_args(args = {})
9
- args = super
11
+ args = super(args)
10
12
  if args[:provision_method] == 'bootdisk'
11
13
  args[:cdroms] = [new_cdrom]
12
- args[:boot_order] = ['cdrom', 'disk']
14
+ args[:boot_order] = %w[cdrom disk]
13
15
  args[:boot_retry] = 10
14
16
  end
15
17
  args