puppetdb_foreman 4.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -23
- data/Rakefile +9 -6
- data/app/controllers/api/v2/puppetdb_nodes_controller.rb +8 -6
- data/app/controllers/puppetdb_foreman/nodes_controller.rb +32 -7
- data/app/helpers/concerns/puppetdb_foreman/hosts_helper_extensions.rb +28 -0
- data/app/models/concerns/orchestration/puppetdb.rb +13 -6
- data/app/models/puppetdb_foreman/host_extensions.rb +5 -4
- data/app/services/puppetdb.rb +8 -12
- data/app/services/puppetdb_client/base.rb +12 -6
- data/app/services/puppetdb_client/v4.rb +48 -1
- data/app/services/puppetdb_host.rb +5 -3
- data/app/views/api/v2/puppetdb_nodes/import.json.rabl +2 -0
- data/app/views/api/v2/puppetdb_nodes/index.json.rabl +2 -0
- data/app/views/api/v2/puppetdb_nodes/unknown.json.rabl +2 -0
- data/app/views/puppetdb_foreman/nodes/index.html.erb +1 -0
- data/app/views/puppetdb_foreman/nodes/show.html.erb +69 -0
- data/config/routes.rb +11 -11
- data/db/migrate/20170717140010_migrate_puppetdb_api_version_setting.rb +4 -2
- data/db/migrate/20181001113836_remove_puppetdb_dashboard_address_setting.puppetdb_foreman.rb +7 -0
- data/lib/puppetdb_foreman/engine.rb +58 -33
- data/lib/puppetdb_foreman/version.rb +3 -1
- data/lib/puppetdb_foreman.rb +2 -0
- data/lib/tasks/puppetdb_foreman_tasks.rake +4 -4
- data/test/controllers/api/v2/puppetdb_nodes_controller_test.rb +60 -55
- data/test/controllers/nodes_controller_test.rb +34 -9
- data/test/models/host_test.rb +5 -4
- data/test/static_fixtures/resources.json +41 -0
- data/test/test_plugin_helper.rb +2 -4
- data/test/unit/puppetdb_host_test.rb +5 -4
- data/test/unit/puppetdb_test.rb +34 -85
- metadata +20 -23
- data/app/controllers/puppetdb_foreman/puppetdb_controller.rb +0 -30
- data/app/models/setting/puppetdb.rb +0 -52
- data/app/services/puppetdb_client/v1.rb +0 -29
- data/app/services/puppetdb_client/v3.rb +0 -45
- data/app/views/puppetdb_foreman/puppetdb/error.html.erb +0 -6
- data/test/static_fixtures/query_nodes.json +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2917867afdc2d20921a278f2c2fb35aa90ee71ad3ceca28cbfb6fbff4d087bd9
|
4
|
+
data.tar.gz: 3f6bd9d01c00bd9007220a95b1c0752c938cbbad24c01c670f03ae79e80fd6a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 424fd00c14417f01cc1ae6eac59d468bb6b32048f5fbd2f0e646319182500a8b46349f31d2797d87efb578d86704eed14cb42710bf25097334993118a335c904
|
7
|
+
data.tar.gz: 0e0ad581dbecf0ce351bb50e8fd88c348e080b64a812c82cb933da13c60a9006f681ba1bcdc6229987e36b96d5d37719895eb7be81c685a15ddb5ec1c8630121
|
data/README.md
CHANGED
@@ -2,15 +2,12 @@
|
|
2
2
|
|
3
3
|
[![Code Climate](https://codeclimate.com/github/theforeman/puppetdb_foreman/badges/gpa.svg)](https://codeclimate.com/github/theforeman/puppetdb_foreman)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/puppetdb_foreman.svg)](http://badge.fury.io/rb/puppetdb_foreman)
|
5
|
-
[![Dependency Status](https://gemnasium.com/theforeman/puppetdb_foreman.svg)](https://gemnasium.com/theforeman/puppetdb_foreman)
|
6
|
-
[![Issue stats](http://issuestats.com/github/theforeman/puppetdb_foreman/badge/pr?style=flat)](http://issuestats.com/github/theforeman/puppetdb_foreman)
|
7
5
|
|
8
6
|
This is a [Foreman](http://theforeman.org) plugin to interact with [PuppetDB](https://docs.puppetlabs.com/puppetdb/index.html).
|
9
7
|
|
10
8
|
It does the following:
|
11
9
|
|
12
10
|
* Disables hosts on PuppetDB after they are deleted in Foreman.
|
13
|
-
* Proxies the PuppetDB Performance Dashboard for access through Foreman.
|
14
11
|
* Compares nodes in PuppetDB to Hosts in Foreman.
|
15
12
|
* Creates Hosts in Foreman from PuppetDB facts.
|
16
13
|
|
@@ -21,6 +18,8 @@ Feel free to raise issues, ask for features, anything, in the github repository
|
|
21
18
|
| Foreman Version | Plugin Version |
|
22
19
|
| --------------- | -------------- |
|
23
20
|
| >= 1.17 | ~> 4.0.0 |
|
21
|
+
| >= 1.20 | ~> 5.0.0 |
|
22
|
+
| >= 3.1 | ~> 6.0.0 |
|
24
23
|
|
25
24
|
# Installation:
|
26
25
|
|
@@ -51,26 +50,7 @@ puppetdb_foreman uses [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.
|
|
51
50
|
|
52
51
|
# Usage:
|
53
52
|
|
54
|
-
Go to Administer > Settings > PuppetDB and set `puppetdb_address` with your PuppetDB address, `
|
55
|
-
|
56
|
-
Alternatively you can put your settings in `config/settings.yaml`. Please keep in mind these will be overwritten if changed in the application, and if the application is rebooted, YAML rules will overwrite again your manually changed settings. Hence passing your settings in this format is discouraged, but allowed.
|
57
|
-
|
58
|
-
for PuppetDB 4
|
59
|
-
```yaml
|
60
|
-
:puppetdb:
|
61
|
-
:enabled: true
|
62
|
-
:address: 'https://puppetdb:8081/pdb/cmd/v1'
|
63
|
-
:dashboard_address: 'http://puppetdb:8080/pdb/dashboard'
|
64
|
-
:ssl_ca_file: '/etc/puppetlabs/puppet/ssl/certs/ca.pem'
|
65
|
-
:ssl_certificate: '/etc/puppetlabs/puppet/ssl/certs/FQDN.pem'
|
66
|
-
:ssl_private_key: '/etc/puppetlabs/puppet/ssl/private_keys/FQDN.pem'
|
67
|
-
:api_version: 4
|
68
|
-
```
|
69
|
-
|
70
|
-
You can find the dashboard under Monitor > PuppetDB dashboard. Only administrators and users with a role `view_puppetdb_dashboard` will be able to access it. Aside from convenience, the PuppetDB dashboard cannot be served over HTTPS, you can restrict your dashboard requests to only Foreman boxes and serve it securely to your users through HTTPS in Foreman.
|
71
|
-
|
72
|
-
![Screenshot](http://i.imgur.com/5d80CtZ.png)
|
73
|
-
|
53
|
+
Go to Administer > Settings > PuppetDB and set `puppetdb_address` with your PuppetDB address, `puppetdb_enabled` to either true or false if you want to enable or disable PuppetDB integration. Obviously you will need a PuppetDB instance at the address you provide.
|
74
54
|
|
75
55
|
# Copyright:
|
76
56
|
Copyright 2013 CERN, Switzerland and various authors
|
data/Rakefile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
begin
|
3
5
|
require 'bundler/setup'
|
4
6
|
rescue LoadError
|
@@ -20,7 +22,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
23
|
end
|
22
24
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
25
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
24
26
|
|
25
27
|
Bundler::GemHelper.install_tasks
|
26
28
|
|
@@ -37,11 +39,12 @@ task default: :test
|
|
37
39
|
|
38
40
|
begin
|
39
41
|
require 'rubocop/rake_task'
|
40
|
-
|
41
|
-
rescue => _
|
42
|
+
rescue StandardError
|
42
43
|
puts 'Rubocop not loaded.'
|
43
|
-
|
44
|
+
else
|
45
|
+
RuboCop::RakeTask.new
|
44
46
|
|
45
|
-
task :default do
|
46
|
-
|
47
|
+
task :default do
|
48
|
+
Rake::Task['rubocop'].execute
|
49
|
+
end
|
47
50
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Api
|
2
4
|
module V2
|
3
5
|
class PuppetdbNodesController < V2::BaseController
|
4
6
|
include Api::Version2
|
5
|
-
before_action :find_node, :
|
7
|
+
before_action :find_node, only: %i[destroy import]
|
6
8
|
|
7
|
-
layout 'api/v2/layouts/index_layout', :
|
9
|
+
layout 'api/v2/layouts/index_layout', only: %i[index unknown]
|
8
10
|
|
9
11
|
api :GET, '/puppetdb_nodes/', N_('List all PuppetDB nodes')
|
10
12
|
def index
|
@@ -19,20 +21,20 @@ module Api
|
|
19
21
|
end
|
20
22
|
|
21
23
|
api :DELETE, '/puppetdb_nodes/:id/', N_('Deactivate a node in PuppetDB')
|
22
|
-
param :id, String, :
|
24
|
+
param :id, String, required: true
|
23
25
|
|
24
26
|
def destroy
|
25
27
|
uuid = Puppetdb.client.deactivate_node(@node)
|
26
|
-
response = { :
|
28
|
+
response = { job: { uuid: uuid } }
|
27
29
|
process_success response
|
28
30
|
end
|
29
31
|
|
30
32
|
api :PUT, '/puppetdb_nodes/:id/import/', N_('Import PuppetDB Node to Foreman Host')
|
31
|
-
param :id, :identifier, :
|
33
|
+
param :id, :identifier, required: true
|
32
34
|
|
33
35
|
def import
|
34
36
|
facts = Puppetdb.client.facts(@node)
|
35
|
-
@host = PuppetdbHost.new(:
|
37
|
+
@host = PuppetdbHost.new(facts: facts).to_host
|
36
38
|
end
|
37
39
|
|
38
40
|
# Overrides because PuppetDB is not backed by ActiveRecord
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbForeman
|
2
4
|
class NodesController < ApplicationController
|
3
|
-
before_action :find_node, :
|
5
|
+
before_action :find_node, only: %i[show destroy import]
|
4
6
|
|
5
7
|
def controller_permission
|
6
8
|
'puppetdb_nodes'
|
@@ -12,19 +14,42 @@ module PuppetdbForeman
|
|
12
14
|
@unknown_hosts = @puppetdb_hosts - @foreman_hosts
|
13
15
|
end
|
14
16
|
|
17
|
+
def show # rubocop:disable Metrics/AbcSize
|
18
|
+
response = Puppetdb.client.resources(@node)
|
19
|
+
|
20
|
+
class_names = response.map { |v| v['title'] if v['type'] == 'Class' }.compact
|
21
|
+
|
22
|
+
@classes_count = class_names.count
|
23
|
+
@classes = class_names.paginate(page: params[:page], per_page: params[:per_page])
|
24
|
+
|
25
|
+
@type_names = response.map { |v| v['type'] }.uniq
|
26
|
+
end
|
27
|
+
|
15
28
|
def destroy
|
16
29
|
Puppetdb.client.deactivate_node(@node)
|
17
|
-
process_success
|
30
|
+
process_success(
|
31
|
+
success_msg: _('Deactivated node %s in PuppetDB') % @node,
|
32
|
+
success_redirect: puppetdb_foreman_nodes_path
|
33
|
+
)
|
18
34
|
rescue StandardError => e
|
19
|
-
process_error(
|
35
|
+
process_error(
|
36
|
+
redirect: puppetdb_foreman_nodes_path,
|
37
|
+
error_msg: _('Failed to deactivate node in PuppetDB: %s') % e.message
|
38
|
+
)
|
20
39
|
end
|
21
40
|
|
22
|
-
def import
|
41
|
+
def import # rubocop:disable Metrics/MethodLength
|
23
42
|
facts = Puppetdb.client.facts(@node)
|
24
|
-
host = PuppetdbHost.new(:
|
25
|
-
process_success
|
43
|
+
host = PuppetdbHost.new(facts: facts).to_host
|
44
|
+
process_success(
|
45
|
+
success_msg: _('Imported host %s from PuppetDB') % @node,
|
46
|
+
success_redirect: host_path(id: host)
|
47
|
+
)
|
26
48
|
rescue StandardError => e
|
27
|
-
process_error(
|
49
|
+
process_error(
|
50
|
+
redirect: puppetdb_foreman_nodes_path,
|
51
|
+
error_msg: _('Failed to import host from PuppetDB: %s') % e.message
|
52
|
+
)
|
28
53
|
end
|
29
54
|
|
30
55
|
private
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PuppetdbForeman
|
4
|
+
module HostsHelperExtensions
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module Overrides
|
8
|
+
def show_appropriate_host_buttons(host)
|
9
|
+
buttons = super
|
10
|
+
|
11
|
+
if host.puppet_proxy_id?
|
12
|
+
buttons << link_to_if_authorized(
|
13
|
+
_('Puppet Classes'),
|
14
|
+
hash_for_puppetdb_foreman_node_path(id: host.name),
|
15
|
+
title: _('Browse host puppet classes'),
|
16
|
+
class: 'btn btn-default'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
buttons.compact
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
included do
|
25
|
+
prepend Overrides
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Orchestration
|
2
4
|
module Puppetdb
|
3
5
|
extend ActiveSupport::Concern
|
@@ -10,18 +12,23 @@ module Orchestration
|
|
10
12
|
|
11
13
|
def queue_puppetdb_destroy
|
12
14
|
return unless ::Puppetdb.ready? && errors.empty?
|
13
|
-
queue.create(
|
14
|
-
|
15
|
+
queue.create(
|
16
|
+
name: _('Deactivating node %s in PuppetDB') % self,
|
17
|
+
priority: 60,
|
18
|
+
action: [self, :del_puppetdb]
|
19
|
+
)
|
15
20
|
end
|
16
21
|
|
17
|
-
def
|
22
|
+
def del_puppetdb
|
18
23
|
Rails.logger.info "Deactivating node in PuppetDB: #{name}"
|
19
24
|
::Puppetdb.client.deactivate_node(name)
|
20
25
|
rescue StandardError => e
|
21
|
-
failure
|
22
|
-
|
26
|
+
failure format(
|
27
|
+
_("Failed to deactivate node %<name>s in PuppetDB: %<message>s\n "), name: name, message: e.message
|
28
|
+
), e
|
23
29
|
end
|
24
30
|
|
25
|
-
def
|
31
|
+
def set_puppetdb
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbForeman
|
2
4
|
module HostExtensions
|
3
5
|
extend ActiveSupport::Concern
|
@@ -7,20 +9,19 @@ module PuppetdbForeman
|
|
7
9
|
after_build :deactivate_host
|
8
10
|
end
|
9
11
|
|
10
|
-
def deactivate_host
|
12
|
+
def deactivate_host # rubocop:disable Metrics/MethodLength
|
11
13
|
logger.debug "Deactivating host #{name} in PuppetDB"
|
12
14
|
return true unless Puppetdb.enabled?
|
13
15
|
|
14
16
|
unless Puppetdb.configured?
|
15
|
-
errors.add(:base,
|
16
|
-
_('PuppetDB plugin is enabled but not configured. Please configure it before trying to delete a host.'))
|
17
|
+
errors.add(:base, _('PuppetDB plugin is enabled but not configured. Please configure it before trying to delete a host.')) # rubocop:disable Layout/LineLength
|
17
18
|
end
|
18
19
|
|
19
20
|
begin
|
20
21
|
Puppetdb.client.deactivate_node(name)
|
21
22
|
rescue StandardError => e
|
22
23
|
errors.add(:base, _("Could not deactivate host on PuppetDB: #{e}"))
|
23
|
-
|
24
|
+
false
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
data/app/services/puppetdb.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Puppetdb
|
2
4
|
API_VERSIONS = {
|
3
|
-
'4' => 'v4: PuppetDB 4
|
4
|
-
'3' => 'v3: PuppetDB 3.0, 3.1, 3.2',
|
5
|
-
'1' => 'v1: PuppetDB 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1, 2.2, 2.3'
|
5
|
+
'4' => 'v4: PuppetDB 4 - 7',
|
6
6
|
}.freeze
|
7
7
|
|
8
|
-
def self.client
|
8
|
+
def self.client # rubocop:disable Metrics/MethodLength
|
9
9
|
options = {
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
10
|
+
uri: uri,
|
11
|
+
ssl_ca_file: Setting[:puppetdb_ssl_ca_file],
|
12
|
+
ssl_certificate_file: Setting[:puppetdb_ssl_certificate],
|
13
|
+
ssl_private_key_file: Setting[:puppetdb_ssl_private_key],
|
14
14
|
}
|
15
15
|
|
16
16
|
case api_version
|
17
|
-
when 1
|
18
|
-
PuppetdbClient::V1.new(options)
|
19
|
-
when 3
|
20
|
-
PuppetdbClient::V3.new(options)
|
21
17
|
when 4
|
22
18
|
PuppetdbClient::V4.new(options)
|
23
19
|
else
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbClient
|
2
4
|
class Base
|
3
|
-
delegate :logger, :
|
5
|
+
delegate :logger, to: :Rails
|
4
6
|
attr_reader :uri, :ssl_ca_file, :ssl_certificate_file, :ssl_private_key_file
|
5
7
|
|
6
8
|
def initialize(opts)
|
@@ -25,6 +27,10 @@ module PuppetdbClient
|
|
25
27
|
parse(get(facts_url, query: "[\"=\", \"certname\", \"#{nodename}\"]"))
|
26
28
|
end
|
27
29
|
|
30
|
+
def resources(nodename)
|
31
|
+
parse(get(resources_url, query: "[\"=\", \"certname\", \"#{nodename}\"]"))
|
32
|
+
end
|
33
|
+
|
28
34
|
private
|
29
35
|
|
30
36
|
def connection(url)
|
@@ -62,13 +68,13 @@ module PuppetdbClient
|
|
62
68
|
|
63
69
|
def request_options
|
64
70
|
{
|
65
|
-
headers: request_headers
|
71
|
+
headers: request_headers,
|
66
72
|
}.merge(auth_options).merge(ssl_options)
|
67
73
|
end
|
68
74
|
|
69
75
|
def request_headers
|
70
76
|
{
|
71
|
-
'Accept' => 'application/json'
|
77
|
+
'Accept' => 'application/json',
|
72
78
|
}
|
73
79
|
end
|
74
80
|
|
@@ -76,11 +82,11 @@ module PuppetdbClient
|
|
76
82
|
if ssl_ca_file
|
77
83
|
{
|
78
84
|
ssl_ca_file: ssl_ca_file,
|
79
|
-
verify_ssl: true
|
85
|
+
verify_ssl: true,
|
80
86
|
}
|
81
87
|
else
|
82
88
|
{
|
83
|
-
verify_ssl: false
|
89
|
+
verify_ssl: false,
|
84
90
|
}
|
85
91
|
end
|
86
92
|
end
|
@@ -89,7 +95,7 @@ module PuppetdbClient
|
|
89
95
|
return {} unless certificate_request?
|
90
96
|
{
|
91
97
|
ssl_client_cert: ssl_certificate,
|
92
|
-
ssl_client_key: ssl_private_key
|
98
|
+
ssl_client_key: ssl_private_key,
|
93
99
|
}
|
94
100
|
end
|
95
101
|
|
@@ -1,4 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbClient
|
2
|
-
class V4 <
|
4
|
+
class V4 < Base
|
5
|
+
# The payload is formatted as a JSON map.
|
6
|
+
# certname: The name of the node for which the catalog was compiled.
|
7
|
+
# producer_timestamp: The time of command submission.
|
8
|
+
def deactivate_node_payload(nodename)
|
9
|
+
{
|
10
|
+
'command' => 'deactivate node',
|
11
|
+
'version' => 3,
|
12
|
+
'payload' => {
|
13
|
+
'certname' => nodename,
|
14
|
+
'producer_timestamp' => producer_timestamp,
|
15
|
+
},
|
16
|
+
}.to_json
|
17
|
+
end
|
18
|
+
|
19
|
+
def command_url
|
20
|
+
'/pdb/cmd/v1'
|
21
|
+
end
|
22
|
+
|
23
|
+
def nodes_url
|
24
|
+
'/pdb/query/v4/nodes'
|
25
|
+
end
|
26
|
+
|
27
|
+
def facts_url
|
28
|
+
'/pdb/query/v4/facts'
|
29
|
+
end
|
30
|
+
|
31
|
+
def resources_url
|
32
|
+
'/pdb/query/v4/resources'
|
33
|
+
end
|
34
|
+
|
35
|
+
def query_nodes
|
36
|
+
super.map { |node| node['certname'] }
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def post_options
|
42
|
+
{
|
43
|
+
content_type: :json,
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def producer_timestamp
|
48
|
+
Time.now.iso8601.to_s
|
49
|
+
end
|
3
50
|
end
|
4
51
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class PuppetdbHost
|
2
4
|
attr_accessor :certname, :environment, :facts
|
3
5
|
|
@@ -7,9 +9,9 @@ class PuppetdbHost
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def to_host
|
10
|
-
host = Host::Managed.import_host(facts[:fqdn],
|
11
|
-
host.import_facts(facts)
|
12
|
-
host.update_attribute(:
|
12
|
+
host = Host::Managed.import_host(facts[:fqdn], certname)
|
13
|
+
HostFactImporter.new(host).import_facts(facts)
|
14
|
+
host.update_attribute(environment: environment) if environment # rubocop:disable Rails/SkipsModelValidations
|
13
15
|
host
|
14
16
|
end
|
15
17
|
|
@@ -51,6 +51,7 @@
|
|
51
51
|
<td class="ellipsis"><%= node %></td>
|
52
52
|
<td>
|
53
53
|
<%= action_buttons(
|
54
|
+
(display_link_if_authorized(_("Puppet Classes"), hash_for_puppetdb_foreman_node_path(:id => node), :method => :get)),
|
54
55
|
(display_link_if_authorized(_("Import"), hash_for_import_puppetdb_foreman_node_path(:id => node), :method => :put)),
|
55
56
|
(display_delete_if_authorized(hash_for_puppetdb_foreman_node_path(:id => node), :class => 'delete', :text => _('Deactivate')))
|
56
57
|
) %>
|
@@ -0,0 +1,69 @@
|
|
1
|
+
<% title @node %>
|
2
|
+
|
3
|
+
<% if respond_to?(:breadcrumbs) %>
|
4
|
+
<% breadcrumbs(
|
5
|
+
items: [
|
6
|
+
{
|
7
|
+
caption: _('Nodes'),
|
8
|
+
url: (url_for(puppetdb_foreman_nodes_path) if authorized_for(hash_for_puppetdb_foreman_nodes_path))
|
9
|
+
},
|
10
|
+
{
|
11
|
+
caption: @node
|
12
|
+
}],
|
13
|
+
switchable: false)
|
14
|
+
%>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<div class="col-md-12">
|
18
|
+
<div class="row">
|
19
|
+
<div class="container-fluid container-cards-pf">
|
20
|
+
<div class="row row-cards-pf">
|
21
|
+
<div class="col-xs-6 col-sm-4 col-md-4">
|
22
|
+
<div class="card-pf card-pf-accented card-pf-aggregate-status">
|
23
|
+
<h2 class="card-pf-title">
|
24
|
+
<span class="pficon pficon-infrastructure"></span><span class="card-pf-aggregate-status-count"><%= @classes_count %></span> <%= _('Classes') %>
|
25
|
+
</h2>
|
26
|
+
<div class="card-pf-body"></div>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class="col-xs-6 col-sm-4 col-md-4">
|
31
|
+
<div class="card-pf card-pf-accented card-pf-aggregate-status">
|
32
|
+
<h2 class="card-pf-title">
|
33
|
+
<span class="fa fa-wrench"></span><span class="card-pf-aggregate-status-count"><%= @type_names.count %></span> <%= _('Types') %>
|
34
|
+
</h2>
|
35
|
+
<div class="card-pf-body"></div>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div class="col-md-8">
|
42
|
+
<div class="panel panel-default">
|
43
|
+
<div class="panel-heading">
|
44
|
+
<h3 class="panel-title"><%= _('Puppet classes') %></h3>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<div class="panel-body">
|
48
|
+
<% if @classes.any? %>
|
49
|
+
<table class="<%= table_css_classes 'table-fixed' %>">
|
50
|
+
<thead>
|
51
|
+
<tr>
|
52
|
+
<th class="col-md-5"><%= _('Name') %></th>
|
53
|
+
</tr>
|
54
|
+
</thead>
|
55
|
+
|
56
|
+
<tbody>
|
57
|
+
<% @classes.each do |class_name| %>
|
58
|
+
<tr><td><%= class_name %></td></tr>
|
59
|
+
<% end %>
|
60
|
+
</tbody>
|
61
|
+
</table>
|
62
|
+
<% end %>
|
63
|
+
|
64
|
+
<%= will_paginate_with_info @classes %>
|
65
|
+
</div>
|
66
|
+
</div>
|
67
|
+
</div>
|
68
|
+
</div>
|
69
|
+
</div>
|
data/config/routes.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
get ':puppetdb(/*puppetdb_url)', :to => 'puppetdb_foreman/puppetdb#index', :puppetdb => /d3\.v2|charts|v3|puppetdb|metrics|\/pdb\/meta\/v1\/version\/latest|pdb\/meta\/v1\/version|pdb\/dashboard\/data/, :as => 'puppetdb'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
Rails.application.routes.draw do
|
4
4
|
namespace :puppetdb_foreman do
|
5
|
-
constraints(:
|
6
|
-
resources :nodes, :
|
5
|
+
constraints(id: %r{[^/]+}) do
|
6
|
+
resources :nodes, only: %i[index show destroy] do
|
7
7
|
member do
|
8
8
|
put 'import'
|
9
9
|
end
|
@@ -11,13 +11,13 @@ Rails.application.routes.draw do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
namespace :api, :
|
15
|
-
scope '(:apiv)', :
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
constraints(:
|
20
|
-
resources :puppetdb_nodes, :
|
14
|
+
namespace :api, defaults: { format: 'json' } do
|
15
|
+
scope '(:apiv)', module: :v2,
|
16
|
+
defaults: { apiv: 'v2' },
|
17
|
+
apiv: /v1|v2/,
|
18
|
+
constraints: ApiConstraints.new(version: 2) do
|
19
|
+
constraints(id: %r{[^/]+}) do
|
20
|
+
resources :puppetdb_nodes, only: %i[index destroy] do
|
21
21
|
collection do
|
22
22
|
get 'unknown'
|
23
23
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class MigratePuppetdbApiVersionSetting < ActiveRecord::Migration[4.2]
|
2
4
|
def up
|
3
|
-
puppetdb_address = Setting.where(:
|
5
|
+
puppetdb_address = Setting.where(category: 'Setting::Puppetdb', name: 'puppetdb_address').first.try(:value)
|
4
6
|
return unless puppetdb_address
|
5
7
|
|
6
8
|
api_version = URI.parse(puppetdb_address).path.start_with?('/pdb') ? 3 : 1
|
7
|
-
setting = Setting.where(:
|
9
|
+
setting = Setting.where(category: 'Setting::Puppetdb', name: 'puppetdb_api_version').first_or_create
|
8
10
|
setting.value = api_version
|
9
11
|
setting.save
|
10
12
|
end
|