foreman_column_view 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -6
- data/Rakefile +1 -1
- data/app/helpers/foreman_column_view/hosts_helper_extension.rb +40 -0
- data/app/overrides/add_column_content.rb +1 -1
- data/app/overrides/add_column_title.rb +1 -1
- data/lib/foreman_column_view.rb +2 -3
- data/lib/foreman_column_view/engine.rb +5 -0
- data/lib/foreman_column_view/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 942628959842bb592201db30bf188899ccf5c39d
|
4
|
+
data.tar.gz: d0efccf2714f26cc7d36e7e833893fb34d4e7f6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d5c334da3404a7e3dbba931463d02d018ddfffa3cc015faf2200ce766dfe3aa241029d0abd6cf64d09c32a4a3717689c3c4129597d4a181856d499978a9f297
|
7
|
+
data.tar.gz: 839d22fe642884e4872ee6d73912897f14434478b5f45a3177fd9781895f003628b712c177603c311b64cbf81ded6f7899ece8cc4a1fced95120cb8d931aed32
|
data/README.md
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
# foreman\_column\_view
|
2
2
|
|
3
3
|
A small plugin to showcase the awesome [Deface](https://github.com/spree/deface)
|
4
|
-
library. It simply adds a column to the Hosts list. It also
|
5
|
-
of including a new Helper in the plugin.
|
4
|
+
library. It simply adds a column to the Hosts list or properties table. It also
|
5
|
+
serves as a simple example of including a new Helper in the plugin.
|
6
6
|
|
7
7
|
# Installation
|
8
8
|
|
9
|
-
Require the gem in Foreman
|
9
|
+
Require the gem in Foreman (you may need extra dependencies such as libxml or libxslt
|
10
|
+
to build the nokogiri dependency)
|
10
11
|
|
11
12
|
```yaml
|
12
|
-
gem '
|
13
|
-
gem 'foreman_column_view', :git => "https://github.com/GregSutcliffe/foreman_column_view.git"
|
13
|
+
gem 'foreman_column_view'
|
14
14
|
```
|
15
15
|
|
16
16
|
Update Foreman with the new gems:
|
17
17
|
|
18
|
-
bundle update
|
18
|
+
bundle update foreman_column_view
|
19
19
|
|
20
20
|
# Configuration
|
21
21
|
|
@@ -50,6 +50,41 @@ as well:
|
|
50
50
|
:content: facts_hash['uptime']
|
51
51
|
```
|
52
52
|
|
53
|
+
Additional rows can also be added to the Properties table on the host page by setting
|
54
|
+
`:view: hosts_properties`. The position is also controlled by `:after` using either a
|
55
|
+
numeric index to represent the row or the name of the previous row (however this will
|
56
|
+
not work well when the Foreman language is switched). An example configuration:
|
57
|
+
|
58
|
+
```yaml
|
59
|
+
:uptime:
|
60
|
+
:title: Uptime
|
61
|
+
:after: 6
|
62
|
+
:content: facts_hash['uptime']
|
63
|
+
:view: :hosts_properties
|
64
|
+
```
|
65
|
+
|
66
|
+
If you need to add information not readily available in a host, you can add information that
|
67
|
+
will be evaluated on runtime by adding `:eval_content: true` to your additional row.
|
68
|
+
Also, some times you do not want to show the additional row if a certain condition is not met,
|
69
|
+
in order to show that row conditionally, add `:conditional: :condition_symbol` to your configuration,
|
70
|
+
and that conditional will be executed on your host.
|
71
|
+
|
72
|
+
As an example, the following yaml shows a link to a custom URL if the method host.bmc_available? is true.
|
73
|
+
|
74
|
+
```yaml
|
75
|
+
:console:
|
76
|
+
:title: Console
|
77
|
+
:after: 0
|
78
|
+
:content: link_to(_("Console"), "https://#{host.interfaces.first.name}.domainname", { :class => "btn btn-info" } )
|
79
|
+
:conditional: :bmc_available?
|
80
|
+
:eval_content: true
|
81
|
+
:view: :hosts_properties
|
82
|
+
```
|
83
|
+
|
84
|
+
If your conditional method needs arguments to work, the arguments should go after the method name separated by
|
85
|
+
spaces, as in `:custom_method arg1 arg2`
|
86
|
+
|
87
|
+
|
53
88
|
You will need to restart Foreman for changes to take effect, as the `settings.yaml` is
|
54
89
|
only read at startup.
|
55
90
|
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
gem.license = "GPL-3"
|
19
19
|
gem.summary = %Q{Column View Plugin for Foreman }
|
20
20
|
gem.description = %Q{Displays an additional column in the Foreman Hosts view}
|
21
|
-
gem.email = "greg.
|
21
|
+
gem.email = "greg.sutcliffe@gmail.com"
|
22
22
|
gem.authors = ["Greg Sutcliffe"]
|
23
23
|
# dependencies defined in Gemfile
|
24
24
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ForemanColumnView
|
2
|
+
module HostsHelperExtension
|
3
|
+
def self.included(base)
|
4
|
+
base.send :alias_method_chain, :overview_fields, :fcv
|
5
|
+
end
|
6
|
+
|
7
|
+
# Extend core HostsHelper to add rows to Properties on hosts/show
|
8
|
+
def overview_fields_with_fcv host
|
9
|
+
fields = overview_fields_without_fcv(host)
|
10
|
+
valid_views = [:hosts_properties]
|
11
|
+
|
12
|
+
SETTINGS[:column_view].reject { |k,v| !valid_views.include?(v[:view]) }.keys.sort.map do |k|
|
13
|
+
after = SETTINGS[:column_view][k.to_sym][:after]
|
14
|
+
conditional = SETTINGS[:column_view][k.to_sym][:conditional]
|
15
|
+
if conditional.present?
|
16
|
+
method = conditional[0].to_sym
|
17
|
+
args = conditional.drop(1)
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
next unless (conditional.present? && host.respond_to?(method) && host.send(method, *args)) ||
|
22
|
+
(conditional.nil?)
|
23
|
+
rescue ArgumentError
|
24
|
+
Rails.logger.warn("Foreman_column_view: Your are supplying the wrong kind/number of arguments to your conditional method. Host #{host} , method - #{method} - arguments - #{args.join(', ')} ")
|
25
|
+
next
|
26
|
+
end
|
27
|
+
|
28
|
+
# This won't work well with i18n, use row numbers instead
|
29
|
+
after = fields.find_index { |r| r[0].include? after } unless after.is_a? Fixnum
|
30
|
+
eval_content = SETTINGS[:column_view][k.to_sym][:eval_content]
|
31
|
+
content = eval_content ? eval(SETTINGS[:column_view][k.to_sym][:content]) :
|
32
|
+
fcv_content(host, k)
|
33
|
+
|
34
|
+
fields.insert(after || -1, [fcv_title(k), content])
|
35
|
+
end
|
36
|
+
|
37
|
+
fields
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
if SETTINGS[:column_view]
|
2
|
-
SETTINGS[:column_view].keys.sort.map do |k|
|
2
|
+
SETTINGS[:column_view].reject { |k,v| v[:view] && v[:view] != 'hosts_list' }.keys.sort.map do |k|
|
3
3
|
after = SETTINGS[:column_view][k.to_sym][:after]
|
4
4
|
Deface::Override.new(
|
5
5
|
:virtual_path => "hosts/_list",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
if SETTINGS[:column_view]
|
2
|
-
SETTINGS[:column_view].keys.sort.map do |k|
|
2
|
+
SETTINGS[:column_view].reject { |k,v| v[:view] && v[:view] != 'hosts_list' }.keys.sort.map do |k|
|
3
3
|
after = SETTINGS[:column_view][k.to_sym][:after]
|
4
4
|
Deface::Override.new(
|
5
5
|
:virtual_path => "hosts/_list",
|
data/lib/foreman_column_view.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'deface'
|
1
2
|
require 'foreman_column_view'
|
3
|
+
require 'deface'
|
2
4
|
|
3
5
|
module ForemanColumnView
|
4
6
|
#Inherit from the Rails module of the parent app (Foreman), not the plugin.
|
@@ -7,6 +9,9 @@ module ForemanColumnView
|
|
7
9
|
|
8
10
|
initializer 'foreman_column_view.helper' do |app|
|
9
11
|
ActionView::Base.send :include, ForemanColumnView::HostsHelper
|
12
|
+
|
13
|
+
# Extend core HostHelper to add rows to Properties on hosts/show
|
14
|
+
::HostsHelper.send :include, ForemanColumnView::HostsHelperExtension
|
10
15
|
end
|
11
16
|
|
12
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_column_view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Sutcliffe
|
@@ -34,6 +34,7 @@ extra_rdoc_files:
|
|
34
34
|
- LICENSE
|
35
35
|
- README.md
|
36
36
|
files:
|
37
|
+
- app/helpers/foreman_column_view/hosts_helper_extension.rb
|
37
38
|
- app/helpers/foreman_column_view/hosts_helper.rb
|
38
39
|
- app/overrides/add_column_title.rb
|
39
40
|
- app/overrides/add_column_content.rb
|