foreman_hosts 0.0.1dev
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.
- data/LICENSE +619 -0
- data/README.md +155 -0
- data/Rakefile +47 -0
- data/app/controllers/foreman_hosts/hosts_controller.rb +27 -0
- data/app/helpers/concerns/foreman_hosts/hosts_helper_extensions.rb +20 -0
- data/app/models/concerns/foreman_hosts/host_extensions.rb +19 -0
- data/app/overrides/dashboard/index/sample_override.html.erb.deface +4 -0
- data/app/views/dashboard/_foreman_hosts_widget.html.erb +2 -0
- data/app/views/foreman_hosts/hosts/export.xlsx.axlsx +130 -0
- data/app/views/foreman_hosts/hosts/hosts/new_action.html.erb +1 -0
- data/app/views/foreman_hosts/hosts/new_action.html.erb +1 -0
- data/app/views/foreman_hosts/hosts/report_index.html.erb +46 -0
- data/app/views/foreman_hosts/layouts/layouts/new_layout.html.erb +0 -0
- data/app/views/foreman_hosts/layouts/new_layout.html.erb +0 -0
- data/bin/foreman-hosts +5 -0
- data/config/routes.rb +5 -0
- data/lib/foreman_hosts/engine.rb +86 -0
- data/lib/foreman_hosts/version.rb +3 -0
- data/lib/foreman_hosts.rb +4 -0
- data/lib/tasks/foreman_hosts_tasks.rake +49 -0
- data/locale/Makefile +62 -0
- data/locale/en/foreman_hosts.po +19 -0
- data/locale/foreman_hosts.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/test/factories/foreman_hosts_factories.rb +5 -0
- data/test/test_plugin_helper.rb +6 -0
- data/test/unit/foreman_hosts_test.rb +11 -0
- metadata +107 -0
data/README.md
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
*** LOCAL GEMS ***
|
2
|
+
|
3
|
+
actionmailer (3.2.8)
|
4
|
+
actionpack (3.2.8)
|
5
|
+
activemodel (3.2.8)
|
6
|
+
activerecord (3.2.8)
|
7
|
+
activeresource (3.2.8)
|
8
|
+
activesupport (4.2.4, 3.2.8)
|
9
|
+
ancestry (2.0.0)
|
10
|
+
apipie-rails (0.2.6)
|
11
|
+
arel (3.0.2)
|
12
|
+
audited (3.0.0)
|
13
|
+
audited-activerecord (3.0.0)
|
14
|
+
bigdecimal (1.1.0)
|
15
|
+
builder (3.0.0)
|
16
|
+
bundler (1.3.5)
|
17
|
+
bundler_ext (0.3.0)
|
18
|
+
coffee-rails (3.2.2)
|
19
|
+
coffee-script (2.2.0)
|
20
|
+
coffee-script-source (1.3.3)
|
21
|
+
colorize (0.7.7)
|
22
|
+
deep_cloneable (2.0.2)
|
23
|
+
deface (1.0.1)
|
24
|
+
diff-lcs (1.1.3)
|
25
|
+
erubis (2.7.0)
|
26
|
+
execjs (1.4.0)
|
27
|
+
fast_gettext (0.9.2)
|
28
|
+
foreigner (1.7.1)
|
29
|
+
foreman-hosts (0.0.1)
|
30
|
+
foreman_setup (3.0.1)
|
31
|
+
friendly_id (4.0.10.1)
|
32
|
+
gettext_i18n_rails (1.2.1)
|
33
|
+
hike (1.2.1)
|
34
|
+
i18n (0.7.0, 0.6.0)
|
35
|
+
io-console (0.3)
|
36
|
+
journey (1.0.4)
|
37
|
+
json (1.8.3, 1.5.5)
|
38
|
+
ldap_fluff (0.3.5)
|
39
|
+
little-plugger (1.1.3)
|
40
|
+
logging (1.8.2)
|
41
|
+
loofah (2.0.3)
|
42
|
+
mail (2.4.4)
|
43
|
+
mime-types (1.19)
|
44
|
+
mini_portile (0.6.2)
|
45
|
+
minitest (5.8.1, 2.5.1)
|
46
|
+
multi_json (1.10.1)
|
47
|
+
net-http-persistent (2.7)
|
48
|
+
net-ldap (0.11)
|
49
|
+
netrc (0.7.7)
|
50
|
+
nokogiri (1.6.6.2)
|
51
|
+
oauth (0.4.7)
|
52
|
+
passenger (4.0.18)
|
53
|
+
pg (0.12.2)
|
54
|
+
polyglot (0.3.3)
|
55
|
+
rabl (0.11.6)
|
56
|
+
rack (1.6.4, 1.4.1)
|
57
|
+
rack-cache (1.2)
|
58
|
+
rack-jsonp (1.3.1)
|
59
|
+
rack-ssl (1.3.2)
|
60
|
+
rack-test (0.6.3, 0.6.1)
|
61
|
+
rails (3.2.8)
|
62
|
+
railties (3.2.8)
|
63
|
+
rake (0.9.2.2)
|
64
|
+
rdoc (3.9.5)
|
65
|
+
rest-client (1.6.7)
|
66
|
+
ruby2ruby (2.1.3)
|
67
|
+
ruby_parser (3.6.3)
|
68
|
+
safemode (1.2.2)
|
69
|
+
scoped_search (3.2.1)
|
70
|
+
secure_headers (1.4.1)
|
71
|
+
sexp_processor (4.4.4)
|
72
|
+
sprockets (2.12.3)
|
73
|
+
thor (0.18.1)
|
74
|
+
thread_safe (0.3.5)
|
75
|
+
tilt (1.3.3)
|
76
|
+
treetop (1.4.10)
|
77
|
+
turbolinks (2.5.3)
|
78
|
+
tzinfo (1.2.2, 0.3.33)
|
79
|
+
validates_lengths_from_database (0.4.0)
|
80
|
+
will_paginate (3.0.2)
|
81
|
+
|
82
|
+
|
83
|
+
============================================================================
|
84
|
+
Fetching: mini_portile-0.6.2.gem (100%)
|
85
|
+
Fetching: nokogiri-1.6.6.2.gem (100%)
|
86
|
+
Building native extensions. This could take a while...
|
87
|
+
Fetching: colorize-0.7.7.gem (100%)
|
88
|
+
Fetching: deface-1.0.1.gem (100%)
|
89
|
+
Fetching: foreman-hosts-0.0.1.gem (100%)
|
90
|
+
Fetching: i18n-0.7.0.gem (100%)
|
91
|
+
Fetching: json-1.8.3.gem (100%)
|
92
|
+
Building native extensions. This could take a while...
|
93
|
+
Fetching: thread_safe-0.3.5.gem (100%)
|
94
|
+
Fetching: tzinfo-1.2.2.gem (100%)
|
95
|
+
Fetching: minitest-5.8.1.gem (100%)
|
96
|
+
Fetching: activesupport-4.2.4.gem (100%)
|
97
|
+
Fetching: rack-1.6.4.gem (100%)
|
98
|
+
Fetching: rack-test-0.6.3.gem (100%)
|
99
|
+
Fetching: loofah-2.0.3.gem (100%)
|
100
|
+
Fetching: rails-html-sanitizer-1.0.2.gem (100%)
|
101
|
+
Fetching: rails-deprecated_sanitizer-1.0.3.gem (100%)
|
102
|
+
Fetching: rails-dom-testing-1.0.7.gem (100%)
|
103
|
+
Fetching: builder-3.2.2.gem (100%)
|
104
|
+
Fetching: actionview-4.2.4.gem (100%)
|
105
|
+
Fetching: actionpack-4.2.4.gem (100%)
|
106
|
+
Fetching: activemodel-4.2.4.gem (100%)
|
107
|
+
Fetching: arel-6.0.3.gem (100%)
|
108
|
+
Fetching: activerecord-4.2.4.gem (100%)
|
109
|
+
Fetching: globalid-0.3.6.gem (100%)
|
110
|
+
Fetching: activejob-4.2.4.gem (100%)
|
111
|
+
Fetching: mail-2.6.3.gem (100%)
|
112
|
+
Fetching: actionmailer-4.2.4.gem (100%)
|
113
|
+
Fetching: railties-4.2.4.gem (100%)
|
114
|
+
Fetching: sprockets-rails-2.3.3.gem (100%)
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
# ForemanHosts
|
119
|
+
|
120
|
+
*Introdction here*
|
121
|
+
|
122
|
+
## Installation
|
123
|
+
|
124
|
+
See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Plugin)
|
125
|
+
for how to install Foreman plugins
|
126
|
+
|
127
|
+
## Usage
|
128
|
+
|
129
|
+
*Usage here*
|
130
|
+
|
131
|
+
## TODO
|
132
|
+
|
133
|
+
*Todo list here*
|
134
|
+
|
135
|
+
## Contributing
|
136
|
+
|
137
|
+
Fork and send a Pull Request. Thanks!
|
138
|
+
|
139
|
+
## Copyright
|
140
|
+
|
141
|
+
Copyright (c) *year* *your name*
|
142
|
+
|
143
|
+
This program is free software: you can redistribute it and/or modify
|
144
|
+
it under the terms of the GNU General Public License as published by
|
145
|
+
the Free Software Foundation, either version 3 of the License, or
|
146
|
+
(at your option) any later version.
|
147
|
+
|
148
|
+
This program is distributed in the hope that it will be useful,
|
149
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
150
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
151
|
+
GNU General Public License for more details.
|
152
|
+
|
153
|
+
You should have received a copy of the GNU General Public License
|
154
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
155
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ForemanHosts'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
task default: :test
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'rubocop/rake_task'
|
40
|
+
RuboCop::RakeTask.new
|
41
|
+
rescue => _
|
42
|
+
puts 'Rubocop not loaded.'
|
43
|
+
end
|
44
|
+
|
45
|
+
task :default do
|
46
|
+
Rake::Task['rubocop'].execute
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ForemanHosts
|
2
|
+
# Example: Plugin's HostsController inherits from Foreman's HostsController
|
3
|
+
class HostsController < ::HostsController
|
4
|
+
# change layout if needed
|
5
|
+
layout 'foreman_hosts/layouts/new_layout'
|
6
|
+
|
7
|
+
def new_action
|
8
|
+
# automatically renders view/foreman_hosts/hosts/new_action
|
9
|
+
end
|
10
|
+
|
11
|
+
def export
|
12
|
+
@hosts = Host.all
|
13
|
+
render xlsx: 'hosts',template: "/hosts/export.xlsx.axlsx"
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def report_index
|
18
|
+
@fact_values = FactValue.all
|
19
|
+
@fact_names = FactName.all
|
20
|
+
@hosts = Host.all
|
21
|
+
respond_to do |format|
|
22
|
+
format.html # index.html.erb
|
23
|
+
format.json { render json: @hosts }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ForemanHosts
|
2
|
+
module HostsHelperExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
# execute callbacks
|
7
|
+
end
|
8
|
+
|
9
|
+
# create or overwrite instance methods...
|
10
|
+
def instance_method_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_fact_value(host,name)
|
14
|
+
fact_value = FactValue.where(host_id: host.id, fact_name_id: name.id)
|
15
|
+
if fact_value.first.present?
|
16
|
+
return fact_value.first.value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ForemanHosts
|
2
|
+
module HostExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
# execute callbacks
|
7
|
+
end
|
8
|
+
|
9
|
+
# create or overwrite instance methods...
|
10
|
+
def instance_method_name
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
# create or overwrite class methods...
|
15
|
+
def class_method_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
wb = xlsx_package.workbook
|
2
|
+
wb.add_worksheet(name: "Hosts") do |sheet|
|
3
|
+
sheet.add_row [
|
4
|
+
"name",
|
5
|
+
"last_compile",
|
6
|
+
"last_report",
|
7
|
+
"updated_at",
|
8
|
+
"created_at",
|
9
|
+
"root_pass",
|
10
|
+
"architecture_id",
|
11
|
+
"operatingsystem_id",
|
12
|
+
"environment_id",
|
13
|
+
"ptable_id",
|
14
|
+
"medium_id",
|
15
|
+
"build",
|
16
|
+
"comment",
|
17
|
+
"disk",
|
18
|
+
"installed_at",
|
19
|
+
"model_id",
|
20
|
+
"roup_id",
|
21
|
+
"owner_id",
|
22
|
+
"owner_type",
|
23
|
+
"enabled ",
|
24
|
+
"puppet_ca_proxy_id ",
|
25
|
+
"managed ",
|
26
|
+
"use_image ",
|
27
|
+
"image_file ",
|
28
|
+
"uuid ",
|
29
|
+
"compute_resource_id ",
|
30
|
+
"puppet_proxy_id ",
|
31
|
+
"certname ",
|
32
|
+
"image_id ",
|
33
|
+
"organization_id ",
|
34
|
+
"location_id ",
|
35
|
+
"type ",
|
36
|
+
"otp ",
|
37
|
+
"realm_id ",
|
38
|
+
"compute_profile_id ",
|
39
|
+
"provision_method ",
|
40
|
+
"grub_pass ",
|
41
|
+
"global_status ",
|
42
|
+
"lookup_value_matcher"
|
43
|
+
]
|
44
|
+
|
45
|
+
|
46
|
+
@hosts.each do |host|
|
47
|
+
|
48
|
+
expet_name = host.name rescue ""
|
49
|
+
expet_last_compile = host.last_compile rescue ""
|
50
|
+
expet_last_report = host.last_report rescue ""
|
51
|
+
expet_updated_at= host.updated_at rescue ""
|
52
|
+
expet_created_ate = host.created_at rescue ""
|
53
|
+
expet_root_pass = host.root_pass rescue ""
|
54
|
+
expet_architecture_id = host.architecture.name rescue ""
|
55
|
+
expet_operatingsystem_id = host.operatingsystem.name rescue ""
|
56
|
+
expet_environment_id= host.environment.name rescue ""
|
57
|
+
expet_ptable_id = host.ptable.name rescue ""
|
58
|
+
expet_medium_id = host.medium.name rescue ""
|
59
|
+
expet_build = host.build rescue ""
|
60
|
+
expet_comment = host.comment rescue ""
|
61
|
+
expetdisk = host.disk rescue ""
|
62
|
+
expet_installed_at = host.installed_at rescue ""
|
63
|
+
expet_model_id = host.model.name rescue ""
|
64
|
+
expet_hostgroup_id = host.hostgroup.name rescue ""
|
65
|
+
expet_owner_id = host.owner.name rescue ""
|
66
|
+
expet_owner_type = host.owner_type rescue ""
|
67
|
+
expet_enabled= host.enabled rescue ""
|
68
|
+
expet_puppet_ca_proxy_id = host.puppet_ca_proxy.name rescue ""
|
69
|
+
expet_managed = host.managed rescue ""
|
70
|
+
expet_use_image = host.use_image rescue ""
|
71
|
+
expet_image_file = host.image_file rescue ""
|
72
|
+
expet_uuid = host.uuid rescue ""
|
73
|
+
expet_compute_resource_id = host.compute_resource.name rescue ""
|
74
|
+
expet_puppet_proxy_id = host.puppet_proxy.name rescue ""
|
75
|
+
expet_certname = host.certname rescue ""
|
76
|
+
expet_image_id = host.image_id rescue ""
|
77
|
+
expet_organization_id = host.organization.name rescue ""
|
78
|
+
expet_location_id = host.location.name rescue ""
|
79
|
+
expet_type= host.type rescue ""
|
80
|
+
expet_otp = host.otp rescue ""
|
81
|
+
expet_realm_id = host.realm.name rescue ""
|
82
|
+
expet_compute_profile_id = host.compute_profile.name rescue ""
|
83
|
+
expet_provision_method = host.provision_method rescue ""
|
84
|
+
expet_grub_pass = host.grub_pass rescue ""
|
85
|
+
expet_global_status = host.global_status rescue ""
|
86
|
+
expet_lookup_value_matcher = host.lookup_value_matcher rescue ""
|
87
|
+
|
88
|
+
sheet.add_row [
|
89
|
+
expet_name,
|
90
|
+
expet_last_compile,
|
91
|
+
expet_last_report,
|
92
|
+
expet_updated_at= host.updated_at rescue "",
|
93
|
+
expet_created_ate,
|
94
|
+
expet_root_pass,
|
95
|
+
expet_architecture_id,
|
96
|
+
expet_operatingsystem_id,
|
97
|
+
expet_environment_id,
|
98
|
+
expet_ptable_id,
|
99
|
+
expet_medium_id,
|
100
|
+
expet_build,
|
101
|
+
expet_comment,
|
102
|
+
expetdisk,
|
103
|
+
expet_installed_at,
|
104
|
+
expet_model_id,
|
105
|
+
expet_hostgroup_id,
|
106
|
+
expet_owner_id,
|
107
|
+
expet_owner_type,
|
108
|
+
expet_enabled= host.enabled rescue "",
|
109
|
+
expet_puppet_ca_proxy_id,
|
110
|
+
expet_managed,
|
111
|
+
expet_use_image,
|
112
|
+
expet_image_file,
|
113
|
+
expet_uuid,
|
114
|
+
expet_compute_resource_id,
|
115
|
+
expet_puppet_proxy_id,
|
116
|
+
expet_certname,
|
117
|
+
expet_image_id,
|
118
|
+
expet_organization_id,
|
119
|
+
expet_location_id,
|
120
|
+
expet_type= host.type rescue "",
|
121
|
+
expet_otp,
|
122
|
+
expet_realm_id,
|
123
|
+
expet_compute_profile_id,
|
124
|
+
expet_provision_method,
|
125
|
+
expet_grub_pass,
|
126
|
+
expet_global_status,
|
127
|
+
expet_lookup_value_matcher
|
128
|
+
]
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Welcome to <b>ForemanHosts</b>
|
@@ -0,0 +1 @@
|
|
1
|
+
Welcome to <b>ForemanHosts</b>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<div class="four wide right column">
|
2
|
+
<a href="javascript:void(0);" class="ui green button icon mini" id="btnExport" onclick="export_excel();">导出</a>
|
3
|
+
</div>
|
4
|
+
<%= javascript "jquery.cookie", "host_checkbox" %>
|
5
|
+
<% title header ||= "" %>
|
6
|
+
<table class="table table-bordered table-striped table-condensed" id="tblExport">
|
7
|
+
<thead>
|
8
|
+
<tr>
|
9
|
+
<th class="ca"><%= check_box_tag "check_all", "", false, { :onclick => "toggleCheck()", :'check-title' => _("Select all items in this page"), :'uncheck-title'=> _("items selected. Uncheck to Clear") } %></th>
|
10
|
+
<th class=''><%= sort :name, :as => _('Name') %></th>
|
11
|
+
<% @fact_names.each do |fact_name| %>
|
12
|
+
<th><%= fact_name.name %></th>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
</tr>
|
16
|
+
</thead>
|
17
|
+
<tbody>
|
18
|
+
<% @hosts.each do |host| %>
|
19
|
+
<tr>
|
20
|
+
<td class="ca">
|
21
|
+
<%= check_box_tag "host_ids[]", nil, false, :id => "host_ids_#{host.id}", :disabled => !authorized?, :class => 'host_select_boxes', :onclick => 'hostChecked(this)' %>
|
22
|
+
</td>
|
23
|
+
<td class='ellipsis'><%= name_column(host) %></td>
|
24
|
+
<% @fact_names.each do |fact_name| %>
|
25
|
+
<td><%= get_fact_value(host, fact_name) %> </td>
|
26
|
+
<% end %>
|
27
|
+
</tr>
|
28
|
+
<% end %>
|
29
|
+
</tbody>
|
30
|
+
</table>
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
<script type="text/javascript">
|
38
|
+
function export_excel(){
|
39
|
+
var uri = $("#tblExport").battatech_excelexport({
|
40
|
+
containerid: "tblExport",
|
41
|
+
datatype: 'table',
|
42
|
+
returnUri: true
|
43
|
+
});
|
44
|
+
$("#btnExport").attr('download', '项目工时.xlsx').attr('href', uri).attr('target', '_blank');
|
45
|
+
}
|
46
|
+
</script>
|
File without changes
|
File without changes
|
data/bin/foreman-hosts
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'deface'
|
2
|
+
|
3
|
+
module ForemanHosts
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
engine_name 'foreman_hosts'
|
6
|
+
|
7
|
+
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
8
|
+
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
9
|
+
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
10
|
+
config.autoload_paths += Dir["#{config.root}/app/overrides"]
|
11
|
+
|
12
|
+
# Add any db migrations
|
13
|
+
initializer 'foreman_hosts.load_app_instance_data' do |app|
|
14
|
+
app.config.paths['db/migrate'] += ForemanHosts::Engine.paths['db/migrate'].existent
|
15
|
+
end
|
16
|
+
|
17
|
+
initializer 'foreman_hosts.register_plugin', after: :finisher_hook do |_app|
|
18
|
+
Foreman::Plugin.register :foreman_hosts do
|
19
|
+
requires_foreman '>= 1.4'
|
20
|
+
|
21
|
+
# Add permissions
|
22
|
+
security_block :foreman_hosts do
|
23
|
+
permission :view_foreman_hosts, :'foreman_hosts/hosts' => [:new_action]
|
24
|
+
permission :view_foreman_hosts, :'foreman_hosts/hosts' => [:export]
|
25
|
+
permission :view_foreman_hosts, :'foreman_hosts/hosts' => [:report_index]
|
26
|
+
end
|
27
|
+
|
28
|
+
# Add a new role called 'Discovery' if it doesn't exist
|
29
|
+
role 'ForemanHosts', [:view_foreman_hosts]
|
30
|
+
|
31
|
+
# add menu entry
|
32
|
+
menu :top_menu, :template,
|
33
|
+
url_hash: { controller: :'foreman_hosts/hosts', action: :new_action },
|
34
|
+
url_hash: { controller: :'foreman_hosts/hosts', action: :export },
|
35
|
+
url_hash: { controller: :'foreman_hosts/hosts', action: :report_index },
|
36
|
+
caption: 'ForemanHosts',
|
37
|
+
parent: :hosts_menu,
|
38
|
+
after: :hosts
|
39
|
+
|
40
|
+
# add dashboard widget
|
41
|
+
widget 'foreman_hosts_widget', name: N_('Foreman plugin template widget'), sizex: 4, sizey: 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Precompile any JS or CSS files under app/assets/
|
46
|
+
# If requiring files from each other, list them explicitly here to avoid precompiling the same
|
47
|
+
# content twice.
|
48
|
+
assets_to_precompile =
|
49
|
+
Dir.chdir(root) do
|
50
|
+
Dir['app/assets/javascripts/**/*', 'app/assets/stylesheets/**/*'].map do |f|
|
51
|
+
f.split(File::SEPARATOR, 4).last
|
52
|
+
end
|
53
|
+
end
|
54
|
+
initializer 'foreman_hosts.assets.precompile' do |app|
|
55
|
+
app.config.assets.precompile += assets_to_precompile
|
56
|
+
end
|
57
|
+
initializer 'foreman_hosts.configure_assets', group: :assets do
|
58
|
+
SETTINGS[:foreman_hosts] = { assets: { precompile: assets_to_precompile } }
|
59
|
+
end
|
60
|
+
|
61
|
+
# Include concerns in this config.to_prepare block
|
62
|
+
config.to_prepare do
|
63
|
+
begin
|
64
|
+
Host::Managed.send(:include, ForemanHosts::HostExtensions)
|
65
|
+
HostsHelper.send(:include, ForemanHosts::HostsHelperExtensions)
|
66
|
+
rescue => e
|
67
|
+
Rails.logger.warn "ForemanHosts: skipping engine hook (#{e})"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
rake_tasks do
|
72
|
+
Rake::Task['db:seed'].enhance do
|
73
|
+
ForemanHosts::Engine.load_seed
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
initializer 'foreman_hosts.register_gettext', after: :load_config_initializers do |_app|
|
78
|
+
locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
|
79
|
+
locale_domain = 'foreman_hosts'
|
80
|
+
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
81
|
+
end
|
82
|
+
initializer "foreman_chef.load_app_instance_data" do |app|
|
83
|
+
app.config.paths['db/migrate'] += PluginTemplate::Engine.paths['db/migrate'].existent
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Tasks
|
2
|
+
namespace :foreman_hosts do
|
3
|
+
namespace :example do
|
4
|
+
desc 'Example Task'
|
5
|
+
task task: :environment do
|
6
|
+
# Task goes here
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Tests
|
12
|
+
namespace :test do
|
13
|
+
desc 'Test ForemanHosts'
|
14
|
+
Rake::TestTask.new(:foreman_hosts) do |t|
|
15
|
+
test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
|
16
|
+
t.libs << ['test', test_dir]
|
17
|
+
t.pattern = "#{test_dir}/**/*_test.rb"
|
18
|
+
t.verbose = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :foreman_hosts do
|
23
|
+
task :rubocop do
|
24
|
+
begin
|
25
|
+
require 'rubocop/rake_task'
|
26
|
+
RuboCop::RakeTask.new(:rubocop_foreman_hosts) do |task|
|
27
|
+
task.patterns = ["#{ForemanHosts::Engine.root}/app/**/*.rb",
|
28
|
+
"#{ForemanHosts::Engine.root}/lib/**/*.rb",
|
29
|
+
"#{ForemanHosts::Engine.root}/test/**/*.rb"]
|
30
|
+
end
|
31
|
+
rescue
|
32
|
+
puts 'Rubocop not loaded.'
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::Task['rubocop_foreman_hosts'].invoke
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Rake::Task[:test].enhance do
|
40
|
+
Rake::Task['test:foreman_hosts'].invoke
|
41
|
+
end
|
42
|
+
|
43
|
+
load 'tasks/jenkins.rake'
|
44
|
+
if Rake::Task.task_defined?(:'jenkins:unit')
|
45
|
+
Rake::Task['jenkins:unit'].enhance do
|
46
|
+
Rake::Task['test:foreman_hosts'].invoke
|
47
|
+
Rake::Task['foreman_hosts:rubocop'].invoke
|
48
|
+
end
|
49
|
+
end
|