foreman_chef 0.3.1 → 0.4.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/app/assets/javascripts/foreman_chef/chef_proxy_environment_refresh.js +1 -2
- data/app/controllers/foreman_chef/concerns/environment_parameters.rb +19 -0
- data/app/controllers/foreman_chef/environments_controller.rb +4 -2
- data/app/lib/actions/foreman_chef/client/create.rb +36 -0
- data/app/lib/actions/foreman_chef/host/create.rb +51 -0
- data/app/lib/actions/foreman_chef/host/destroy.rb +1 -1
- data/app/lib/proxy_api/foreman_chef/chef_proxy.rb +10 -3
- data/app/models/foreman_chef/concerns/host_action_subject.rb +6 -1
- data/app/models/foreman_chef/concerns/host_and_hostgroup_extensions.rb +0 -2
- data/app/models/foreman_chef/concerns/host_build.rb +14 -0
- data/app/models/foreman_chef/concerns/renderer.rb +4 -0
- data/app/models/foreman_chef/concerns/smart_proxy_extensions.rb +7 -0
- data/app/models/foreman_chef/environment.rb +0 -2
- data/app/models/foreman_chef/fact_name.rb +0 -1
- data/app/models/setting/foreman_chef.rb +2 -1
- data/app/services/foreman_chef/object_exists_exception.rb +4 -0
- data/app/views/foreman/unattended/snippets/_chef_client_bootstrap.erb +6 -1
- data/app/views/foreman_chef/environments/index.html.erb +1 -1
- data/db/migrate/20150916141657_create_chef_environment.rb +1 -1
- data/db/migrate/20160408091653_add_chef_private_key_to_host.rb +5 -0
- data/lib/foreman_chef/engine.rb +7 -3
- data/lib/foreman_chef/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ca6ce84d67a9c71ce00228a2cab0999e53662de
|
4
|
+
data.tar.gz: 97027fe6bc7f56b742a8d568d81a7c047ced35c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e28b20f1dabcfa8e5a82d66214cf4ad5b54ca54e537816967d625bdd1917814ae66a330ede1ac2371ee751cc2f00221d3e78453860af8820b7d791558c767b1b
|
7
|
+
data.tar.gz: 59891a29fe06894f06155574b0ca0f96c42bab8f5b9472481dae3f3fb971083cf07b3c44976c6f56398af6c4644b5981b49655132f57123d6dfa0ef9793e104c
|
@@ -1,4 +1,4 @@
|
|
1
|
-
$(function ()
|
1
|
+
$(document).on('ContentLoad', function (){
|
2
2
|
$("#host_chef_proxy_id, #hostgroup_chef_proxy_id").change(function () {
|
3
3
|
var element = $(this);
|
4
4
|
var attrs = attribute_hash(['chef_proxy_id']);
|
@@ -23,4 +23,3 @@ $(function () {
|
|
23
23
|
});
|
24
24
|
});
|
25
25
|
});
|
26
|
-
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ForemanChef
|
2
|
+
module Concerns
|
3
|
+
module EnvironmentParameters
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def environment_params_filter
|
8
|
+
Foreman::ParameterFilter.new(::ForemanChef::Environment).tap do |filter|
|
9
|
+
filter.permit(:name, :description, :chef_proxy_id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def environment_params
|
15
|
+
self.class.environment_params_filter.filter_params(params, parameter_filter_context, 'foreman_chef_environment')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ForemanChef
|
2
2
|
class EnvironmentsController < ::ForemanChef::ApplicationController
|
3
3
|
include Foreman::Controller::AutoCompleteSearch
|
4
|
+
include ForemanChef::Concerns::EnvironmentParameters
|
5
|
+
|
4
6
|
before_filter :find_resource, :only => [:edit, :update, :destroy]
|
5
7
|
|
6
8
|
def import
|
@@ -34,7 +36,7 @@ module ForemanChef
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def create
|
37
|
-
@environment = ForemanChef::Environment.new(
|
39
|
+
@environment = ForemanChef::Environment.new(environment_params)
|
38
40
|
if @environment.save
|
39
41
|
process_success
|
40
42
|
else
|
@@ -46,7 +48,7 @@ module ForemanChef
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def update
|
49
|
-
if @environment.update_attributes(
|
51
|
+
if @environment.update_attributes(environment_params)
|
50
52
|
process_success
|
51
53
|
else
|
52
54
|
process_error
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanChef
|
3
|
+
module Client
|
4
|
+
class Create < Actions::EntryAction
|
5
|
+
|
6
|
+
def plan(name, proxy)
|
7
|
+
client_exists_in_chef = proxy.show_client(name)
|
8
|
+
if client_exists_in_chef
|
9
|
+
raise ::ForemanChef::ObjectExistsException.new(N_('Client with name %s already exist on this Chef proxy' % name))
|
10
|
+
else
|
11
|
+
plan_self :chef_proxy_id => proxy.id, :name => name
|
12
|
+
end
|
13
|
+
rescue => e
|
14
|
+
Rails.logger.debug "Unable to communicate with Chef proxy, #{e.message}"
|
15
|
+
Rails.logger.debug e.backtrace.join("\n")
|
16
|
+
raise ::ForemanChef::ProxyException.new(N_('CLIENT Unable to communicate with Chef proxy, %s' % e.message))
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
proxy = ::SmartProxy.find_by_id(input[:chef_proxy_id])
|
21
|
+
action_logger.debug "Creating client #{input[:name]} on proxy #{proxy.name} at #{proxy.url}"
|
22
|
+
self.output = proxy.create_client(input[:name])
|
23
|
+
end
|
24
|
+
|
25
|
+
def humanized_name
|
26
|
+
_("Create client")
|
27
|
+
end
|
28
|
+
|
29
|
+
def humanized_input
|
30
|
+
input[:name]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanChef
|
3
|
+
module Host
|
4
|
+
class Create < Actions::EntryAction
|
5
|
+
|
6
|
+
def plan(host)
|
7
|
+
action_subject(host)
|
8
|
+
|
9
|
+
if host.chef_proxy
|
10
|
+
client_exists_in_chef = host.chef_proxy.show_client(host.name)
|
11
|
+
|
12
|
+
sequence do
|
13
|
+
if client_exists_in_chef
|
14
|
+
plan_action Actions::ForemanChef::Client::Destroy, host.name, host.chef_proxy
|
15
|
+
end
|
16
|
+
|
17
|
+
unless ::Setting::ForemanChef.validate_bootstrap_method
|
18
|
+
client_creation = plan_action Actions::ForemanChef::Client::Create, host.name, host.chef_proxy
|
19
|
+
end
|
20
|
+
|
21
|
+
plan_self(:create_action_output => client_creation.output)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
rescue => e
|
25
|
+
Rails.logger.debug "Unable to communicate with Chef proxy, #{e.message}"
|
26
|
+
Rails.logger.debug e.backtrace.join("\n")
|
27
|
+
raise ::ForemanChef::ProxyException.new(N_('Unable to communicate with Chef proxy, %s' % e.message))
|
28
|
+
end
|
29
|
+
|
30
|
+
# def run
|
31
|
+
# # TODO create node with runlist?
|
32
|
+
# end
|
33
|
+
|
34
|
+
def finalize
|
35
|
+
if input[:create_action_output][:private_key].present?
|
36
|
+
::Host.find(self.input[:host][:id]).update_attribute(:chef_private_key, input[:create_action_output][:private_key])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def humanized_name
|
41
|
+
_("Create node")
|
42
|
+
end
|
43
|
+
|
44
|
+
def humanized_input
|
45
|
+
input[:host][:name]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -7,7 +7,7 @@ module Actions
|
|
7
7
|
|
8
8
|
def plan(host)
|
9
9
|
action_subject(host)
|
10
|
-
if (::Setting::ForemanChef.auto_deletion && proxy =
|
10
|
+
if (::Setting::ForemanChef.auto_deletion && proxy = host.chef_proxy)
|
11
11
|
node_exists_in_chef = proxy.show_node(host.name)
|
12
12
|
if node_exists_in_chef
|
13
13
|
plan_self :chef_proxy_id => host.chef_proxy_id
|
@@ -43,14 +43,21 @@ module ProxyAPI
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# Shows a Chef Client entry
|
46
|
-
# [+key+] : String containing the
|
47
|
-
# Returns : Hash representation of
|
46
|
+
# [+key+] : String containing the client name
|
47
|
+
# Returns : Hash representation of client on chef server
|
48
48
|
def show_client(key)
|
49
49
|
Client.new(@args).send(:get, key)
|
50
50
|
end
|
51
51
|
|
52
|
+
# Creates a Chef Client entry
|
53
|
+
# [+key+] : String containing the client name
|
54
|
+
# Returns : Hash representation of client on chef server
|
55
|
+
def create_client(key)
|
56
|
+
Client.new(@args).send(:post, :client => {:name => key})
|
57
|
+
end
|
58
|
+
|
52
59
|
# Deletes a Chef Client entry
|
53
|
-
# [+key+] : String containing the
|
60
|
+
# [+key+] : String containing the client name
|
54
61
|
# Returns : Boolean status
|
55
62
|
def delete_client(key)
|
56
63
|
Client.new(@args).send(:delete, key)
|
@@ -5,6 +5,11 @@ module ForemanChef
|
|
5
5
|
include ForemanTasks::Concerns::ActionSubject
|
6
6
|
include ForemanTasks::Concerns::ActionTriggering
|
7
7
|
|
8
|
+
def create_action
|
9
|
+
sync_action!
|
10
|
+
::Actions::ForemanChef::Host::Create
|
11
|
+
end
|
12
|
+
|
8
13
|
def destroy_action
|
9
14
|
sync_action!
|
10
15
|
::Actions::ForemanChef::Host::Destroy
|
@@ -18,5 +23,5 @@ module ForemanChef
|
|
18
23
|
end
|
19
24
|
|
20
25
|
class ::Host::Managed::Jail < Safemode::Jail
|
21
|
-
allow :chef_proxy, :chef_environment
|
26
|
+
allow :chef_proxy, :chef_environment, :chef_private_key
|
22
27
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ForemanChef
|
2
|
+
module Concerns
|
3
|
+
module HostBuild
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
included do
|
6
|
+
include ForemanTasks::Concerns::ActionSubject
|
7
|
+
include ForemanTasks::Concerns::ActionTriggering
|
8
|
+
|
9
|
+
after_build :plan_destroy_action
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -9,6 +9,10 @@ module ForemanChef
|
|
9
9
|
raise SecurityError, 'snippet contains not white-listed characters' unless snippet_name =~ /\A[a-zA-Z0-9 _-]+\Z/
|
10
10
|
snippet snippet_name
|
11
11
|
end
|
12
|
+
|
13
|
+
def validation_bootstrap_method?
|
14
|
+
::Setting::ForemanChef.validate_bootstrap_method
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
@@ -32,6 +32,13 @@ module ForemanChef
|
|
32
32
|
return false
|
33
33
|
end
|
34
34
|
|
35
|
+
def create_client(fqdn)
|
36
|
+
begin
|
37
|
+
reply = ProxyAPI::ForemanChef::ChefProxy.new(:url => url).create_client(fqdn)
|
38
|
+
JSON.parse(reply)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
35
42
|
def delete_client(fqdn)
|
36
43
|
begin
|
37
44
|
reply = ProxyAPI::ForemanChef::ChefProxy.new(:url => url).delete_client(fqdn)
|
@@ -9,8 +9,6 @@ module ForemanChef
|
|
9
9
|
has_many :hostgroups, :class_name => '::Hostgroup'
|
10
10
|
belongs_to :chef_proxy, :class_name => '::SmartProxy'
|
11
11
|
|
12
|
-
attr_accessible :name, :description, :chef_proxy_id
|
13
|
-
|
14
12
|
validates :name, :uniqueness => true, :presence => true, :format => { :with => /\A[\w\d\.]+\z/, :message => N_('is alphanumeric and cannot contain spaces') }
|
15
13
|
|
16
14
|
scoped_search :on => :name, :complete_value => true
|
@@ -6,7 +6,8 @@ class Setting::ForemanChef < Setting
|
|
6
6
|
|
7
7
|
self.transaction do
|
8
8
|
[
|
9
|
-
self.set('auto_deletion', N_("Enable the auto deletion of mapped objects in chef-server through foreman-proxy (currently node and client upon host deletion)"), true),
|
9
|
+
self.set('auto_deletion', N_("Enable the auto deletion of mapped objects in chef-server through foreman-proxy (currently node and client upon host deletion, client on host rebuild)"), true),
|
10
|
+
self.set('validation_bootstrap_method', N_("Use validation.pem or create client directly storing private key in Foreman DB)"), true),
|
10
11
|
].each { |s| self.create! s.update(:category => "Setting::ForemanChef")}
|
11
12
|
end
|
12
13
|
|
@@ -1,12 +1,17 @@
|
|
1
|
+
<% if validation_bootstrap_method? -%>
|
1
2
|
echo "Creating validation.pem"
|
2
3
|
mkdir /etc/chef
|
3
4
|
touch /etc/chef/validation.pem
|
4
5
|
chmod 600 /etc/chef/validation.pem
|
5
6
|
|
6
|
-
## You need to paste here foreman's private key
|
7
7
|
cat << 'EOF' > /etc/chef/validation.pem
|
8
8
|
<%= @host.params['chef_validation_private_key'] %>
|
9
9
|
EOF
|
10
|
+
<% else -%>
|
11
|
+
cat << 'EOF' > /etc/chef/client.pem
|
12
|
+
<%= @host.chef_private_key %>
|
13
|
+
EOF
|
14
|
+
<% end -%>
|
10
15
|
|
11
16
|
## If chef_server_certificate is present, install it into /etc/chef/trusted_certs
|
12
17
|
<% chef_server_certificate = @host.params['chef_server_certificate'] -%>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
{:class => 'btn btn-default', :"data-no-turbolink" => true})
|
8
8
|
end.flatten)
|
9
9
|
) %>
|
10
|
-
<% title_actions button_group(
|
10
|
+
<% title_actions button_group(new_link(_('New Chef Environment'))) %>
|
11
11
|
|
12
12
|
<table class="table table-bordered table-striped">
|
13
13
|
<tr>
|
@@ -2,7 +2,7 @@ class CreateChefEnvironment < ActiveRecord::Migration
|
|
2
2
|
def up
|
3
3
|
create_table :foreman_chef_environments do |t|
|
4
4
|
t.string :name, :default => '', :null => false
|
5
|
-
t.text :description
|
5
|
+
t.text :description
|
6
6
|
t.integer :chef_proxy_id, :null => false
|
7
7
|
t.timestamps
|
8
8
|
end
|
data/lib/foreman_chef/engine.rb
CHANGED
@@ -45,10 +45,10 @@ module ForemanChef
|
|
45
45
|
ForemanTasks.dynflow.config.eager_load_paths.concat(%W[#{ForemanChef::Engine.root}/app/lib/actions])
|
46
46
|
end
|
47
47
|
|
48
|
-
initializer 'foreman_chef.register_plugin', :
|
48
|
+
initializer 'foreman_chef.register_plugin', :before => :finisher_hook do |app|
|
49
49
|
Foreman::Plugin.register :foreman_chef do
|
50
|
-
requires_foreman '>= 1.
|
51
|
-
allowed_template_helpers :chef_bootstrap
|
50
|
+
requires_foreman '>= 1.13'
|
51
|
+
allowed_template_helpers :chef_bootstrap, :validation_bootstrap_method?
|
52
52
|
|
53
53
|
permission :import_chef_environments, { :environments => [:import, :synchronize] }, :resource_type => 'ForemanChef::Environment'
|
54
54
|
permission :view_chef_environments, { :environments => [:index, :environments_for_chef_proxy] }, :resource_type => 'ForemanChef::Environment'
|
@@ -61,6 +61,9 @@ module ForemanChef
|
|
61
61
|
caption: N_('Environments'),
|
62
62
|
parent: :configure_menu,
|
63
63
|
last: true
|
64
|
+
|
65
|
+
parameter_filter Host::Managed, :chef_private_key, :chef_proxy_id, :chef_environment_id
|
66
|
+
parameter_filter Hostgroup, :chef_proxy_id, :chef_environment_id
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
@@ -85,6 +88,7 @@ module ForemanChef
|
|
85
88
|
::Hostgroup.send :include, ForemanChef::Concerns::HostgroupExtensions
|
86
89
|
::SmartProxy.send :include, ForemanChef::Concerns::SmartProxyExtensions
|
87
90
|
::Host::Base.send :include, ForemanChef::Concerns::HostActionSubject
|
91
|
+
::Host::Managed.send :include, ForemanChef::Concerns::HostBuild
|
88
92
|
::HostsController.send :include, ForemanChef::Concerns::HostsControllerRescuer
|
89
93
|
# Renderer Concern needs to be injected to controllers, ForemanRenderer was already included
|
90
94
|
(TemplatesController.descendants + [TemplatesController]).each do |klass|
|
data/lib/foreman_chef/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_chef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Hulan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|
@@ -29,9 +29,6 @@ dependencies:
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.6.9
|
34
|
-
- - "<"
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: 0.8.0
|
37
34
|
type: :runtime
|
@@ -39,9 +36,6 @@ dependencies:
|
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 0.6.9
|
44
|
-
- - "<"
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: 0.8.0
|
47
41
|
- !ruby/object:Gem::Dependency
|
@@ -70,14 +64,18 @@ files:
|
|
70
64
|
- Rakefile
|
71
65
|
- app/assets/javascripts/foreman_chef/chef_proxy_environment_refresh.js
|
72
66
|
- app/controllers/foreman_chef/application_controller.rb
|
67
|
+
- app/controllers/foreman_chef/concerns/environment_parameters.rb
|
73
68
|
- app/controllers/foreman_chef/concerns/hosts_controller_rescuer.rb
|
74
69
|
- app/controllers/foreman_chef/environments_controller.rb
|
75
70
|
- app/helpers/foreman_chef/chef_proxy_form.rb
|
71
|
+
- app/lib/actions/foreman_chef/client/create.rb
|
76
72
|
- app/lib/actions/foreman_chef/client/destroy.rb
|
73
|
+
- app/lib/actions/foreman_chef/host/create.rb
|
77
74
|
- app/lib/actions/foreman_chef/host/destroy.rb
|
78
75
|
- app/lib/proxy_api/foreman_chef/chef_proxy.rb
|
79
76
|
- app/models/foreman_chef/concerns/host_action_subject.rb
|
80
77
|
- app/models/foreman_chef/concerns/host_and_hostgroup_extensions.rb
|
78
|
+
- app/models/foreman_chef/concerns/host_build.rb
|
81
79
|
- app/models/foreman_chef/concerns/host_extensions.rb
|
82
80
|
- app/models/foreman_chef/concerns/hostgroup_extensions.rb
|
83
81
|
- app/models/foreman_chef/concerns/renderer.rb
|
@@ -89,6 +87,7 @@ files:
|
|
89
87
|
- app/models/setting/foreman_chef.rb
|
90
88
|
- app/overrides/add_chef_proxy.rb
|
91
89
|
- app/services/foreman_chef/chef_server_importer.rb
|
90
|
+
- app/services/foreman_chef/object_exists_exception.rb
|
92
91
|
- app/services/foreman_chef/proxy_exception.rb
|
93
92
|
- app/views/foreman/unattended/snippets/_chef_client_bootstrap.erb
|
94
93
|
- app/views/foreman/unattended/snippets/_chef_client_gem_bootstrap.erb
|
@@ -103,6 +102,7 @@ files:
|
|
103
102
|
- db/migrate/20140220145827_add_chef_proxy_id_to_host.rb
|
104
103
|
- db/migrate/20140513144804_add_chef_proxy_id_to_hostgroup.rb
|
105
104
|
- db/migrate/20150916141657_create_chef_environment.rb
|
105
|
+
- db/migrate/20160408091653_add_chef_private_key_to_host.rb
|
106
106
|
- db/seeds.rb
|
107
107
|
- lib/foreman_chef.rb
|
108
108
|
- lib/foreman_chef/engine.rb
|