Skip to content

Commit

Permalink
add plugin foreman_column_view
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoetz committed Aug 3, 2020
1 parent 8e4c89a commit 3d6cbe6
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
18 changes: 18 additions & 0 deletions manifests/plugin/column_view.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# = Foreman Column View
#
# This class installs the column view plugin and optionally manages the configuration file
#
# === Parameters:
#
# $columns:: an hash of columns to add to the configuration
#
class foreman::plugin::column_view (
Hash[String, Hash] $columns = {},
){
# https://projects.theforeman.org/issues/21398
assert_type(Hash[String, Foreman::Column_view_column], $columns)

foreman::plugin { 'column_view':
config => template('foreman/foreman_column_view.yaml.erb'),
}
}
63 changes: 63 additions & 0 deletions spec/classes/plugin/column_view_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'spec_helper'

describe 'foreman::plugin::column_view' do
include_examples 'basic foreman plugin tests', 'column_view'

context 'with columns hash architecture' do
let(:params) do
{
'columns' => {
'architecture' => {
'title' => 'Architecture',
'after' => 'last_report',
'content' => 'facts_hash["architecture"]',
}
}
}
end

it { is_expected.to contain_file('/etc/foreman/plugins/foreman_column_view.yaml').with_content(/.*:title: Architecture.*/) }

it { is_expected.to compile.with_all_deps }
end

context 'with columns hash architecture and console' do
let(:params) do
{
'columns' => {
'architecture' => {
'title' => 'Architecture',
'after' => 'last_report',
'content' => 'facts_hash["architecture"]',
},
'console' => {
'title' => 'Console',
'after' => '0',
'content' => 'link_to(_("Console"), "https://#{host.interfaces.first.name}.domainname", { :class => "btn btn-info" } )',
'conditional' => ':bmc_available?',
'eval_content' => 'true',
'view' => ':hosts_properties',
}
}
}
end

it { is_expected.to contain_file('/etc/foreman/plugins/foreman_column_view.yaml').with_content(/.*:title: Console.*/) }

it { is_expected.to compile.with_all_deps }
end

context 'with columns hash broken' do
let(:params) do
{
'columns' => {
'broken' => {
'title' => 'Broken',
}
}
}
end

it { is_expected.to_not compile.with_all_deps }
end
end
12 changes: 12 additions & 0 deletions templates/foreman_column_view.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= ERB.new(File.read(File.expand_path("_header.erb",File.dirname(file)))).result(binding) -%>
#
# See tfm-rubygem-foreman_column_view-doc and /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_column_view-0.3.0/README.md for more information
:column_view:
<% if @columns -%>
<% @columns.each do |column, hash| -%>
:<%= column %>:
<% hash.each do |key,value| -%>
:<%= key %>: <%= value %>
<% end -%>
<% end -%>
<% end -%>
12 changes: 12 additions & 0 deletions types/column_view_column.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type Foreman::Column_view_column = Struct[
{
title => String[1],
after => String[1],
content => String[1],
Optional['conditional'] => String[1],
Optional['eval_content'] => String[1],
Optional['view'] => String[1],
Optional['width'] => String[1],
Optional['custom_method'] => String[1],
}
]

0 comments on commit 3d6cbe6

Please sign in to comment.