foreman_bootdisk 12.0.1 → 13.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/README.md +2 -0
- data/app/controllers/foreman_bootdisk/disks_controller.rb +4 -0
- data/app/lib/foreman_bootdisk/scope/bootdisk.rb +21 -0
- data/app/models/concerns/foreman_bootdisk/host_ext.rb +5 -2
- data/app/services/foreman_bootdisk/renderer.rb +30 -15
- data/app/views/foreman_bootdisk/generic_host.erb +21 -3
- data/app/views/foreman_bootdisk/host.erb +2 -3
- data/db/migrate/20140522185700_change_templatekind_to_bootdisk.rb +1 -1
- data/lib/foreman_bootdisk/engine.rb +3 -4
- data/lib/foreman_bootdisk/version.rb +1 -1
- data/test/models/host/managed_test.rb +22 -0
- data/test/unit/concerns/host_test.rb +8 -0
- data/test/unit/foreman_bootdisk/renderer_test.rb +34 -0
- data/test/unit/foreman_bootdisk/scope/bootdisk_test.rb +29 -0
- metadata +6 -3
- data/app/services/foreman_bootdisk/renderer_methods.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d43b8549de63eaac53bdccedfed1db1c8c96f9481ee411724686686476e01767
|
4
|
+
data.tar.gz: 30d918f87198e96711e2d75506127bb7ded00cafef415e5eaa176c24810f1a94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d73855b7dbf1f7ed717883a56813917d1fba38ca226cf77fa0c73005b38e44220563bd411c112c636182ba328d52ef336b912c80c7c356f29a4d8bb29687ab
|
7
|
+
data.tar.gz: 832d7248d4bc1364f17507dad46325cd929e719790d3ebe08529459a21762d557987d908c5fca82d632bd8e522df3f4a1ba34b49a24faff60a0f5ebc0c6b5251
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,10 @@ module ForemanBootdisk
|
|
4
4
|
class DisksController < ::ApplicationController
|
5
5
|
before_action :find_resource, :only => %w[host full_host subnet]
|
6
6
|
|
7
|
+
# as this engine is isolated, we need to include url helpers from core explicitly
|
8
|
+
# to render help page layout
|
9
|
+
include Rails.application.routes.url_helpers
|
10
|
+
|
7
11
|
def generic
|
8
12
|
begin
|
9
13
|
tmpl = ForemanBootdisk::Renderer.new.generic_template_render
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ForemanBootdisk
|
2
|
+
module Scope
|
3
|
+
class Bootdisk < ::Foreman::Renderer::Scope::Provisioning
|
4
|
+
def bootdisk_chain_url(mac = host.try(:mac), action = 'iPXE')
|
5
|
+
url = foreman_url(action)
|
6
|
+
u = URI.parse(url)
|
7
|
+
ForemanBootdisk.logger.warn("Foreman or proxy is configured with HTTPS, probably not supported by iPXE: #{u}") if u.scheme == 'https'
|
8
|
+
new_query_data = URI.decode_www_form(u.query || '') << ['mac', mac || '']
|
9
|
+
new_querystring = URI.encode_www_form(new_query_data)
|
10
|
+
u.query = nil
|
11
|
+
u.query = new_querystring if new_querystring.present?
|
12
|
+
u.fragment = nil
|
13
|
+
u.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def bootdisk_raise(*args)
|
17
|
+
raise ::Foreman::Exception.new(*args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -6,8 +6,7 @@ module ForemanBootdisk::HostExt
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def bootdisk_template_render
|
9
|
-
|
10
|
-
unattended_render(bootdisk_template.template)
|
9
|
+
ForemanBootdisk::Renderer.new.render_template(template: bootdisk_template, host: self)
|
11
10
|
end
|
12
11
|
|
13
12
|
def bootdisk_build?
|
@@ -26,6 +25,10 @@ module ForemanBootdisk::HostExt
|
|
26
25
|
/i.86|x86[_-]64/ =~ architecture.name
|
27
26
|
end
|
28
27
|
|
28
|
+
def validate_media?
|
29
|
+
super || (managed && bootdisk_build? && build?)
|
30
|
+
end
|
31
|
+
|
29
32
|
def can_be_built?
|
30
33
|
super || (managed? and SETTINGS[:unattended] and bootdisk_build? and !build?)
|
31
34
|
end
|
@@ -2,28 +2,43 @@ require 'uri'
|
|
2
2
|
|
3
3
|
module ForemanBootdisk
|
4
4
|
class Renderer
|
5
|
-
include ::Foreman::Renderer
|
6
|
-
include Rails.application.routes.url_helpers
|
7
|
-
delegate :logger, :to => :ForemanBootdisk
|
8
|
-
include RendererMethods
|
9
|
-
|
10
5
|
def generic_template_render(subnet = nil)
|
11
|
-
tmpl = ProvisioningTemplate.unscoped.find_by_name(Setting[:bootdisk_generic_host_template]) || raise(::Foreman::Exception.new(N_('Unable to find template specified by %s setting'), 'bootdisk_generic_host_template'))
|
12
|
-
|
13
6
|
if subnet.present?
|
14
7
|
# rendering a subnet-level bootdisk requires tricking the renderer into thinking it has a
|
15
|
-
# valid host,
|
16
|
-
|
17
|
-
|
8
|
+
# valid host, without a token, but with a tftp proxy
|
9
|
+
host = Struct.new(:token, :provision_interface).new(
|
10
|
+
nil,
|
18
11
|
Struct.new(:subnet).new(subnet)
|
19
12
|
)
|
20
13
|
else
|
21
|
-
|
14
|
+
host = Struct.new(:token, :subnet).new(nil, nil)
|
22
15
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
|
17
|
+
render_template(template: generic_host_template, host: host)
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_template(template: , host:)
|
21
|
+
source = Foreman::Renderer.get_source(
|
22
|
+
template: template,
|
23
|
+
host: host
|
24
|
+
)
|
25
|
+
scope = Foreman::Renderer.get_scope(
|
26
|
+
host: host,
|
27
|
+
klass: renderer_scope
|
28
|
+
)
|
29
|
+
Foreman::Renderer.render(source, scope)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def renderer_scope
|
35
|
+
ForemanBootdisk::Scope::Bootdisk
|
36
|
+
end
|
37
|
+
|
38
|
+
def generic_host_template
|
39
|
+
template = ProvisioningTemplate.unscoped.find_by_name(Setting[:bootdisk_generic_host_template])
|
40
|
+
raise ::Foreman::Exception.new(N_('Unable to find template specified by %s setting'), 'bootdisk_generic_host_template') unless template
|
41
|
+
template
|
27
42
|
end
|
28
43
|
end
|
29
44
|
end
|
@@ -21,8 +21,26 @@ dhcp net<%= i %> || goto net<%= i+1 %>
|
|
21
21
|
chain <%= url %>${net<%= i -%>/mac} || goto net<%= i+1 %>
|
22
22
|
exit 0
|
23
23
|
<% end -%>
|
24
|
+
echo Failed to chainload from any network interface, fallback to static.
|
25
|
+
ifstat
|
24
26
|
|
25
27
|
:no_nic
|
26
|
-
echo
|
27
|
-
|
28
|
-
|
28
|
+
echo -n Enter interface name to boot from (e.g. net0): && read interface
|
29
|
+
isset ${${interface}/mac} && goto get_static_ip
|
30
|
+
echo Interface ${interface} is not initialized, try again
|
31
|
+
goto no_nic
|
32
|
+
|
33
|
+
:get_static_ip
|
34
|
+
ifopen ${interface}
|
35
|
+
echo Please enter IP details for ${interface}
|
36
|
+
echo
|
37
|
+
echo -n IP address : && read ${interface}/ip
|
38
|
+
echo -n Subnet mask : && read ${interface}/netmask
|
39
|
+
echo -n Default gateway : && read ${interface}/gateway
|
40
|
+
echo -n DNS server : && read dns
|
41
|
+
chain <%= url %>${${interface}/mac} || goto boot_failure
|
42
|
+
exit 0
|
43
|
+
|
44
|
+
:boot_failure
|
45
|
+
echo Cannot continue, spawning shell
|
46
|
+
shell
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class ChangeTemplatekindToBootdisk < ActiveRecord::Migration[4.2]
|
2
2
|
class FakeConfigTemplate < ApplicationRecord
|
3
|
-
if ActiveRecord::
|
3
|
+
if ActiveRecord::Base.connection.migration_context.get_all_versions.include?(20150514072626)
|
4
4
|
self.table_name = 'templates'
|
5
5
|
else
|
6
6
|
self.table_name = 'config_templates'
|
@@ -9,8 +9,9 @@ module ForemanBootdisk
|
|
9
9
|
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
10
10
|
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
11
11
|
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
12
|
+
config.autoload_paths += Dir["#{config.root}/app/lib"]
|
12
13
|
|
13
|
-
initializer 'foreman_bootdisk.mount_engine'
|
14
|
+
initializer 'foreman_bootdisk.mount_engine' do |app|
|
14
15
|
app.routes_reloader.paths << "#{ForemanBootdisk::Engine.root}/config/routes/mount_engine.rb"
|
15
16
|
end
|
16
17
|
|
@@ -60,11 +61,10 @@ module ForemanBootdisk
|
|
60
61
|
|
61
62
|
add_all_permissions_to_default_roles
|
62
63
|
|
63
|
-
allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise
|
64
64
|
apipie_documented_controllers ["#{ForemanBootdisk::Engine.root}/app/controllers/foreman_bootdisk/api/v2/*.rb"]
|
65
65
|
provision_method 'bootdisk', N_('Boot disk based')
|
66
66
|
template_labels 'Bootdisk' => N_('Boot disk embedded template')
|
67
|
-
|
67
|
+
allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -77,7 +77,6 @@ module ForemanBootdisk
|
|
77
77
|
config.to_prepare do
|
78
78
|
begin
|
79
79
|
Host::Managed.send(:prepend, ForemanBootdisk::HostExt)
|
80
|
-
Host::Managed.send(:include, ForemanBootdisk::RendererMethods)
|
81
80
|
Host::Managed.send(:include, ForemanBootdisk::Orchestration::Compute) if SETTINGS[:unattended]
|
82
81
|
HostsHelper.send(:prepend, ForemanBootdisk::HostsHelperExt)
|
83
82
|
Foreman::Model::Vmware.send(:prepend, ForemanBootdisk::ComputeResources::Vmware) if Foreman::Model::Vmware.available?
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class Host::ManagedTest < ActiveSupport::TestCase
|
4
|
+
include ForemanBootdiskTestHelper
|
5
|
+
|
6
|
+
setup do
|
7
|
+
User.current = users(:admin)
|
8
|
+
setup_bootdisk
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'with host' do
|
12
|
+
let(:host) { FactoryBot.create(:host, :managed, :with_subnet, build: true) }
|
13
|
+
|
14
|
+
test 'finds the bootdisk_template specified in settings' do
|
15
|
+
assert_kind_of ProvisioningTemplate, host.bootdisk_template
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'renders the host bootdisk template' do
|
19
|
+
assert_includes host.bootdisk_template_render, 'loop_success'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -9,6 +9,14 @@ class ForemanBootdisk::HostTest < ActiveSupport::TestCase
|
|
9
9
|
refute host.pxe_build?
|
10
10
|
end
|
11
11
|
|
12
|
+
test "#validate_media? must be true when provision_method is bootdisk" do
|
13
|
+
host = FactoryBot.build(:host, :managed,
|
14
|
+
:provision_method => "bootdisk",
|
15
|
+
:build => true,
|
16
|
+
)
|
17
|
+
assert host.validate_media?
|
18
|
+
end
|
19
|
+
|
12
20
|
test "#can_be_built? must be true when provision_method is bootdisk" do
|
13
21
|
host = FactoryBot.build(:host, :managed,
|
14
22
|
:provision_method => "bootdisk"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanBootdisk
|
4
|
+
class RendererTest < ActiveSupport::TestCase
|
5
|
+
include ForemanBootdiskTestHelper
|
6
|
+
|
7
|
+
setup do
|
8
|
+
User.current = users(:admin)
|
9
|
+
setup_bootdisk
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:renderer) { ForemanBootdisk::Renderer.new }
|
13
|
+
|
14
|
+
describe 'a generic template' do
|
15
|
+
test 'can be rendered' do
|
16
|
+
rendered_template = renderer.generic_template_render
|
17
|
+
assert_includes rendered_template, 'ifstat'
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'does not include a host token' do
|
21
|
+
rendered_template = renderer.generic_template_render
|
22
|
+
assert_includes rendered_template, 'http://foreman.some.host.fqdn/unattended/iPXE?mac=${net0/mac}'
|
23
|
+
refute_includes rendered_template, 'token'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with a subnet' do
|
28
|
+
let(:subnet) { FactoryBot.create(:subnet_ipv4) }
|
29
|
+
test 'renders a subnet template' do
|
30
|
+
assert_includes renderer.generic_template_render(subnet), 'ifstat'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanBootdisk
|
4
|
+
module Scope
|
5
|
+
class BootdiskTest < ActiveSupport::TestCase
|
6
|
+
let(:host) { FactoryBot.build(:host, :managed) }
|
7
|
+
let(:source) { Foreman::Renderer::Source::String.new(content: 'Test') }
|
8
|
+
let(:scope) { ForemanBootdisk::Scope::Bootdisk.new(host: host, source: source) }
|
9
|
+
|
10
|
+
describe '#bootdisk_chain_url' do
|
11
|
+
test 'should render bootdisk chain url' do
|
12
|
+
assert_equal "http://foreman.some.host.fqdn/unattended/iPXE?mac=#{URI.encode_www_form_component(host.mac)}", scope.bootdisk_chain_url
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'should render bootdisk chain url with custom mac' do
|
16
|
+
assert_equal "http://foreman.some.host.fqdn/unattended/iPXE?mac=00%3A11%3A22%3A33%3A44%3A55", scope.bootdisk_chain_url('00:11:22:33:44:55')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#bootdisk_raise' do
|
21
|
+
test 'should raise a Foreman::Exception' do
|
22
|
+
assert_raise ::Foreman::Exception do
|
23
|
+
scope.bootdisk_raise('Some error.')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_bootdisk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 13.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominic Cleal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Plugin for Foreman that creates iPXE-based boot disks to provision hosts
|
14
14
|
without the need for PXE infrastructure.
|
@@ -29,13 +29,13 @@ files:
|
|
29
29
|
- app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb
|
30
30
|
- app/controllers/foreman_bootdisk/disks_controller.rb
|
31
31
|
- app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb
|
32
|
+
- app/lib/foreman_bootdisk/scope/bootdisk.rb
|
32
33
|
- app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb
|
33
34
|
- app/models/concerns/foreman_bootdisk/host_ext.rb
|
34
35
|
- app/models/concerns/foreman_bootdisk/orchestration/compute.rb
|
35
36
|
- app/models/setting/bootdisk.rb
|
36
37
|
- app/services/foreman_bootdisk/iso_generator.rb
|
37
38
|
- app/services/foreman_bootdisk/renderer.rb
|
38
|
-
- app/services/foreman_bootdisk/renderer_methods.rb
|
39
39
|
- app/views/foreman_bootdisk/disks/help.html.erb
|
40
40
|
- app/views/foreman_bootdisk/generic_host.erb
|
41
41
|
- app/views/foreman_bootdisk/host.erb
|
@@ -89,11 +89,14 @@ files:
|
|
89
89
|
- test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb
|
90
90
|
- test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb
|
91
91
|
- test/functional/foreman_bootdisk/disks_controller_test.rb
|
92
|
+
- test/models/host/managed_test.rb
|
92
93
|
- test/test_plugin_helper.rb
|
93
94
|
- test/unit/access_permissions_test.rb
|
94
95
|
- test/unit/concerns/compute_resources/vmware_test.rb
|
95
96
|
- test/unit/concerns/host_test.rb
|
96
97
|
- test/unit/concerns/orchestration/compute_test.rb
|
98
|
+
- test/unit/foreman_bootdisk/renderer_test.rb
|
99
|
+
- test/unit/foreman_bootdisk/scope/bootdisk_test.rb
|
97
100
|
- test/unit/iso_generator_test.rb
|
98
101
|
homepage: http://github.com/theforeman/foreman_bootdisk
|
99
102
|
licenses:
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module ForemanBootdisk
|
2
|
-
module RendererMethods
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
class_methods do
|
6
|
-
def format_bootdisk_chain_url(url, mac)
|
7
|
-
u = URI.parse(url)
|
8
|
-
ForemanBootdisk.logger.warn("Foreman or proxy is configured with HTTPS, probably not supported by iPXE: #{u}") if u.scheme == 'https'
|
9
|
-
u.query = "#{u.query}&mac=#{mac}"
|
10
|
-
u.fragment = nil
|
11
|
-
u.to_s
|
12
|
-
end
|
13
|
-
|
14
|
-
def bootdisk_raise(*args)
|
15
|
-
raise ::Foreman::Exception.new(*args)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def bootdisk_chain_url(mac = self.try(:mac), action = 'iPXE')
|
20
|
-
self.class.format_bootdisk_chain_url(foreman_url(action), mac)
|
21
|
-
end
|
22
|
-
|
23
|
-
def bootdisk_raise(*args)
|
24
|
-
self.class.bootdisk_raise(*args)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|