foreman-katello-engine 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
class ActivationKeysController < ApplicationController
|
2
2
|
def index
|
3
|
-
|
3
|
+
if org = Organization.find_by_id(params[:environment_id])
|
4
|
+
if match = org.name.match(/\Akt-\[(.*)\]\[(.*)\]\Z/)
|
5
|
+
org_name, env_name = match[1], match[2]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
ak_data = ForemanKatelloEngine::Bindings.activation_keys_to_subscriptions(org_name, env_name)
|
10
|
+
render :status => 200, :json => ak_data, :content_type => 'application/json'
|
4
11
|
end
|
5
12
|
end
|
@@ -1,11 +1,34 @@
|
|
1
1
|
<%= javascript_tag do %>
|
2
2
|
|
3
3
|
$(function() {
|
4
|
-
var KT_AK_LABEL = "<%= kt_ak_label %>"
|
5
|
-
var availableActivationKeys =
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
var KT_AK_LABEL = "<%= kt_ak_label %>";
|
5
|
+
var availableActivationKeys = {};
|
6
|
+
|
7
|
+
function ktLoadActivationKeys() {
|
8
|
+
$("#ak-subscriptions-info").hide();
|
9
|
+
$("#ak-subscriptions-spinner").show();
|
10
|
+
var url = foreman_url('/activation_keys');
|
11
|
+
var environmentId = $("#kt_environment_id").val();
|
12
|
+
if(environmentId) {
|
13
|
+
$.ajax({
|
14
|
+
type: 'get',
|
15
|
+
url: url,
|
16
|
+
data:'environment_id=' + environmentId,
|
17
|
+
success: function(response) {
|
18
|
+
availableActivationKeys = response;
|
19
|
+
},
|
20
|
+
error: function(error) {
|
21
|
+
$.jnotify("Error while loading activation keys from Katello", { type: "error", sticky: true });
|
22
|
+
},
|
23
|
+
complete: function() {
|
24
|
+
ktAkUpdateSubscriptionsInfo();
|
25
|
+
}
|
26
|
+
});
|
27
|
+
} else {
|
28
|
+
availableActivationKeys = {};
|
29
|
+
ktAkUpdateSubscriptionsInfo();
|
30
|
+
}
|
31
|
+
}
|
9
32
|
|
10
33
|
function ktFindParamContainer(name){
|
11
34
|
var ret;
|
@@ -136,7 +159,7 @@ $(function() {
|
|
136
159
|
ktSetParam(KT_AK_LABEL, ktActivationKeysValue);
|
137
160
|
}
|
138
161
|
|
139
|
-
function
|
162
|
+
function ktAkUpdateSubscriptionsInfo() {
|
140
163
|
var subsInfo = $("ul#ak-subscriptions-info");
|
141
164
|
subsInfo.empty();
|
142
165
|
var selectedKeys = $("#kt_activation_keys").val().split(/,\s*/);
|
@@ -144,19 +167,25 @@ $(function() {
|
|
144
167
|
if(availableActivationKeys[key]) {
|
145
168
|
// hack to make it working with deface
|
146
169
|
var ul = "<ul>", ul_end = "</ul>", li = "<li>", li_end = "</li>";
|
147
|
-
content = li + key + ul
|
148
|
-
|
149
|
-
|
170
|
+
content = li + key + ul;
|
171
|
+
if(!availableActivationKeys[key].length == 0) {
|
172
|
+
content += li;
|
173
|
+
content += availableActivationKeys[key].join(li_end + li);
|
174
|
+
content += li_end;
|
175
|
+
}
|
176
|
+
content += ul_end + li_end;
|
150
177
|
subsInfo.append(content);
|
151
178
|
}
|
152
179
|
});
|
180
|
+
$("#ak-subscriptions-info").show();
|
181
|
+
$("#ak-subscriptions-spinner").hide();
|
153
182
|
}
|
154
183
|
|
155
184
|
function ktOnLoad() {
|
156
185
|
ktHideParams();
|
157
186
|
ktParamToAkInput();
|
158
|
-
ktAkUpdateubscriptionsInfo();
|
159
187
|
ktOrganizationsToKtEnv();
|
188
|
+
ktLoadActivationKeys();
|
160
189
|
};
|
161
190
|
|
162
191
|
function ktOnSubmit() {
|
@@ -191,11 +220,11 @@ $(function() {
|
|
191
220
|
select: function(event, ui) {
|
192
221
|
var oldTerms = this.value.replace(/[^, ][^,]*$/,"");
|
193
222
|
this.value = oldTerms + ui.item.value;
|
194
|
-
|
223
|
+
ktAkUpdateSubscriptionsInfo();
|
195
224
|
return false;
|
196
225
|
},
|
197
226
|
close: function() {
|
198
|
-
|
227
|
+
ktAkUpdateSubscriptionsInfo();
|
199
228
|
}
|
200
229
|
|
201
230
|
}).bind("focus", function(event) {
|
@@ -203,6 +232,13 @@ $(function() {
|
|
203
232
|
$(this).autocomplete( "search" );
|
204
233
|
}});
|
205
234
|
|
235
|
+
$("#kt_environment_id").change(ktLoadActivationKeys);
|
236
|
+
|
237
|
+
$("#ak_refresh_subscriptions").click(function () {
|
238
|
+
ktLoadActivationKeys();
|
239
|
+
return false;
|
240
|
+
});
|
241
|
+
|
206
242
|
});
|
207
243
|
|
208
244
|
<% end %>
|
@@ -217,6 +253,12 @@ $(function() {
|
|
217
253
|
<p><b>Subscriptions information based on selected activation keys:</b></p>
|
218
254
|
<ul id="ak-subscriptions-info">
|
219
255
|
</ul>
|
220
|
-
<
|
256
|
+
<div id="ak-subscriptions-spinner" style="display: none">
|
257
|
+
<%= image_tag "spinner.gif" %>
|
258
|
+
</div>
|
259
|
+
<p>Activation keys and subscriptions can be managed
|
260
|
+
<b><a href="<%= Setting['katello_url'] %>/activation_keys" target="_blank">here</a></b>
|
261
|
+
</p>
|
262
|
+
<p><a href="" id="ak_refresh_subscriptions">Reload data from Katello</a></p>
|
221
263
|
</div>
|
222
264
|
</div>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "foreman-katello-engine"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.3"
|
4
4
|
|
5
5
|
s.authors = ["Katello"]
|
6
6
|
s.date = "2013-03-04"
|
@@ -10,5 +10,6 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://katello.org"
|
11
11
|
s.licenses = ["GPL-2"]
|
12
12
|
s.require_paths = ["lib"]
|
13
|
+
s.add_dependency "katello_api"
|
13
14
|
s.summary = "Katello specific parts of Foreman"
|
14
15
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'katello_api'
|
2
|
+
|
3
|
+
module ForemanKatelloEngine
|
4
|
+
module Bindings
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def initialize_settings
|
9
|
+
# proceed only if db set up correctly
|
10
|
+
Setting.first rescue return
|
11
|
+
[
|
12
|
+
Foreman::DefaultSettings::Loader.set('katello_url', 'url of a Katello instance', 'https://localhost/katello')
|
13
|
+
].each { |s| Foreman::DefaultSettings::Loader.create(s.update(:category => "General")) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def client_config
|
17
|
+
{
|
18
|
+
:base_url => Setting['katello_url'],
|
19
|
+
:enable_validations => false,
|
20
|
+
:oauth => {
|
21
|
+
:consumer_key => Setting['oauth_consumer_key'],
|
22
|
+
:consumer_secret => Setting['oauth_consumer_secret']
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def environment
|
28
|
+
KatelloApi::Resources::Environment.new(client_config)
|
29
|
+
end
|
30
|
+
|
31
|
+
def activation_key
|
32
|
+
KatelloApi::Resources::ActivationKey.new(client_config)
|
33
|
+
end
|
34
|
+
|
35
|
+
def activation_keys_to_subscriptions(org_name, env_name)
|
36
|
+
environments, _ = self.environment.index('organization_id' => org_name, :name => env_name)
|
37
|
+
if environment = environments.first
|
38
|
+
activation_keys, _ = self.activation_key.index('environment_id' => environment['id'])
|
39
|
+
return activation_keys.reduce({}) do |h, ak|
|
40
|
+
h.update(ak['name'] => ak['pools'].map { |pool| pool['subscription'] })
|
41
|
+
end
|
42
|
+
else
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
@@ -4,6 +4,8 @@ module ForemanKatelloEngine
|
|
4
4
|
class Engine < ::Rails::Engine
|
5
5
|
|
6
6
|
initializer 'foreman_katello_engine.helper' do |app|
|
7
|
+
require 'foreman_katello_engine/bindings'
|
8
|
+
ForemanKatelloEngine::Bindings.initialize_settings
|
7
9
|
ActionView::Base.send :include, ForemanKatelloEngine::HostsAndHostgroupsHelper
|
8
10
|
end
|
9
11
|
|
metadata
CHANGED
@@ -1,22 +1,45 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-katello-engine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Katello
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
17
|
+
|
18
|
+
date: 2013-03-04 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: katello_api
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
14
34
|
description: Katello specific parts of Foreman
|
15
35
|
email: katello-devel@redhat.com
|
16
36
|
executables: []
|
37
|
+
|
17
38
|
extensions: []
|
39
|
+
|
18
40
|
extra_rdoc_files: []
|
19
|
-
|
41
|
+
|
42
|
+
files:
|
20
43
|
- .gitignore
|
21
44
|
- Gemfile
|
22
45
|
- LICENSE
|
@@ -31,30 +54,40 @@ files:
|
|
31
54
|
- foreman-katello-engine.gemspec
|
32
55
|
- lib/foreman-katello-engine.rb
|
33
56
|
- lib/foreman_katello_engine.rb
|
57
|
+
- lib/foreman_katello_engine/bindings.rb
|
34
58
|
- lib/foreman_katello_engine/engine.rb
|
35
59
|
homepage: http://katello.org
|
36
|
-
licenses:
|
60
|
+
licenses:
|
37
61
|
- GPL-2
|
38
62
|
post_install_message:
|
39
63
|
rdoc_options: []
|
40
|
-
|
64
|
+
|
65
|
+
require_paths:
|
41
66
|
- lib
|
42
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
68
|
none: false
|
44
|
-
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
77
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
54
85
|
requirements: []
|
86
|
+
|
55
87
|
rubyforge_project:
|
56
88
|
rubygems_version: 1.8.25
|
57
89
|
signing_key:
|
58
90
|
specification_version: 3
|
59
91
|
summary: Katello specific parts of Foreman
|
60
92
|
test_files: []
|
93
|
+
|