foreman_export_hosts 0.0.1
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 +39 -0
- data/Rakefile +47 -0
- data/app/assets/javascripts/application.js +2 -0
- data/app/assets/javascripts/jquery.battatech.excelexport.js +180 -0
- data/app/controllers/foreman_hosts/hosts_controller.rb +17 -0
- data/app/controllers/foreman_hosts/syhostmodeldetails_controller.rb +83 -0
- data/app/controllers/foreman_hosts/syhostmodels_controller.rb +84 -0
- data/app/helpers/concerns/foreman_hosts/hosts_helper_extensions.rb +20 -0
- data/app/models/concerns/foreman_hosts/hosts_extensions.rb +19 -0
- data/app/models/foreman_hosts/syhostmodel.rb +8 -0
- data/app/models/foreman_hosts/syhostmodeldetail.rb +5 -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/report_index.html.erb +257 -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/app/views/foreman_hosts/syhostmodels/_form.html.erb +30 -0
- data/app/views/foreman_hosts/syhostmodels/_list.html.erb +41 -0
- data/app/views/foreman_hosts/syhostmodels/_report.html.erb +258 -0
- data/app/views/foreman_hosts/syhostmodels/_sub.html.erb +37 -0
- data/app/views/foreman_hosts/syhostmodels/edit.html.erb +1 -0
- data/app/views/foreman_hosts/syhostmodels/index.html.erb +5 -0
- data/app/views/foreman_hosts/syhostmodels/new.html.erb +1 -0
- data/app/views/foreman_hosts/syhostmodels/show.html.erb +72 -0
- data/bin/foreman-hosts +5 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20151015022411_create_syhostmodels.rb +10 -0
- data/db/migrate/20151015050239_create_syhostmodeldetails.rb +13 -0
- data/lib/foreman_hosts/engine.rb +92 -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 +154 -0
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,180 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* jQuery Client Side Excel Export Plugin Library
|
|
3
|
+
* http://www.battatech.com/
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2013 Batta Tech Private Limited
|
|
6
|
+
* Licensed under https://github.com/battatech/battatech_excelexport/blob/master/LICENSE.txt
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
(function ($) {
|
|
10
|
+
var $defaults = {
|
|
11
|
+
containerid: null
|
|
12
|
+
, datatype: 'table'
|
|
13
|
+
, dataset: null
|
|
14
|
+
, columns: null
|
|
15
|
+
, returnUri: false
|
|
16
|
+
, worksheetName: "Sheet1"
|
|
17
|
+
, encoding: "utf-8"
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var $settings = $defaults;
|
|
21
|
+
|
|
22
|
+
$.fn.battatech_excelexport = function (options) {
|
|
23
|
+
$settings = $.extend({}, $defaults, options);
|
|
24
|
+
|
|
25
|
+
var gridData = [];
|
|
26
|
+
var excelData;
|
|
27
|
+
|
|
28
|
+
return Initialize();
|
|
29
|
+
|
|
30
|
+
function Initialize() {
|
|
31
|
+
var type = $settings.datatype.toLowerCase();
|
|
32
|
+
|
|
33
|
+
BuildDataStructure(type);
|
|
34
|
+
|
|
35
|
+
switch (type) {
|
|
36
|
+
case 'table':
|
|
37
|
+
excelData = Export(ConvertFromTable());
|
|
38
|
+
break;
|
|
39
|
+
case 'json':
|
|
40
|
+
excelData = Export(ConvertDataStructureToTable());
|
|
41
|
+
break;
|
|
42
|
+
case 'xml':
|
|
43
|
+
excelData = Export(ConvertDataStructureToTable());
|
|
44
|
+
break;
|
|
45
|
+
case 'jqgrid':
|
|
46
|
+
excelData = Export(ConvertDataStructureToTable());
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ($settings.returnUri) {
|
|
51
|
+
return excelData;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
window.open(excelData);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function BuildDataStructure(type) {
|
|
59
|
+
switch (type) {
|
|
60
|
+
case 'table':
|
|
61
|
+
break;
|
|
62
|
+
case 'json':
|
|
63
|
+
gridData = $settings.dataset;
|
|
64
|
+
break;
|
|
65
|
+
case 'xml':
|
|
66
|
+
$($settings.dataset).find("row").each(function (key, value) {
|
|
67
|
+
var item = {};
|
|
68
|
+
|
|
69
|
+
if (this.attributes != null && this.attributes.length > 0) {
|
|
70
|
+
$(this.attributes).each(function () {
|
|
71
|
+
item[this.name] = this.value;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
gridData.push(item);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
break;
|
|
78
|
+
case 'jqgrid':
|
|
79
|
+
$($settings.dataset).find("rows > row").each(function (key, value) {
|
|
80
|
+
var item = {};
|
|
81
|
+
|
|
82
|
+
if (this.children != null && this.children.length > 0) {
|
|
83
|
+
$(this.children).each(function () {
|
|
84
|
+
item[this.tagName] = $(this).text();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
gridData.push(item);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function ConvertFromTable() {
|
|
95
|
+
var result = $('<div>').append($('#' + $settings.containerid).clone()).html();
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function ConvertDataStructureToTable() {
|
|
100
|
+
var result = "<table>";
|
|
101
|
+
|
|
102
|
+
result += "<thead><tr>";
|
|
103
|
+
$($settings.columns).each(function (key, value) {
|
|
104
|
+
if (this.ishidden != true) {
|
|
105
|
+
result += "<th";
|
|
106
|
+
if (this.width != null) {
|
|
107
|
+
result += " style='width: " + this.width + "'";
|
|
108
|
+
}
|
|
109
|
+
result += ">";
|
|
110
|
+
result += this.headertext;
|
|
111
|
+
result += "</th>";
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
result += "</tr></thead>";
|
|
115
|
+
|
|
116
|
+
result += "<tbody>";
|
|
117
|
+
$(gridData).each(function (key, value) {
|
|
118
|
+
result += "<tr>";
|
|
119
|
+
$($settings.columns).each(function (k, v) {
|
|
120
|
+
if (value.hasOwnProperty(this.datafield)) {
|
|
121
|
+
if (this.ishidden != true) {
|
|
122
|
+
result += "<td";
|
|
123
|
+
if (this.width != null) {
|
|
124
|
+
result += " style='width: " + this.width + "'";
|
|
125
|
+
}
|
|
126
|
+
result += ">";
|
|
127
|
+
result += value[this.datafield];
|
|
128
|
+
result += "</td>";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
result += "</tr>";
|
|
133
|
+
});
|
|
134
|
+
result += "</tbody>";
|
|
135
|
+
|
|
136
|
+
result += "</table>";
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function Export(htmltable) {
|
|
141
|
+
var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
|
|
142
|
+
excelFile += "<head>";
|
|
143
|
+
excelFile += '<meta http-equiv="Content-type" content="text/html;charset=' + $defaults.encoding + '" />';
|
|
144
|
+
excelFile += "<!--[if gte mso 9]>";
|
|
145
|
+
excelFile += "<xml>";
|
|
146
|
+
excelFile += "<x:ExcelWorkbook>";
|
|
147
|
+
excelFile += "<x:ExcelWorksheets>";
|
|
148
|
+
excelFile += "<x:ExcelWorksheet>";
|
|
149
|
+
excelFile += "<x:Name>";
|
|
150
|
+
excelFile += "{worksheet}";
|
|
151
|
+
excelFile += "</x:Name>";
|
|
152
|
+
excelFile += "<x:WorksheetOptions>";
|
|
153
|
+
excelFile += "<x:DisplayGridlines/>";
|
|
154
|
+
excelFile += "</x:WorksheetOptions>";
|
|
155
|
+
excelFile += "</x:ExcelWorksheet>";
|
|
156
|
+
excelFile += "</x:ExcelWorksheets>";
|
|
157
|
+
excelFile += "</x:ExcelWorkbook>";
|
|
158
|
+
excelFile += "</xml>";
|
|
159
|
+
excelFile += "<![endif]-->";
|
|
160
|
+
excelFile += "</head>";
|
|
161
|
+
excelFile += "<body>";
|
|
162
|
+
excelFile += htmltable.replace(/"/g, '\'');
|
|
163
|
+
excelFile += "</body>";
|
|
164
|
+
excelFile += "</html>";
|
|
165
|
+
|
|
166
|
+
var uri = "data:application/vnd.ms-excel;base64,";
|
|
167
|
+
var ctx = { worksheet: $settings.worksheetName, table: htmltable };
|
|
168
|
+
|
|
169
|
+
return (uri + base64(format(excelFile, ctx)));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function base64(s) {
|
|
173
|
+
return window.btoa(unescape(encodeURIComponent(s)));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function format(s, c) {
|
|
177
|
+
return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; });
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
})(jQuery);
|
|
@@ -0,0 +1,17 @@
|
|
|
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 report_index
|
|
8
|
+
@fact_values = FactValue.all
|
|
9
|
+
@fact_names = FactName.all
|
|
10
|
+
@hosts = Host.all
|
|
11
|
+
respond_to do |format|
|
|
12
|
+
format.html # index.html.erb
|
|
13
|
+
format.json { render json: @hosts }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
class ForemanHosts::SyhostmodeldetailsController < ApplicationController
|
|
2
|
+
# GET /syhostmodeldetails
|
|
3
|
+
# GET /syhostmodeldetails.json
|
|
4
|
+
def index
|
|
5
|
+
@syhostmodeldetails = ForemanHosts::Syhostmodeldetail.all.paginate(:page => params[:page])
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.html # index.html.erb
|
|
9
|
+
format.json { render json: @syhostmodeldetails }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# GET /syhostmodeldetails/1
|
|
14
|
+
# GET /syhostmodeldetails/1.json
|
|
15
|
+
def show
|
|
16
|
+
@syhostmodeldetail = ForemanHosts::Syhostmodeldetail.find(params[:id])
|
|
17
|
+
|
|
18
|
+
respond_to do |format|
|
|
19
|
+
format.html # show.html.erb
|
|
20
|
+
format.json { render json: @syhostmodeldetail }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# GET /syhostmodeldetails/new
|
|
25
|
+
# GET /syhostmodeldetails/new.json
|
|
26
|
+
def new
|
|
27
|
+
@syhostmodeldetail = ForemanHosts::Syhostmodeldetail.new
|
|
28
|
+
respond_to do |format|
|
|
29
|
+
format.html # new.html.erb
|
|
30
|
+
format.json { render json: @syhostmodeldetail }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# GET /syhostmodeldetails/1/edit
|
|
35
|
+
def edit
|
|
36
|
+
@syhostmodeldetail = ForemanHosts::Syhostmodeldetail.find(params[:id])
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# POST /syhostmodeldetails
|
|
40
|
+
# POST /syhostmodeldetails.json
|
|
41
|
+
def create
|
|
42
|
+
@syhostmodeldetail = ForemanHosts::Syhostmodeldetail.new(params[:foreman_hosts_syhostmodeldetail])
|
|
43
|
+
|
|
44
|
+
respond_to do |format|
|
|
45
|
+
if @syhostmodeldetail.save
|
|
46
|
+
format.html { redirect_to @syhostmodeldetail, notice: 'syhostmodeldetail was successfully created.' }
|
|
47
|
+
format.json { render json: @syhostmodeldetail, status: :created, location: @syhostmodeldetail }
|
|
48
|
+
else
|
|
49
|
+
format.html { render action: "new" }
|
|
50
|
+
format.json { render json: @syhostmodeldetail.errors, status: :unprocessable_entity }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# PUT /syhostmodeldetails/1
|
|
56
|
+
# PUT /syhostmodeldetails/1.json
|
|
57
|
+
def update
|
|
58
|
+
@syhostmodeldetail = ForemanHosts::Syhostmodeldetail.find(params[:id])
|
|
59
|
+
|
|
60
|
+
respond_to do |format|
|
|
61
|
+
if @syhostmodeldetail.update_attributes(params[:foreman_hosts_syhostmodeldetail])
|
|
62
|
+
format.html { redirect_to @syhostmodeldetail, notice: 'syhostmodeldetail was successfully updated.' }
|
|
63
|
+
format.json { head :no_content }
|
|
64
|
+
else
|
|
65
|
+
format.html { render action: "edit" }
|
|
66
|
+
format.json { render json: @syhostmodeldetail.errors, status: :unprocessable_entity }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# DELETE /syhostmodeldetails/1
|
|
72
|
+
# DELETE /syhostmodeldetails/1.json
|
|
73
|
+
def destroy
|
|
74
|
+
@syhostmodeldetail = ForemanHosts::Syhostmodeldetail.find(params[:id])
|
|
75
|
+
@syhostmodeldetail.destroy
|
|
76
|
+
respond_to do |format|
|
|
77
|
+
format.html { redirect_to foreman_hosts_syhostmodeldetails_url }
|
|
78
|
+
format.json { head :no_content }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
class ForemanHosts::SyhostmodelsController < ApplicationController
|
|
2
|
+
# GET /syhostmodels
|
|
3
|
+
# GET /syhostmodels.json
|
|
4
|
+
def index
|
|
5
|
+
@syhostmodels = ForemanHosts::Syhostmodel.all.paginate(:page => params[:page])
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.html # index.html.erb
|
|
9
|
+
format.json { render json: @syhostmodels }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# GET /syhostmodels/1
|
|
14
|
+
# GET /syhostmodels/1.json
|
|
15
|
+
def show
|
|
16
|
+
@syhostmodel = ForemanHosts::Syhostmodel.find(params[:id])
|
|
17
|
+
# @syhosts = Host.all
|
|
18
|
+
# @syfactvalues = FactValue.all
|
|
19
|
+
respond_to do |format|
|
|
20
|
+
format.html # show.html.erb
|
|
21
|
+
format.json { render json: @syhostmodel }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# GET /syhostmodels/new
|
|
26
|
+
# GET /syhostmodels/new.json
|
|
27
|
+
def new
|
|
28
|
+
@syhostmodel = ForemanHosts::Syhostmodel.new
|
|
29
|
+
respond_to do |format|
|
|
30
|
+
format.html # new.html.erb
|
|
31
|
+
format.json { render json: @syhostmodel }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# GET /syhostmodels/1/edit
|
|
36
|
+
def edit
|
|
37
|
+
@syhostmodel = ForemanHosts::Syhostmodel.find(params[:id])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# POST /syhostmodels
|
|
41
|
+
# POST /syhostmodels.json
|
|
42
|
+
def create
|
|
43
|
+
@syhostmodel = ForemanHosts::Syhostmodel.new(params[:foreman_hosts_syhostmodel])
|
|
44
|
+
|
|
45
|
+
respond_to do |format|
|
|
46
|
+
if @syhostmodel.save
|
|
47
|
+
format.html { redirect_to @syhostmodel, notice: 'syhostmodel was successfully created.' }
|
|
48
|
+
format.json { render json: @syhostmodel, status: :created, location: @syhostmodel }
|
|
49
|
+
else
|
|
50
|
+
format.html { render action: "new" }
|
|
51
|
+
format.json { render json: @syhostmodel.errors, status: :unprocessable_entity }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# PUT /syhostmodels/1
|
|
57
|
+
# PUT /syhostmodels/1.json
|
|
58
|
+
def update
|
|
59
|
+
@syhostmodel = ForemanHosts::Syhostmodel.find(params[:id])
|
|
60
|
+
|
|
61
|
+
respond_to do |format|
|
|
62
|
+
if @syhostmodel.update_attributes(params[:foreman_hosts_syhostmodel])
|
|
63
|
+
format.html { redirect_to @syhostmodel, notice: 'syhostmodel was successfully updated.' }
|
|
64
|
+
format.json { head :no_content }
|
|
65
|
+
else
|
|
66
|
+
format.html { render action: "edit" }
|
|
67
|
+
format.json { render json: @syhostmodel.errors, status: :unprocessable_entity }
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# DELETE /syhostmodels/1
|
|
73
|
+
# DELETE /syhostmodels/1.json
|
|
74
|
+
def destroy
|
|
75
|
+
@syhostmodel = ForemanHosts::Syhostmodel.find(params[:id])
|
|
76
|
+
@syhostmodel.destroy
|
|
77
|
+
respond_to do |format|
|
|
78
|
+
format.html { redirect_to foreman_hosts_syhostmodels_url }
|
|
79
|
+
format.json { head :no_content }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
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,8 @@
|
|
|
1
|
+
class ForemanHosts::Syhostmodel < ActiveRecord::Base
|
|
2
|
+
|
|
3
|
+
attr_accessible :name, :remark, :syhostmodeldetails_attributes
|
|
4
|
+
has_many :syhostmodeldetails, class_name: "ForemanHosts::Syhostmodeldetail"
|
|
5
|
+
accepts_nested_attributes_for :syhostmodeldetails, reject_if: proc { |attributes| attributes['no'].blank?| attributes['status'].blank? | attributes['fact_name_id'].blank? } , allow_destroy: true
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
end
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
class ForemanHosts::Syhostmodeldetail < ActiveRecord::Base
|
|
2
|
+
attr_accessible :no, :status, :fact_name_id, :syhostmodel_id, :syhostmodel_type
|
|
3
|
+
belongs_to :foreman_hosts_syhostmodel, class_name: "ForemanHosts::Syhostmodel",foreign_key: "syhostmodel_id"
|
|
4
|
+
#belongs_to :fact_name, class_name: "FactName", foreign_key: "fact_name_id"
|
|
5
|
+
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>
|