foreman_virt_who_configure 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.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +35 -0
- data/Rakefile +47 -0
- data/app/assets/javascripts/foreman_virt_who_configure/config_edit.js +31 -0
- data/app/assets/stylesheets/foreman_virt_who_configure/config.css.scss +13 -0
- data/app/controllers/foreman_virt_who_configure/application_controller.rb +11 -0
- data/app/controllers/foreman_virt_who_configure/concerns/config_parameters.rb +22 -0
- data/app/controllers/foreman_virt_who_configure/configs_controller.rb +94 -0
- data/app/helpers/foreman_virt_who_configure/compatibility_helper.rb +22 -0
- data/app/helpers/foreman_virt_who_configure/configs_helper.rb +25 -0
- data/app/models/foreman_virt_who_configure/auth_source_hidden_with_authentication.rb +13 -0
- data/app/models/foreman_virt_who_configure/config.rb +157 -0
- data/app/models/foreman_virt_who_configure/output_generator.rb +152 -0
- data/app/models/foreman_virt_who_configure/service_user.rb +21 -0
- data/app/services/sso/basic_with_hidden.rb +11 -0
- data/app/views/dashboard/_foreman_virt_who_configure_widget.html.erb +2 -0
- data/app/views/foreman_virt_who_configure/configs/_form.html.erb +20 -0
- data/app/views/foreman_virt_who_configure/configs/edit.html.erb +3 -0
- data/app/views/foreman_virt_who_configure/configs/index.html.erb +27 -0
- data/app/views/foreman_virt_who_configure/configs/new.html.erb +3 -0
- data/app/views/foreman_virt_who_configure/configs/show.html.erb +24 -0
- data/app/views/foreman_virt_who_configure/configs/steps/_connection_form.erb +16 -0
- data/app/views/foreman_virt_who_configure/configs/steps/_general_information_form.erb +12 -0
- data/app/views/foreman_virt_who_configure/configs/steps/_schedule_form.erb +4 -0
- data/app/views/foreman_virt_who_configure/configs/welcome.html.erb +14 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20170102152649_create_service_users.rb +12 -0
- data/db/migrate/20170102152650_create_configs.rb +22 -0
- data/db/migrate/20170102152751_add_lab_attrs_to_config.rb +9 -0
- data/db/migrate/20170102152851_add_satellite_url_to_config.rb +5 -0
- data/db/migrate/20170215152851_change_default_interval.rb +9 -0
- data/db/migrate/20170309161551_add_proxy_and_no_proxy_to_config.rb +11 -0
- data/lib/foreman_virt_who_configure/engine.rb +108 -0
- data/lib/foreman_virt_who_configure/version.rb +3 -0
- data/lib/foreman_virt_who_configure.rb +4 -0
- data/lib/tasks/foreman_virt_who_configure_tasks.rake +47 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_virt_who_configure.po +19 -0
- data/locale/foreman_virt_who_configure.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/test/factories/foreman_virt_who_configure_factories.rb +13 -0
- data/test/test_plugin_helper.rb +6 -0
- data/test/unit/config_test.rb +65 -0
- data/test/unit/output_generator_test.rb +89 -0
- metadata +134 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
module ForemanVirtWhoConfigure
|
2
|
+
class OutputGenerator
|
3
|
+
attr_reader :config
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
def ready_for_virt_who_output?
|
10
|
+
missing_virt_who_input_messages.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def missing_virt_who_input_messages
|
14
|
+
messages = []
|
15
|
+
messages.push _('Owner was not provided') unless config.organization_id?
|
16
|
+
messages.push _('Interval was not provided') unless config.interval.present?
|
17
|
+
# messages.push _('Cofiguration not stored') unless config.persisted?
|
18
|
+
# messages.push _('Service user was not provided') unless config.service_user_id.present?
|
19
|
+
messages
|
20
|
+
end
|
21
|
+
|
22
|
+
def virt_who_output
|
23
|
+
<<EOS
|
24
|
+
echo "Installing virt-who.."
|
25
|
+
yum install -y virt-who
|
26
|
+
echo "Encrypting password.."
|
27
|
+
cr_password=`virt-who-password --password "#{cr_password}" 2> /dev/null`
|
28
|
+
user_password=`virt-who-password --password "#{service_user_password}" 2> /dev/null`
|
29
|
+
|
30
|
+
echo "Creating virt-who configuration.."
|
31
|
+
cat > #{config_file_path} << EOF
|
32
|
+
[#{identifier}]
|
33
|
+
type=#{type}
|
34
|
+
hypervisor_id=#{hypervisor_id}
|
35
|
+
owner=#{owner}
|
36
|
+
env=Library
|
37
|
+
server=#{cr_server}
|
38
|
+
username=#{cr_username}
|
39
|
+
encrypted_password=$cr_password#{filtering}
|
40
|
+
rhsm_hostname=#{satellite_url}
|
41
|
+
rhsm_username=#{service_user_username}
|
42
|
+
rhsm_encrypted_password=$user_password
|
43
|
+
rhsm_prefix=/rhsm
|
44
|
+
EOF
|
45
|
+
|
46
|
+
echo "Creating sysconfig virt-who configuration.."
|
47
|
+
cat > /etc/sysconfig/virt-who << EOF
|
48
|
+
VIRTWHO_SATELLITE6=1
|
49
|
+
VIRTWHO_DEBUG=#{config.debug? ? 1 : 0}
|
50
|
+
VIRTWHO_INTERVAL=#{config.interval * 60}#{proxy_strings}
|
51
|
+
EOF
|
52
|
+
|
53
|
+
echo "Enabling and restarting the virt-who service"
|
54
|
+
chkconfig virt-who on
|
55
|
+
service virt-who restart
|
56
|
+
|
57
|
+
echo "Done."
|
58
|
+
EOS
|
59
|
+
end
|
60
|
+
|
61
|
+
def filtering
|
62
|
+
case config.listing_mode.to_i
|
63
|
+
when ForemanVirtWhoConfigure::Config::UNLIMITED
|
64
|
+
return ''
|
65
|
+
when ForemanVirtWhoConfigure::Config::WHITELIST
|
66
|
+
return filtering_line_sanitized('filter_hosts', config.whitelist)
|
67
|
+
when ForemanVirtWhoConfigure::Config::BLACKLIST
|
68
|
+
return filtering_line_sanitized('exclude_hosts', config.blacklist)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def filtering_line_sanitized(filter, list)
|
73
|
+
"\n" + filter + '=' + sanitize_filter(list.to_s)
|
74
|
+
end
|
75
|
+
|
76
|
+
def sanitize_filter(list)
|
77
|
+
sanitize(list)
|
78
|
+
end
|
79
|
+
|
80
|
+
def config_file_path
|
81
|
+
"/etc/virt-who.d/#{identifier}.conf"
|
82
|
+
end
|
83
|
+
|
84
|
+
def identifier
|
85
|
+
"virt-who-config-#{config.id}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def hypervisor_id
|
89
|
+
config.hypervisor_id
|
90
|
+
end
|
91
|
+
|
92
|
+
def owner
|
93
|
+
config.organization.label
|
94
|
+
end
|
95
|
+
|
96
|
+
def type
|
97
|
+
config.hypervisor_type
|
98
|
+
end
|
99
|
+
|
100
|
+
# returns nil if url could not be parsed or is invalid, e.g. qemu:///system
|
101
|
+
def cr_server
|
102
|
+
config.hypervisor_server
|
103
|
+
end
|
104
|
+
|
105
|
+
def cr_username
|
106
|
+
config.hypervisor_username
|
107
|
+
end
|
108
|
+
|
109
|
+
def cr_password
|
110
|
+
config.hypervisor_password
|
111
|
+
end
|
112
|
+
|
113
|
+
def satellite_url
|
114
|
+
config.satellite_url
|
115
|
+
end
|
116
|
+
|
117
|
+
def service_user_username
|
118
|
+
config.service_user.username
|
119
|
+
end
|
120
|
+
|
121
|
+
def service_user_password
|
122
|
+
config.service_user.encrypted_password
|
123
|
+
end
|
124
|
+
|
125
|
+
def cr
|
126
|
+
config.compute_resource
|
127
|
+
end
|
128
|
+
|
129
|
+
def proxy
|
130
|
+
config.proxy
|
131
|
+
end
|
132
|
+
|
133
|
+
def no_proxy
|
134
|
+
config.no_proxy
|
135
|
+
end
|
136
|
+
|
137
|
+
def sanitize_proxy(string)
|
138
|
+
sanitize(string)
|
139
|
+
end
|
140
|
+
|
141
|
+
def proxy_strings
|
142
|
+
output = ''
|
143
|
+
output << "\nhttp_proxy=#{sanitize_proxy(proxy)}" if proxy.present?
|
144
|
+
output << "\nno_proxy=#{sanitize_proxy(no_proxy)}" if no_proxy.present?
|
145
|
+
output
|
146
|
+
end
|
147
|
+
|
148
|
+
def sanitize(string)
|
149
|
+
string.tr("\r\n", '').strip.chomp(",")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ForemanVirtWhoConfigure
|
2
|
+
# holds the encrypted password for internal user that can be deployed to virt who reporter
|
3
|
+
class ServiceUser < ActiveRecord::Base
|
4
|
+
include Authorizable
|
5
|
+
include Encryptable
|
6
|
+
encrypts :encrypted_password
|
7
|
+
|
8
|
+
belongs_to :user
|
9
|
+
has_many :configs
|
10
|
+
|
11
|
+
# Foreman 1.11 specifics, can be removed later, otherwise when string does not start with "encrypts" prefix
|
12
|
+
# we get 500 when we try to create log message that relies on name method
|
13
|
+
def name
|
14
|
+
self.username || self.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def username
|
18
|
+
self.user.login if self.user
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module SSO
|
2
|
+
class BasicWithHidden < Basic
|
3
|
+
def available?
|
4
|
+
controller.api_request? && http_auth_set? && controller.is_a?(::Katello::Api::Rhsm::CandlepinProxiesController)
|
5
|
+
end
|
6
|
+
|
7
|
+
def current_user
|
8
|
+
User.unscoped.where(:auth_source_id => ForemanVirtWhoConfigure::AuthSourceHiddenWithAuthentication.default.id).find_by_login(self.user)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<% javascript 'foreman_virt_who_configure/config_edit' %>
|
2
|
+
|
3
|
+
<%= form_for @config, :as => 'foreman_virt_who_configure_config', :url => (@config.new_record? ? foreman_virt_who_configure_configs_path : foreman_virt_who_configure_config_path(:id => @config)) do |f| %>
|
4
|
+
<%= base_errors_for @config %>
|
5
|
+
|
6
|
+
<div class="tab-content">
|
7
|
+
|
8
|
+
<% @config.steps.each do |step| %>
|
9
|
+
<fieldset>
|
10
|
+
<h3><%= @config.step_name(step) %></h3>
|
11
|
+
<hr>
|
12
|
+
<%= render :partial => "foreman_virt_who_configure/configs/steps/#{step.downcase.tr(' ', '_')}_form", :locals => { :f => f } %>
|
13
|
+
</fieldset>
|
14
|
+
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<%= submit_or_cancel f %>
|
20
|
+
<% end %>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<% title _("Configs") %>
|
2
|
+
|
3
|
+
<% title_actions new_config_link, help_button_or_path %>
|
4
|
+
|
5
|
+
<table class="<%= table_css_classes 'table-fixed' %>">
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th class="col-md-8"><%= sort :name, :as => s_("Config|Title") %></th>
|
9
|
+
<th><%= s_("Config|Interval") %></th>
|
10
|
+
<th><%= _('Actions') %></th>
|
11
|
+
</tr>
|
12
|
+
</thead>
|
13
|
+
<tbody>
|
14
|
+
<% @configs.each do |config| %>
|
15
|
+
<tr>
|
16
|
+
<td class="display-two-pane ellipsis"><%= link_to_if_authorized (config.title), hash_for_foreman_virt_who_configure_config_path(:id => config).merge(:auth_object => config, :authorizer => authorizer) %></td>
|
17
|
+
<td><%= config.humanized_interval %></td>
|
18
|
+
<td class="col-md-1"><%= action_buttons(
|
19
|
+
display_link_if_authorized(_('Edit'), hash_for_edit_foreman_virt_who_configure_config_path(:id => config).merge(:auth_object => config, :authorizer => authorizer)),
|
20
|
+
display_delete_if_authorized((hash_for_foreman_virt_who_configure_config_path(:id => config).merge(:auth_object => config, :authorizer => authorizer)), :data => { :confirm => _("Delete virt-who configuration %s?") % config.title })
|
21
|
+
) %></td>
|
22
|
+
</tr>
|
23
|
+
<% end %>
|
24
|
+
</tbody>
|
25
|
+
</table>
|
26
|
+
|
27
|
+
<%= will_paginate_with_info @configs %>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<% stylesheet 'foreman_virt_who_configure/config' %>
|
2
|
+
|
3
|
+
<div class="clearfix">
|
4
|
+
<div class="form-group">
|
5
|
+
<div class="row">
|
6
|
+
<div class="col-md-12">
|
7
|
+
<label><%= _("Run this script on the target host which will run virt-who reporting, preferably Satellite host:") %></label>
|
8
|
+
<p>
|
9
|
+
<%= _("1. Copy this configuration script to a safe directory on the host.") %></br>
|
10
|
+
<%= _("2. Make the script executable and run it on the host.") %></br>
|
11
|
+
<%= _("3. Delete the script on the host.") %></br>
|
12
|
+
</p>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="row">
|
17
|
+
<div class="col-md-8">
|
18
|
+
<pre class="terminal"><%= @config.virt_who_config_file %></pre>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<%= link_to _('Change this configuration'), edit_foreman_virt_who_configure_config_path(@config), :class => 'btn btn-default' %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div id="config_connection">
|
2
|
+
<%= text_f f, :satellite_url, :help_inline => popover('', _('Satellite Server’s fully-qualified host name, for example: satellite.example.com')), :label => _('Satellite Server FQDN') %>
|
3
|
+
<%= select_f f, :hypervisor_id, ForemanVirtWhoConfigure::Config::HYPERVISOR_IDS, :to_s, :to_s, {}, :label => _('Hypervisor ID'),
|
4
|
+
:help_inline => popover('', _("Specifies that hypervisors will be identified by their <b>hostname</b>, <b>uuid</b> or <b>hwuuid</b>.
|
5
|
+
Note that some virtualization backends don't have all of them implemented.
|
6
|
+
Default is <b>uuid</b>, which we also recommend to use. <b>hostname</b> provides more meaningful hypervisor
|
7
|
+
names but can cause duplicated hypervisor registrations if the host is renamed. <b>hwuuid</b> is applicable to esx and rhevm only.
|
8
|
+
This property is meant to be set up before the initial run of virt-who. Changing it later will result in duplicated entries in the subscription manager.").html_safe) %>
|
9
|
+
<%= select_f f, :listing_mode, ForemanVirtWhoConfigure::Config::FILTERING_MODES, :first, :last, {}, :label => _('Filtering'),
|
10
|
+
:help_inline => popover('', _("If you run a hybrid environment, with virtual machines running Red Hat Enterprise Linux and other operating systems, you may want to limit the scope of virt-who’s access to hosts. For example, if some hypervisors host only Microsoft Windows Server instances, there is no benefit in having those hypervisors reported by the virt-who agent."))%>
|
11
|
+
<%= textarea_f f, :whitelist, :help_inline => popover('', _('Only hosts which uuid (or hostname or hwuuid, based on <code>hypervisor_id</code>) is specified in comma-separated list in this option will be reported. Wildcards and regular expressions are supported, multiple records must be separated by comma. Put the value into the double-quotes if it contains special characters like comma. All new line characters will be removed in resulting configuration file, white spaces are removed from beginning and end.')), :label => _('Filter hosts') %>
|
12
|
+
<%= textarea_f f, :blacklist, :help_inline => popover('', _('Hosts which uuid (or hostname or hwuuid, based on <code>hypervisor_id</code>) is specified in comma-separated list in this option will <b>NOT</b> be reported. Wildcards and regular expressions are supported, multiple records must be separated by comma. Put the value into the double-quotes if it contains special characters like comma. All new line characters will be removed in resulting configuration file, white spaces are removed from beginning and end.').html_safe), :label => _('Exclude hosts') %>
|
13
|
+
<%= checkbox_f f, :debug, :label => _('Do you want to enable debugging output?') %>
|
14
|
+
<%= text_f f, :proxy, :help_inline => popover('', _('HTTP proxy that should be used for communication between the server on which virt-who is running and the hypervisors and virtualization managers. Leave this blank if no proxy is used.')), :label => _('HTTP Proxy') %>
|
15
|
+
<%= text_f f, :no_proxy, :help_inline => popover('', _('A comma-separated list of hostnames or domains or ip addresses to ignore proxy settings for. Optionally this may be set to <code>*</code> to bypass proxy settings for all hostnames domains or ip addresses.')), :label => _('Ignore Proxy') %>
|
16
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div id="config_general_information">
|
2
|
+
<% if f.object.organization_id.present? %>
|
3
|
+
<%= f.hidden_field :organization_id %>
|
4
|
+
<% else %>
|
5
|
+
<%= select_f f, :organization_id, Organization.authorized(:view_organizations), :id, :to_s, {}, :label => _('Owner') %>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<%= select_f f, :hypervisor_type, ForemanVirtWhoConfigure::Config::HYPERVISOR_TYPES, :first, :last %>
|
9
|
+
<%= text_f f, :hypervisor_server, :help_inline => popover('', hypervisor_server_help_data[f.object.hypervisor_type].html_safe), :data => { :help => hypervisor_server_help_data } %>
|
10
|
+
<%= text_f f, :hypervisor_username, :help_inline => popover('', hypervisor_username_help_data[f.object.hypervisor_type].html_safe), :data => { :help => hypervisor_username_help_data } %>
|
11
|
+
<%= password_f f, :hypervisor_password, :value => f.object.hypervisor_password, :help_inline => popover('', _('Account password by which virt-who is to connect to the hypervisor instance.')) %>
|
12
|
+
</div>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<div id="config_schedule">
|
2
|
+
<%= select_f f, :interval, ForemanVirtWhoConfigure::Config::AVAILABLE_INTERVALS, :first, :last, {},
|
3
|
+
:help_inline => popover('', _("How often to check connected hypervisors for changes? Also affects how often a mapping is reported. The recommended value for most environments is every two hours.")) %>
|
4
|
+
</div>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<div class="blank-slate-pf">
|
2
|
+
<div class="blank-slate-pf-icon">
|
3
|
+
<%= icon_text("globe", "", :kind => "fa") %>
|
4
|
+
</div>
|
5
|
+
<h1><%= _('Configs') %></h1>
|
6
|
+
<p>
|
7
|
+
<%= _("On this page you can define virt-who configurations for your hypervisors.") %></br>
|
8
|
+
<%= _("One virt-who configuration represents one config file in /etc/virt-who.d directory and maps to single hypervisor, organization and lifecycle environment.") %></br>
|
9
|
+
<%= _("To define a new configuration, click the New Config button and fill in the form. After you provide all required information a virt-who configuration script will be generated. You could either install it manually by copying the script or deploy it on a selected target host through Remote Execution.") %></br>
|
10
|
+
</p>
|
11
|
+
<div class="blank-slate-pf-main-action">
|
12
|
+
<%= new_config_link({}, { :class => "btn btn-primary btn-lg" }) %>
|
13
|
+
</div>
|
14
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateServiceUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :foreman_virt_who_configure_service_users do |t|
|
4
|
+
t.string :encrypted_password, :null => false
|
5
|
+
t.references :user, :index => { :name => 'fvwc_su_user_id' }, :null => false
|
6
|
+
|
7
|
+
t.timestamps :null => false
|
8
|
+
end
|
9
|
+
|
10
|
+
add_foreign_key :foreman_virt_who_configure_service_users, :users, :column => :user_id
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateConfigs < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :foreman_virt_who_configure_configs do |t|
|
4
|
+
t.integer :interval, :default => 60, :null => true
|
5
|
+
# this is not a foreign key but one of 'hostname', 'uuid', 'hwuuid'
|
6
|
+
t.string :hypervisor_id, :null => true
|
7
|
+
t.integer :listing_mode, :null => true
|
8
|
+
t.text :whitelist, :null => true
|
9
|
+
t.text :blacklist, :null => true
|
10
|
+
|
11
|
+
t.references :compute_resource, :index => { :name => 'fvwc_c_compute_resource_id' }, :null => true
|
12
|
+
t.references :organization, :index => { :name => 'fvwc_c_oragnization_id' }, :null => true
|
13
|
+
t.references :service_user, :index => { :name => 'fvwc_su_service_user' }, :null => true
|
14
|
+
|
15
|
+
t.timestamps :null => false
|
16
|
+
end
|
17
|
+
|
18
|
+
add_foreign_key :foreman_virt_who_configure_configs, :compute_resources, :column => :compute_resource_id
|
19
|
+
add_foreign_key :foreman_virt_who_configure_configs, :taxonomies, :column => :organization_id
|
20
|
+
add_foreign_key :foreman_virt_who_configure_configs, :foreman_virt_who_configure_service_users, :column => :service_user_id
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class AddLabAttrsToConfig < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :foreman_virt_who_configure_configs, :debug, :boolean, :default => false, :null => true
|
4
|
+
add_column :foreman_virt_who_configure_configs, :hypervisor_type, :string, :null => true
|
5
|
+
add_column :foreman_virt_who_configure_configs, :hypervisor_server, :string, :null => true
|
6
|
+
add_column :foreman_virt_who_configure_configs, :hypervisor_username, :string, :null => true
|
7
|
+
add_column :foreman_virt_who_configure_configs, :hypervisor_password, :string, :null => true
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class ChangeDefaultInterval < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
change_column :foreman_virt_who_configure_configs, :interval, :integer, :default => 120
|
4
|
+
end
|
5
|
+
|
6
|
+
def down
|
7
|
+
change_column :foreman_virt_who_configure_configs, :interval, :integer, :default => 60
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AddProxyAndNoProxyToConfig < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :foreman_virt_who_configure_configs, :proxy, :string
|
4
|
+
add_column :foreman_virt_who_configure_configs, :no_proxy, :string
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
remove_column :foreman_virt_who_configure_configs, :no_proxy
|
9
|
+
remove_column :foreman_virt_who_configure_configs, :proxy
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'katello'
|
2
|
+
|
3
|
+
module ForemanVirtWhoConfigure
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
engine_name 'foreman_virt_who_configure'
|
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}/test/"]
|
11
|
+
|
12
|
+
# Add any db migrations
|
13
|
+
initializer 'foreman_virt_who_configure.load_app_instance_data' do |app|
|
14
|
+
ForemanVirtWhoConfigure::Engine.paths['db/migrate'].existent.each do |path|
|
15
|
+
app.config.paths['db/migrate'] << path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
initializer 'foreman_virt_who_configure.register_plugin', :before => :finisher_hook do |_app|
|
20
|
+
Foreman::Plugin.register :foreman_virt_who_configure do
|
21
|
+
requires_foreman '>= 1.11'
|
22
|
+
requires_foreman_plugin 'katello', '>= 3.0.0'
|
23
|
+
|
24
|
+
# Add permissions
|
25
|
+
security_block :foreman_virt_who_configure do
|
26
|
+
permission :view_virt_who_config, :'foreman_virt_who_configure/configs' => [:index, :show, :auto_complete_search], :resource_type => 'ForemanVirtWhoConfigure::Config'
|
27
|
+
permission :create_virt_who_config, :'foreman_virt_who_configure/configs' => [:new, :create], :resource_type => 'ForemanVirtWhoConfigure::Config'
|
28
|
+
permission :edit_virt_who_config, :'foreman_virt_who_configure/configs' => [:edit, :update], :resource_type => 'ForemanVirtWhoConfigure::Config'
|
29
|
+
permission :destroy_virt_who_config, :'foreman_virt_who_configure/configs' => [:destroy], :resource_type => 'ForemanVirtWhoConfigure::Config'
|
30
|
+
end
|
31
|
+
|
32
|
+
reporter_permissions = [ :create_hosts, :edit_hosts, :view_lifecycle_environments, :my_organizations ]
|
33
|
+
begin
|
34
|
+
if Permission.where(:name => ['create_content_hosts', 'edit_content_hosts']).count > 0
|
35
|
+
# old Katello permissions detected (6.2 era)
|
36
|
+
reporter_permissions += [:create_content_hosts, :edit_content_hosts]
|
37
|
+
end
|
38
|
+
rescue ActiveRecord::StatementInvalid
|
39
|
+
# permissions could not be loaded, probably migration hasn't been run yet
|
40
|
+
end
|
41
|
+
|
42
|
+
begin
|
43
|
+
role 'Virt-who Reporter', reporter_permissions
|
44
|
+
rescue ArgumentError
|
45
|
+
# could not configure role, some permissions are missing
|
46
|
+
end
|
47
|
+
|
48
|
+
role 'Virt-who Manager', [ :view_virt_who_config, :create_virt_who_config, :edit_virt_who_config, :destroy_virt_who_config ]
|
49
|
+
role 'Virt-who Viewer', [ :view_virt_who_config ]
|
50
|
+
|
51
|
+
# add menu entry
|
52
|
+
menu :top_menu, :virt_who_configs,
|
53
|
+
url_hash: { controller: 'foreman_virt_who_configure/configs', action: :index },
|
54
|
+
caption: N_('Virt-who configurations'),
|
55
|
+
parent: :infrastructure_menu,
|
56
|
+
after: :compute_resources
|
57
|
+
|
58
|
+
# add dashboard widget
|
59
|
+
# widget 'foreman_virt_who_configure_widget', name: N_('Foreman plugin template widget'), sizex: 4, sizey: 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Precompile any JS or CSS files under app/assets/
|
64
|
+
# If requiring files from each other, list them explicitly here to avoid precompiling the same
|
65
|
+
# content twice.
|
66
|
+
assets_to_precompile =
|
67
|
+
Dir.chdir(root) do
|
68
|
+
Dir['app/assets/javascripts/foreman_virt_who_configure/**/*', 'app/assets/stylesheets/foreman_virt_who_configure/**/*'].map do |f|
|
69
|
+
f.split(File::SEPARATOR, 4).last.gsub(/\.scss\Z/, '')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
initializer 'foreman_virt_who_configure.assets.precompile' do |app|
|
73
|
+
app.config.assets.precompile += assets_to_precompile
|
74
|
+
end
|
75
|
+
initializer 'foreman_virt_who_configure.configure_assets', group: :assets do
|
76
|
+
SETTINGS[:foreman_virt_who_configure] = { assets: { precompile: assets_to_precompile } }
|
77
|
+
end
|
78
|
+
|
79
|
+
# Include concerns in this config.to_prepare block
|
80
|
+
config.to_prepare do
|
81
|
+
SSO::METHODS.unshift SSO::BasicWithHidden
|
82
|
+
end
|
83
|
+
|
84
|
+
rake_tasks do
|
85
|
+
Rake::Task['db:seed'].enhance do
|
86
|
+
ForemanVirtWhoConfigure::Engine.load_seed
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
initializer 'foreman_virt_who_configure.register_gettext', after: :load_config_initializers do |_app|
|
91
|
+
locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
|
92
|
+
locale_domain = 'foreman_virt_who_configure'
|
93
|
+
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.with_katello?
|
98
|
+
(Katello rescue false) ? true : false
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.table_name_prefix
|
102
|
+
"foreman_virt_who_configure_"
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.use_relative_model_naming?
|
106
|
+
true
|
107
|
+
end
|
108
|
+
end
|