foreman_salt 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/app/controllers/foreman_salt/application_controller.rb +8 -0
- data/app/controllers/foreman_salt/concerns/hosts_controller_extensions.rb +3 -3
- data/app/controllers/foreman_salt/salt_autosign_controller.rb +1 -1
- data/app/controllers/foreman_salt/salt_environments_controller.rb +2 -2
- data/app/controllers/foreman_salt/salt_keys_controller.rb +1 -1
- data/app/controllers/foreman_salt/salt_modules_controller.rb +2 -2
- data/app/models/foreman_salt/concerns/host_managed_extensions.rb +67 -0
- data/app/models/foreman_salt/concerns/hostgroup_extensions.rb +65 -0
- data/app/models/foreman_salt/concerns/orchestration/salt.rb +75 -0
- data/app/views/foreman_salt/salt_keys/index.erb +1 -1
- data/db/seeds.d/75-salt-seeds.rb +2 -22
- data/lib/foreman_salt/engine.rb +2 -2
- data/lib/foreman_salt/version.rb +1 -1
- data/lib/tasks/foreman_salt_tasks.rake +1 -1
- data/test/factories/foreman_salt_factories.rb +9 -8
- data/test/functional/hosts_controller_test.rb +0 -1
- data/test/integration/salt_autosign_test.rb +1 -1
- data/test/integration/salt_keys_test.rb +1 -1
- data/test/unit/salt_keys_test.rb +3 -0
- metadata +10 -9
- data/app/models/concerns/foreman_salt/host_managed_extensions.rb +0 -65
- data/app/models/concerns/foreman_salt/hostgroup_extensions.rb +0 -63
- data/app/models/concerns/foreman_salt/orchestration/salt.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3958e07e3ba51a52ed71666da0a710088a5f33f6
|
4
|
+
data.tar.gz: df6214da1df13e4ec5eea3026c5237528d88deea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d6dc7e5d6b97d0fc09ebc34df7d6172ceab5e052d779ec907fca754fd6edea1ce82df6e5c56a135dc7db91147b4953aa643b4afec3ab05dd4b1dd59b29c04d0
|
7
|
+
data.tar.gz: b30c5d22dfd590fc398f26893ba1910452e9fc21b0fceca6974217c24fc58cb57142c0b586fd832ceedaeec9115f9553a5c4c88a8203662d2b8a9e39d6eb8250
|
data/README.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
This plug-in adds support for Salt to Foreman.
|
4
4
|
|
5
|
+
## Compatibility
|
6
|
+
|
7
|
+
| Foreman Version | Plugin Version |
|
8
|
+
| --------------- | --------------:|
|
9
|
+
| >= 1.6 | ~> 0.0 |
|
10
|
+
| >= 1.7 | ~> 1.0 |
|
11
|
+
|
5
12
|
## Documentation
|
6
13
|
|
7
14
|
More info is available in the Wiki https://github.com/theforeman/foreman_salt/wiki
|
@@ -4,8 +4,8 @@ module ForemanSalt
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
alias_method :
|
8
|
-
before_filter :
|
7
|
+
alias_method :find_resource_salt, :find_resource
|
8
|
+
before_filter :find_resource_salt, :only => [:saltrun]
|
9
9
|
alias_method_chain :action_permission, :salt_run
|
10
10
|
alias_method_chain :load_vars_for_ajax, :salt_modules
|
11
11
|
alias_method_chain :process_hostgroup, :salt_modules
|
@@ -22,7 +22,7 @@ module ForemanSalt
|
|
22
22
|
|
23
23
|
def salt_external_node
|
24
24
|
begin
|
25
|
-
@host = resource_base.
|
25
|
+
@host = resource_base.find(params[:name])
|
26
26
|
enc = {}
|
27
27
|
env = @host.salt_environment.blank? ? 'base' : @host.salt_environment.name
|
28
28
|
enc["classes"] = @host.salt_modules.any? ? @host.salt_modules.map(&:name) : []
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module ForemanSalt
|
2
|
-
class SaltEnvironmentsController <
|
2
|
+
class SaltEnvironmentsController < ApplicationController
|
3
3
|
include Foreman::Controller::AutoCompleteSearch
|
4
4
|
|
5
|
-
before_filter :
|
5
|
+
before_filter :find_resource, :only => [:edit, :update, :destroy]
|
6
6
|
|
7
7
|
def index
|
8
8
|
@salt_environments = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module ForemanSalt
|
2
|
-
class SaltModulesController <
|
2
|
+
class SaltModulesController < ApplicationController
|
3
3
|
include Foreman::Controller::AutoCompleteSearch
|
4
4
|
|
5
|
-
before_filter :
|
5
|
+
before_filter :find_resource, :only => [:edit, :update, :destroy]
|
6
6
|
|
7
7
|
def index
|
8
8
|
@salt_modules = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module ForemanSalt
|
2
|
+
module Concerns
|
3
|
+
module HostManagedExtensions
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
has_and_belongs_to_many :salt_modules, :class_name => "ForemanSalt::SaltModule", :join_table => "hosts_salt_modules", :foreign_key => "host_id"
|
8
|
+
belongs_to :salt_proxy, :class_name => "SmartProxy"
|
9
|
+
belongs_to :salt_environment, :class_name => "ForemanSalt::SaltEnvironment"
|
10
|
+
alias_method_chain :params, :salt_proxy
|
11
|
+
alias_method_chain :set_hostgroup_defaults, :salt_proxy
|
12
|
+
alias_method_chain :smart_proxy_ids, :salt_proxy
|
13
|
+
end
|
14
|
+
|
15
|
+
def handle_salt
|
16
|
+
return true unless salt?
|
17
|
+
salt_autosign_create
|
18
|
+
end
|
19
|
+
|
20
|
+
def params_with_salt_proxy
|
21
|
+
params = params_without_salt_proxy
|
22
|
+
params["salt_master"] = salt_master unless salt_master.blank?
|
23
|
+
params
|
24
|
+
end
|
25
|
+
|
26
|
+
def salt_modules
|
27
|
+
return super unless hostgroup
|
28
|
+
[super + hostgroup.salt_modules].flatten
|
29
|
+
end
|
30
|
+
|
31
|
+
def salt_module_ids
|
32
|
+
return super unless hostgroup
|
33
|
+
[super + hostgroup.salt_module_ids].flatten
|
34
|
+
end
|
35
|
+
|
36
|
+
def salt_master
|
37
|
+
salt_proxy.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def saltrun!
|
41
|
+
unless salt_proxy.present?
|
42
|
+
errors.add(:base, _("No Salt master defined - can't continue"))
|
43
|
+
logger.warn "Unable to execute salt run, no salt proxies defined"
|
44
|
+
return false
|
45
|
+
end
|
46
|
+
ProxyAPI::Salt.new({:url => salt_proxy.url}).highstate name
|
47
|
+
rescue => e
|
48
|
+
errors.add(:base, _("Failed to execute state.highstate: %s") % e)
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_hostgroup_defaults_with_salt_proxy
|
53
|
+
return unless hostgroup
|
54
|
+
assign_hostgroup_attributes(%w{salt_proxy_id})
|
55
|
+
set_hostgroup_defaults_without_salt_proxy
|
56
|
+
end
|
57
|
+
|
58
|
+
def smart_proxy_ids_with_salt_proxy
|
59
|
+
ids = smart_proxy_ids_without_salt_proxy
|
60
|
+
[salt_proxy, hostgroup.try(:salt_proxy)].compact.each do |proxy|
|
61
|
+
ids << proxy.id
|
62
|
+
end
|
63
|
+
ids
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module ForemanSalt
|
2
|
+
module Concerns
|
3
|
+
module HostgroupExtensions
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
has_and_belongs_to_many :salt_modules, :class_name => "ForemanSalt::SaltModule"
|
8
|
+
belongs_to :salt_proxy, :class_name => "SmartProxy"
|
9
|
+
belongs_to :salt_environment, :class_name => "ForemanSalt::SaltEnvironment"
|
10
|
+
end
|
11
|
+
|
12
|
+
def salt_modules
|
13
|
+
return super unless ancestry.present?
|
14
|
+
([super] + [inherited_salt_modules]).flatten.uniq.compact
|
15
|
+
end
|
16
|
+
|
17
|
+
def salt_module_ids
|
18
|
+
return super unless ancestry.present?
|
19
|
+
([super] + [inherited_salt_module_ids]).flatten.uniq.compact
|
20
|
+
end
|
21
|
+
|
22
|
+
def inherited_salt_modules
|
23
|
+
ForemanSalt::SaltModule.where(:id => inherited_salt_module_ids)
|
24
|
+
end
|
25
|
+
|
26
|
+
def inherited_salt_module_ids
|
27
|
+
if ancestry.present?
|
28
|
+
self.class.sort_by_ancestry(ancestors.reject { |ancestor| ancestor.salt_module_ids.empty? }).last.try(:salt_modules)
|
29
|
+
else
|
30
|
+
[]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def salt_proxy
|
35
|
+
return super unless ancestry.present?
|
36
|
+
SmartProxy.find_by_id(inherited_salt_proxy_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def inherited_salt_proxy_id
|
40
|
+
if ancestry.present?
|
41
|
+
read_attribute(:salt_proxy_id) || self.class.sort_by_ancestry(ancestors.where("salt_proxy_id is not NULL")).last.try(:salt_proxy_id)
|
42
|
+
else
|
43
|
+
self.salt_proxy_id
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def salt_environment
|
48
|
+
return super unless ancestry.present?
|
49
|
+
ForemanSalt::SaltEnvironment.find_by_id(inherited_salt_environment_id)
|
50
|
+
end
|
51
|
+
|
52
|
+
def inherited_salt_environment_id
|
53
|
+
if ancestry.present?
|
54
|
+
read_attribute(:salt_environment_id) || self.class.sort_by_ancestry(ancestors.where("salt_environment_id is not NULL")).last.try(:salt_environment_id)
|
55
|
+
else
|
56
|
+
self.salt_environment_id
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def salt_master
|
61
|
+
salt_proxy.to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module ForemanSalt
|
2
|
+
module Concerns
|
3
|
+
module Orchestration
|
4
|
+
module Salt
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
include ::Orchestration
|
7
|
+
|
8
|
+
included do
|
9
|
+
after_validation :queue_salt_autosign
|
10
|
+
before_destroy :queue_salt_destroy
|
11
|
+
end
|
12
|
+
|
13
|
+
def salt?
|
14
|
+
name.present? && salt_proxy.present?
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize_salt
|
18
|
+
@salt_api ||= ProxyAPI::Salt.new :url => salt_proxy.url
|
19
|
+
end
|
20
|
+
|
21
|
+
def queue_salt_autosign
|
22
|
+
return unless salt? && errors.empty?
|
23
|
+
new_record? ? queue_salt_autosign_create : queue_salt_autosign_update
|
24
|
+
end
|
25
|
+
|
26
|
+
def queue_salt_autosign_create
|
27
|
+
# do nothing - we'll set autosign at the last second: when a host requests a provision URL
|
28
|
+
end
|
29
|
+
|
30
|
+
def queue_salt_autosign_update
|
31
|
+
# Host has been built --> remove auto sign
|
32
|
+
if old.build? and !build?
|
33
|
+
queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def queue_salt_destroy
|
38
|
+
return unless salt? && errors.empty?
|
39
|
+
queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
|
40
|
+
queue.create(:name => _("Delete existing salt key for %s") % self, :priority => 50, :action => [self, :salt_key_delete])
|
41
|
+
end
|
42
|
+
|
43
|
+
def queue_salt_autosign_remove
|
44
|
+
return unless salt? && errors.empty?
|
45
|
+
queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
|
46
|
+
end
|
47
|
+
|
48
|
+
def salt_autosign_create
|
49
|
+
logger.info "Create autosign entry for #{name}"
|
50
|
+
initialize_salt
|
51
|
+
salt_key_delete # if there's already an existing key
|
52
|
+
@salt_api.autosign_create name
|
53
|
+
rescue => e
|
54
|
+
failure _("Failed to create %{name}'s Salt autosign entry: %{e}") % { :name => name, :e => e }
|
55
|
+
end
|
56
|
+
|
57
|
+
def salt_autosign_remove
|
58
|
+
logger.info "Remove autosign entry for #{name}"
|
59
|
+
initialize_salt
|
60
|
+
@salt_api.autosign_remove name
|
61
|
+
rescue => e
|
62
|
+
failure _("Failed to remove %{name}'s Salt autosign entry: %{e}") % { :name => name, :e => e }
|
63
|
+
end
|
64
|
+
|
65
|
+
def salt_key_delete
|
66
|
+
logger.info "Delete salt key for #{name}"
|
67
|
+
initialize_salt
|
68
|
+
@salt_api.key_delete name
|
69
|
+
rescue => e
|
70
|
+
failure _("Failed to delete %{name}'s Salt key: %{e}") % { :name => name, :e => e }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/db/seeds.d/75-salt-seeds.rb
CHANGED
@@ -1,31 +1,11 @@
|
|
1
1
|
# Create feature for Smart Proxy
|
2
2
|
Feature.find_or_create_by_name("Salt")
|
3
3
|
|
4
|
-
# Seed our permissions
|
5
|
-
permissions = [
|
6
|
-
%w(Host saltrun_hosts),
|
7
|
-
%w(Host view_hosts),
|
8
|
-
%w(ForemanSalt::SaltModule create_salt_modules),
|
9
|
-
%w(ForemanSalt::SaltModule view_salt_modules),
|
10
|
-
%w(ForemanSalt::SaltModule edit_salt_modules),
|
11
|
-
%w(ForemanSalt::SaltModule destroy_salt_modules),
|
12
|
-
%w(SmartProxy view_smart_proxies_salt_keys),
|
13
|
-
%w(SmartProxy destroy_smart_proxies_salt_keys),
|
14
|
-
%w(SmartProxy edit_smart_proxies_salt_keys),
|
15
|
-
%w(SmartProxy destroy_smart_proxies_salt_autosign),
|
16
|
-
%w(SmartProxy create_smart_proxies_salt_autosign),
|
17
|
-
%w(SmartProxy view_smart_proxies_salt_autosign),
|
18
|
-
]
|
19
|
-
|
20
|
-
permissions.each do |resource, permission|
|
21
|
-
Permission.find_or_create_by_resource_type_and_name resource, permission
|
22
|
-
end
|
23
|
-
|
24
4
|
# Add new viewing permissions to Viewer role
|
25
5
|
viewer = Role.find_by_name('Viewer')
|
26
6
|
|
27
7
|
if viewer
|
28
|
-
[:view_smart_proxies_salt_keys, :view_smart_proxies_salt_autosign, :view_salt_modules].each do |permission|
|
29
|
-
viewer.add_permissions!([permission]) unless viewer.permissions.include?
|
8
|
+
Permission.where(:name => [:view_smart_proxies_salt_keys, :view_smart_proxies_salt_autosign, :view_salt_modules]).each do |permission|
|
9
|
+
viewer.add_permissions!([permission.name]) unless viewer.permissions.include? permission
|
30
10
|
end
|
31
11
|
end
|
data/lib/foreman_salt/engine.rb
CHANGED
@@ -17,7 +17,7 @@ module ForemanSalt
|
|
17
17
|
|
18
18
|
initializer 'foreman_salt.register_plugin', :after=> :finisher_hook do |app|
|
19
19
|
Foreman::Plugin.register :foreman_salt do
|
20
|
-
requires_foreman '>= 1.
|
20
|
+
requires_foreman '>= 1.7'
|
21
21
|
|
22
22
|
menu :top_menu, :salt_environments,
|
23
23
|
:url_hash => {:controller => :'foreman_salt/salt_environments', :action => :index },
|
@@ -84,7 +84,7 @@ module ForemanSalt
|
|
84
84
|
|
85
85
|
# Model Extensions
|
86
86
|
::Host::Managed.send :include, ForemanSalt::Concerns::HostManagedExtensions
|
87
|
-
::Host::Managed.send :include, ForemanSalt::Orchestration::Salt
|
87
|
+
::Host::Managed.send :include, ForemanSalt::Concerns::Orchestration::Salt
|
88
88
|
::Hostgroup.send :include, ForemanSalt::Concerns::HostgroupExtensions
|
89
89
|
|
90
90
|
# Controller Extensions
|
data/lib/foreman_salt/version.rb
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
FactoryGirl.define do
|
2
|
-
factory :
|
3
|
-
sequence(:name) { |n| "
|
4
|
-
sequence(:url) { |n| "http://proxy#{n}.example.com:9090" }
|
5
|
-
|
6
|
-
trait :with_salt_feature do
|
7
|
-
features { [::Feature.find_or_create_by_name('Salt')] }
|
8
|
-
end
|
2
|
+
factory :salt_module, :class => "ForemanSalt::SaltModule" do
|
3
|
+
sequence(:name) { |n| "module#{n}" }
|
9
4
|
end
|
10
5
|
|
11
|
-
factory :
|
6
|
+
factory :salt_environment, :class => "ForemanSalt::SaltEnvironment" do
|
12
7
|
sequence(:name) { |n| "module#{n}" }
|
13
8
|
end
|
14
9
|
end
|
@@ -29,4 +24,10 @@ FactoryGirl.modify do
|
|
29
24
|
salt_modules { FactoryGirl.create_list :salt_module, 10 }
|
30
25
|
end
|
31
26
|
end
|
27
|
+
|
28
|
+
factory :smart_proxy do
|
29
|
+
trait :with_salt_feature do
|
30
|
+
features { [::Feature.find_or_create_by_name('Salt')] }
|
31
|
+
end
|
32
|
+
end
|
32
33
|
end
|
@@ -6,7 +6,6 @@ class HostsControllerTest < ActionController::TestCase
|
|
6
6
|
Setting[:restrict_registered_puppetmasters] = true
|
7
7
|
Setting[:require_ssl_puppetmasters] = false
|
8
8
|
|
9
|
-
|
10
9
|
proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
|
11
10
|
Resolv.any_instance.stubs(:getnames).returns([proxy.to_s])
|
12
11
|
|
@@ -17,7 +17,7 @@ module ForemanSalt
|
|
17
17
|
test "index page" do
|
18
18
|
visit smart_proxy_salt_autosign_index_path(:smart_proxy_id => @proxy.id)
|
19
19
|
assert find_link('Keys').visible?, "Keys is not visible"
|
20
|
-
assert has_content?("Autosign entries for #{@proxy.
|
20
|
+
assert has_content?("Autosign entries for #{@proxy.hostname}"), "Page title does not appear"
|
21
21
|
assert has_content?("Displaying"), "Pagination 'Display ...' does not appear"
|
22
22
|
end
|
23
23
|
|
@@ -22,7 +22,7 @@ module ForemanSalt
|
|
22
22
|
test "index page" do
|
23
23
|
visit smart_proxy_salt_keys_path(:smart_proxy_id => @proxy.id)
|
24
24
|
assert find_link('Autosign').visible?, "Autosign is not visible"
|
25
|
-
assert has_content?("Salt Keys on #{@proxy.
|
25
|
+
assert has_content?("Salt Keys on #{@proxy.hostname}"), "Page title does not appear"
|
26
26
|
assert has_content?("Displaying"), "Pagination 'Display ...' does not appear"
|
27
27
|
end
|
28
28
|
|
data/test/unit/salt_keys_test.rb
CHANGED
@@ -4,6 +4,9 @@ class SaltKeysTest < ActiveSupport::TestCase
|
|
4
4
|
setup do
|
5
5
|
User.current = User.find_by_login "admin"
|
6
6
|
|
7
|
+
# Fix for 1.8.7 OpenStruct http://stackoverflow.com/questions/9079441/populate-select-tag-ruby-rails
|
8
|
+
OpenStruct.__send__(:define_method, :id) { @table[:id] }
|
9
|
+
|
7
10
|
@proxy = OpenStruct.new(:id => 1, :url => 'http://dummy.example.com:9090')
|
8
11
|
|
9
12
|
ProxyAPI::Salt.any_instance.stubs(:key_list).returns(
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_salt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Benjamin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - <
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - <
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
description: Foreman Plug-in for Salt
|
28
28
|
email:
|
29
29
|
- stephen@redhat.com
|
@@ -54,12 +54,13 @@ files:
|
|
54
54
|
- app/services/foreman_salt/smart_proxies/salt_keys.rb
|
55
55
|
- app/services/foreman_salt/fact_importer.rb
|
56
56
|
- app/models/foreman_salt/salt_module.rb
|
57
|
+
- app/models/foreman_salt/concerns/hostgroup_extensions.rb
|
58
|
+
- app/models/foreman_salt/concerns/host_managed_extensions.rb
|
59
|
+
- app/models/foreman_salt/concerns/orchestration/salt.rb
|
57
60
|
- app/models/foreman_salt/salt_environment.rb
|
58
61
|
- app/models/foreman_salt/fact_name.rb
|
59
|
-
- app/models/concerns/foreman_salt/hostgroup_extensions.rb
|
60
|
-
- app/models/concerns/foreman_salt/host_managed_extensions.rb
|
61
|
-
- app/models/concerns/foreman_salt/orchestration/salt.rb
|
62
62
|
- app/controllers/foreman_salt/salt_modules_controller.rb
|
63
|
+
- app/controllers/foreman_salt/application_controller.rb
|
63
64
|
- app/controllers/foreman_salt/salt_autosign_controller.rb
|
64
65
|
- app/controllers/foreman_salt/salt_keys_controller.rb
|
65
66
|
- app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module ForemanSalt
|
2
|
-
module HostManagedExtensions
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
has_and_belongs_to_many :salt_modules, :class_name => "ForemanSalt::SaltModule", :join_table => "hosts_salt_modules", :foreign_key => "host_id"
|
7
|
-
belongs_to :salt_proxy, :class_name => "SmartProxy"
|
8
|
-
belongs_to :salt_environment, :class_name => "ForemanSalt::SaltEnvironment"
|
9
|
-
alias_method_chain :params, :salt_proxy
|
10
|
-
alias_method_chain :set_hostgroup_defaults, :salt_proxy
|
11
|
-
alias_method_chain :smart_proxy_ids, :salt_proxy
|
12
|
-
end
|
13
|
-
|
14
|
-
def handle_salt
|
15
|
-
return true unless salt?
|
16
|
-
salt_autosign_create
|
17
|
-
end
|
18
|
-
|
19
|
-
def params_with_salt_proxy
|
20
|
-
params = params_without_salt_proxy
|
21
|
-
params["salt_master"] = salt_master unless salt_master.blank?
|
22
|
-
params
|
23
|
-
end
|
24
|
-
|
25
|
-
def salt_modules
|
26
|
-
return super unless hostgroup
|
27
|
-
[super + hostgroup.salt_modules].flatten
|
28
|
-
end
|
29
|
-
|
30
|
-
def salt_module_ids
|
31
|
-
return super unless hostgroup
|
32
|
-
[super + hostgroup.salt_module_ids].flatten
|
33
|
-
end
|
34
|
-
|
35
|
-
def salt_master
|
36
|
-
salt_proxy.to_s
|
37
|
-
end
|
38
|
-
|
39
|
-
def saltrun!
|
40
|
-
unless salt_proxy.present?
|
41
|
-
errors.add(:base, _("No Salt master defined - can't continue"))
|
42
|
-
logger.warn "Unable to execute salt run, no salt proxies defined"
|
43
|
-
return false
|
44
|
-
end
|
45
|
-
ProxyAPI::Salt.new({:url => salt_proxy.url}).highstate name
|
46
|
-
rescue => e
|
47
|
-
errors.add(:base, _("Failed to execute state.highstate: %s") % e)
|
48
|
-
false
|
49
|
-
end
|
50
|
-
|
51
|
-
def set_hostgroup_defaults_with_salt_proxy
|
52
|
-
return unless hostgroup
|
53
|
-
assign_hostgroup_attributes(%w{salt_proxy_id})
|
54
|
-
set_hostgroup_defaults_without_salt_proxy
|
55
|
-
end
|
56
|
-
|
57
|
-
def smart_proxy_ids_with_salt_proxy
|
58
|
-
ids = smart_proxy_ids_without_salt_proxy
|
59
|
-
[salt_proxy, hostgroup.try(:salt_proxy)].compact.each do |proxy|
|
60
|
-
ids << proxy.id
|
61
|
-
end
|
62
|
-
ids
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module ForemanSalt
|
2
|
-
module HostgroupExtensions
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
has_and_belongs_to_many :salt_modules, :class_name => "ForemanSalt::SaltModule"
|
7
|
-
belongs_to :salt_proxy, :class_name => "SmartProxy"
|
8
|
-
belongs_to :salt_environment, :class_name => "ForemanSalt::SaltEnvironment"
|
9
|
-
end
|
10
|
-
|
11
|
-
def salt_modules
|
12
|
-
return super unless ancestry.present?
|
13
|
-
([super] + [inherited_salt_modules]).flatten.uniq.compact
|
14
|
-
end
|
15
|
-
|
16
|
-
def salt_module_ids
|
17
|
-
return super unless ancestry.present?
|
18
|
-
([super] + [inherited_salt_module_ids]).flatten.uniq.compact
|
19
|
-
end
|
20
|
-
|
21
|
-
def inherited_salt_modules
|
22
|
-
ForemanSalt::SaltModule.where(:id => inherited_salt_module_ids)
|
23
|
-
end
|
24
|
-
|
25
|
-
def inherited_salt_module_ids
|
26
|
-
if ancestry.present?
|
27
|
-
self.class.sort_by_ancestry(ancestors.reject { |ancestor| ancestor.salt_module_ids.empty? }).last.try(:salt_modules)
|
28
|
-
else
|
29
|
-
[]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def salt_proxy
|
34
|
-
return super unless ancestry.present?
|
35
|
-
SmartProxy.find_by_id(inherited_salt_proxy_id)
|
36
|
-
end
|
37
|
-
|
38
|
-
def inherited_salt_proxy_id
|
39
|
-
if ancestry.present?
|
40
|
-
read_attribute(:salt_proxy_id) || self.class.sort_by_ancestry(ancestors.where("salt_proxy_id is not NULL")).last.try(:salt_proxy_id)
|
41
|
-
else
|
42
|
-
self.salt_proxy_id
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def salt_environment
|
47
|
-
return super unless ancestry.present?
|
48
|
-
ForemanSalt::SaltEnvironment.find_by_id(inherited_salt_environment_id)
|
49
|
-
end
|
50
|
-
|
51
|
-
def inherited_salt_environment_id
|
52
|
-
if ancestry.present?
|
53
|
-
read_attribute(:salt_environment_id) || self.class.sort_by_ancestry(ancestors.where("salt_environment_id is not NULL")).last.try(:salt_environment_id)
|
54
|
-
else
|
55
|
-
self.salt_environment_id
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def salt_master
|
60
|
-
salt_proxy.to_s
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
module ForemanSalt
|
2
|
-
module Orchestration
|
3
|
-
module Salt
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
include ::Orchestration
|
6
|
-
|
7
|
-
included do
|
8
|
-
after_validation :queue_salt_autosign
|
9
|
-
before_destroy :queue_salt_destroy
|
10
|
-
end
|
11
|
-
|
12
|
-
def salt?
|
13
|
-
name.present? && salt_proxy.present?
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize_salt
|
17
|
-
@salt_api ||= ProxyAPI::Salt.new :url => salt_proxy.url
|
18
|
-
end
|
19
|
-
|
20
|
-
def queue_salt_autosign
|
21
|
-
return unless salt? && errors.empty?
|
22
|
-
new_record? ? queue_salt_autosign_create : queue_salt_autosign_update
|
23
|
-
end
|
24
|
-
|
25
|
-
def queue_salt_autosign_create
|
26
|
-
# do nothing - we'll set autosign at the last second: when a host requests a provision URL
|
27
|
-
end
|
28
|
-
|
29
|
-
def queue_salt_autosign_update
|
30
|
-
# Host has been built --> remove auto sign
|
31
|
-
if old.build? and !build?
|
32
|
-
queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def queue_salt_destroy
|
37
|
-
return unless salt? && errors.empty?
|
38
|
-
queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
|
39
|
-
queue.create(:name => _("Delete existing salt key for %s") % self, :priority => 50, :action => [self, :salt_key_delete])
|
40
|
-
end
|
41
|
-
|
42
|
-
def queue_salt_autosign_remove
|
43
|
-
return unless salt? && errors.empty?
|
44
|
-
queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
|
45
|
-
end
|
46
|
-
|
47
|
-
def salt_autosign_create
|
48
|
-
logger.info "Create autosign entry for #{name}"
|
49
|
-
initialize_salt
|
50
|
-
salt_key_delete # if there's already an existing key
|
51
|
-
@salt_api.autosign_create name
|
52
|
-
rescue => e
|
53
|
-
failure _("Failed to create %{name}'s Salt autosign entry: %{e}") % { :name => name, :e => e }
|
54
|
-
end
|
55
|
-
|
56
|
-
def salt_autosign_remove
|
57
|
-
logger.info "Remove autosign entry for #{name}"
|
58
|
-
initialize_salt
|
59
|
-
@salt_api.autosign_remove name
|
60
|
-
rescue => e
|
61
|
-
failure _("Failed to remove %{name}'s Salt autosign entry: %{e}") % { :name => name, :e => e }
|
62
|
-
end
|
63
|
-
|
64
|
-
def salt_key_delete
|
65
|
-
logger.info "Delete salt key for #{name}"
|
66
|
-
initialize_salt
|
67
|
-
@salt_api.key_delete name
|
68
|
-
rescue => e
|
69
|
-
failure _("Failed to delete %{name}'s Salt key: %{e}") % { :name => name, :e => e }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|