foreman-katello-engine 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ <style>
2
+ option.kt-env { margin-left: 0em; }
3
+ option.kt-cv { margin-left: 1em; }
4
+ </style>
5
+
6
+ <%= field(f, :environment_id, {:include_blank => true}) do
7
+ f.select :environment_id,
8
+ grouped_env_options,
9
+ {:include_blank =>true},
10
+ {:onchange => 'update_puppetclasses(this);',
11
+ :"data-url" => environment_selected_hostgroups_path,
12
+ :'data-host-id' => (@host && @host.id)}
13
+ end %>
@@ -0,0 +1,3 @@
1
+ <li id="activation_keys_tab">
2
+ <a href="#activation_keys" data-toggle="tab">Activation Keys</a>
3
+ </li>
@@ -0,0 +1,250 @@
1
+ <%= javascript_tag do %>
2
+
3
+ $(function() {
4
+ var KT_AK_LABEL = "<%= kt_ak_label %>";
5
+ var availableActivationKeys = {};
6
+
7
+ function ktLoadActivationKeys() {
8
+ if(ktSelectedOrgEnvCv()[0]) {
9
+ ktAkTab().show();
10
+ } else {
11
+ ktAkTab().hide();
12
+ return; //no Katello-specific env selected
13
+ }
14
+
15
+ $("#ak-subscriptions-info").hide();
16
+ $("#ak-subscriptions-spinner").show();
17
+ var url = foreman_url('/foreman_katello_engine/activation_keys');
18
+ var environmentId = $("#hostgroup_environment_id").val();
19
+ if(environmentId) {
20
+ $.ajax({
21
+ type: 'get',
22
+ url: url,
23
+ data:'environment_id=' + environmentId,
24
+ success: function(response) {
25
+ availableActivationKeys = response;
26
+ },
27
+ error: function(error) {
28
+ $.jnotify("Error while loading activation keys from Katello", { type: "error", sticky: true });
29
+ },
30
+ complete: function() {
31
+ ktAkUpdateSubscriptionsInfo();
32
+ }
33
+ });
34
+ } else {
35
+ availableActivationKeys = {};
36
+ ktAkUpdateSubscriptionsInfo();
37
+ }
38
+ }
39
+
40
+ function ktFindParamContainer(name){
41
+ var ret;
42
+ $("div#parameters div.control-group input[ type = 'text']").each(function () {
43
+ element = $(this);
44
+ if(element.val() == name) {
45
+ ret = element.parent();
46
+ return false;
47
+ }
48
+ });
49
+ return ret;
50
+ }
51
+
52
+ function ktOrganizations() {
53
+ return $.grep($("#organizations #hostgroup_organization_ids option"), function (el) {
54
+ return $(el).text().trim().match(/^KT-/)
55
+ });
56
+ }
57
+
58
+ function ktParseOrgName(frOrgName) {
59
+ return frOrgName.match(/^kt-\[(.*)\]\[(.*)\]$/);
60
+ }
61
+
62
+ function ktHideParams() {
63
+ var paramsToHide = [ktFindParamContainer(KT_AK_LABEL),
64
+ ktFindParamContainer('kt_org'),
65
+ ktFindParamContainer('kt_env')];
66
+ $.each(paramsToHide, function (i, paramContainer) {
67
+ if(paramContainer) {
68
+ paramContainer.hide();
69
+ }
70
+ });
71
+ }
72
+
73
+ function ktSelectedOrgEnvCv() {
74
+ var selectedEnvId = $("#hostgroup_environment_id").val();
75
+ var selectedOption = $("#hostgroup_environment_id option[ value ='" + selectedEnvId + "' ]");
76
+
77
+ var ktEnvOption, ktCvOption, ktOrgLabel, ktEnvLabel, ktCvLabel;
78
+ if(selectedOption.hasClass('kt-cv')) {
79
+ ktCvOption = selectedOption;
80
+ ktEnvOption = ktCvOption.prevAll('option.kt-env').first();
81
+ } else if(selectedOption.hasClass('kt-env')) {
82
+ ktEnvOption = selectedOption;
83
+ }
84
+
85
+ if(ktEnvOption) {
86
+ ktEnvLabel = ktEnvOption.text();
87
+ ktOrgLabel = ktEnvOption.parent().attr('label');
88
+ }
89
+
90
+ if(ktCvOption) {
91
+ ktCvLabel = ktCvOption.text();
92
+ }
93
+ return [ktOrgLabel, ktEnvLabel, ktCvLabel];
94
+ }
95
+
96
+ function ktSetParam(name, value) {
97
+ var paramContainer = ktFindParamContainer(name);
98
+ if(value) {
99
+ if(! paramContainer) { // we create the param for kt_activation_keys
100
+ $("div#parameters a.btn-success").click();
101
+ paramContainer = $("div#parameters div.control-group").last();
102
+ paramContainer.find("input").val(name);
103
+ }
104
+ paramContainer.find("textarea").val(value);
105
+ } else if(paramContainer) {
106
+ // we remove the param by setting destoy to 1
107
+ paramContainer.find("input[ type = 'hidden' ]").val(1);
108
+ }
109
+
110
+ }
111
+
112
+ function ktEnvToParam() {
113
+ var orgEnvCv = ktSelectedOrgEnvCv() || [];
114
+ ktSetParam('kt_org', orgEnvCv[0]);
115
+ ktSetParam('kt_env', orgEnvCv[1]);
116
+ ktSetParam('kt_cv', orgEnvCv[2]);
117
+ }
118
+
119
+ function ktEnvToFrOrganizations() {
120
+ var orgEnvCv = ktSelectedOrgEnvCv() || [];
121
+
122
+ var orgName = "";
123
+ if(orgEnvCv[0]) {
124
+ orgName = 'KT-[' + orgEnvCv[0] + ']';
125
+ }
126
+
127
+ $.each(ktOrganizations(), function (i, option) {
128
+ if(orgName == $(option).text().trim()) {
129
+ $("#hostgroup_organization_ids").multiSelect('select', $(option).val());
130
+ } else {
131
+ $("#hostgroup_organization_ids").multiSelect('deselect', $(option).val());
132
+ }
133
+ });
134
+ }
135
+
136
+ function ktParamToAkInput() {
137
+ var paramContainer = ktFindParamContainer(KT_AK_LABEL);
138
+ if(paramContainer) {
139
+ $("#kt_activation_keys").val(paramContainer.find("textarea").val());
140
+ }
141
+ }
142
+
143
+ function ktAkInputToParam() {
144
+ var ktActivationKeysValue = $("#kt_activation_keys").val().replace(/,\s*/g,",").replace(/,$/g,"");
145
+ ktSetParam(KT_AK_LABEL, ktActivationKeysValue);
146
+ }
147
+
148
+ function ktAkUpdateSubscriptionsInfo() {
149
+ var subsInfo = $("ul#ak-subscriptions-info");
150
+ subsInfo.empty();
151
+ var selectedKeys = $("#kt_activation_keys").val().split(/,\s*/);
152
+ $.each(selectedKeys, function(i, key) {
153
+ if(availableActivationKeys[key]) {
154
+ // hack to make it working with deface
155
+ var ul = "<ul>", ul_end = "</ul>", li = "<li>", li_end = "</li>";
156
+ content = li + key + ul;
157
+ if(!availableActivationKeys[key].length == 0) {
158
+ content += li;
159
+ content += availableActivationKeys[key].join(li_end + li);
160
+ content += li_end;
161
+ }
162
+ content += ul_end + li_end;
163
+ subsInfo.append(content);
164
+ }
165
+ });
166
+ $("#ak-subscriptions-info").show();
167
+ $("#ak-subscriptions-spinner").hide();
168
+ }
169
+
170
+ function ktAkTab() {
171
+ return $('li#activation_keys_tab');
172
+ }
173
+
174
+ function ktOnLoad() {
175
+ ktHideParams();
176
+ ktParamToAkInput();
177
+ ktLoadActivationKeys();
178
+ };
179
+
180
+ function ktOnSubmit() {
181
+ ktAkInputToParam();
182
+ ktEnvToParam();
183
+ ktEnvToFrOrganizations();
184
+ }
185
+
186
+
187
+ $("#kt_activation_keys").parents("form").submit(ktOnSubmit);
188
+
189
+ ktOnLoad();
190
+
191
+ $("#kt_activation_keys").autocomplete({
192
+ minLength: 0,
193
+ source: function(request, response) {
194
+ var terms = request.term.split(/,\s*/);
195
+ var part = terms.pop();
196
+ var items = []
197
+ for(key in availableActivationKeys) {
198
+ if(terms.indexOf(key) == -1) {
199
+ items.push(key);
200
+ }
201
+ }
202
+ response($.ui.autocomplete.filter(
203
+ items, part));
204
+ },
205
+ focus: function() {
206
+ // prevent value inserted on focus
207
+ return false;
208
+ },
209
+ select: function(event, ui) {
210
+ var oldTerms = this.value.replace(/[^, ][^,]*$/,"");
211
+ this.value = oldTerms + ui.item.value;
212
+ ktAkUpdateSubscriptionsInfo();
213
+ return false;
214
+ },
215
+ close: function() {
216
+ ktAkUpdateSubscriptionsInfo();
217
+ }
218
+
219
+ }).bind("focus", function(event) {
220
+ if($(this)[0].value == "") {
221
+ $(this).autocomplete( "search" );
222
+ }});
223
+
224
+ $("#hostgroup_environment_id").change(ktLoadActivationKeys);
225
+
226
+ $("#ak_refresh_subscriptions").click(function () {
227
+ ktLoadActivationKeys();
228
+ return false;
229
+ });
230
+
231
+ });
232
+
233
+ <% end %>
234
+ <div class="tab-pane" id="activation_keys">
235
+ <%= field(f, "Activation Keys", :help_inline => "comma separated values. The value will be available in templates as @host.params['#{kt_ak_label}']") do
236
+ text_field_tag("kt_activation_keys", "", :style => 'width: 98%')
237
+ end %>
238
+ <div class="alert alert-info">
239
+ <p><b>Subscriptions information based on selected activation keys:</b></p>
240
+ <ul id="ak-subscriptions-info">
241
+ </ul>
242
+ <div id="ak-subscriptions-spinner" style="display: none">
243
+ <%= image_tag "spinner.gif" %>
244
+ </div>
245
+ <p>Activation keys and subscriptions can be managed
246
+ <b><a href="<%= Setting['katello_url'] %>/activation_keys" target="_blank">here</a></b>
247
+ </p>
248
+ <p><a href="" id="ak_refresh_subscriptions">Reload data from Katello</a></p>
249
+ </div>
250
+ </div>
@@ -0,0 +1,3 @@
1
+ <li>
2
+ <%= link_to "#{ForemanKatelloEngine::LABEL} #{image_tag("foreman_katello_engine/link.png")}".html_safe, Setting['katello_url'] %>
3
+ </li>
@@ -0,0 +1,104 @@
1
+ install
2
+ <%= @mediapath %>
3
+ lang en_US.UTF-8
4
+ selinux --permissive
5
+ keyboard us
6
+ skipx
7
+ network --bootproto <%= @static ? "static" : "dhcp" %> --hostname <%= @host %>
8
+ rootpw --iscrypted <%= root_pass %>
9
+ firewall --<%= @host.operatingsystem.major.to_i >= 6 ? "service=" : "" %>ssh
10
+ authconfig --useshadow --enablemd5
11
+ timezone UTC
12
+ <% if @host.operatingsystem.name == "Fedora" -%>
13
+ repo --name=fedora-everything --mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-<%= @host.operatingsystem.major %>&arch=<%= @host.architecture %>
14
+ <% end -%>
15
+ <% if @host.operatingsystem.name == "Fedora" and @host.operatingsystem.major.to_i <= 16 -%>
16
+ # Bootloader exception for Fedora 16:
17
+ bootloader --append="nofb quiet splash=quiet <%=ks_console%>" <%= grub_pass %>
18
+ part biosboot --fstype=biosboot --size=1
19
+ <% else -%>
20
+ bootloader --location=mbr --append="nofb quiet splash=quiet" <%= grub_pass %>
21
+ <% end -%>
22
+ <% if @host.os.name == "RedHat" -%>
23
+ key --skip
24
+ <% end -%>
25
+
26
+ <% if @dynamic -%>
27
+ %include /tmp/diskpart.cfg
28
+ <% else -%>
29
+ <%= @host.diskLayout %>
30
+ <% end -%>
31
+ text
32
+ reboot
33
+
34
+ %packages
35
+ yum
36
+ dhclient
37
+ ntp
38
+ wget
39
+ @Core
40
+ <%= "%end\n" if @host.operatingsystem.name == "Fedora" %>
41
+
42
+ <% if @dynamic -%>
43
+ %pre
44
+ <%= @host.diskLayout %>
45
+ <% end -%>
46
+
47
+ %post --nochroot
48
+ exec < /dev/tty3 > /dev/tty3
49
+ #changing to VT 3 so that we can see whats going on....
50
+ /usr/bin/chvt 3
51
+ (
52
+ cp -va /etc/resolv.conf /mnt/sysimage/etc/resolv.conf
53
+ /usr/bin/chvt 1
54
+ ) 2>&1 | tee /mnt/sysimage/root/install.postnochroot.log
55
+ <%= "%end\n" if @host.operatingsystem.name == "Fedora" %>
56
+
57
+ %post
58
+ logger "Starting anaconda <%= @host %> postinstall"
59
+ exec < /dev/tty3 > /dev/tty3
60
+ #changing to VT 3 so that we can see whats going on....
61
+ /usr/bin/chvt 3
62
+ (
63
+ #update local time
64
+ echo "updating system time"
65
+ /usr/sbin/ntpdate -sub <%= @host.params["ntp-server"] || "ntp" %>
66
+ /usr/sbin/hwclock --systohc
67
+
68
+ # install epel if we can
69
+ <%= snippet 'epel' %>
70
+
71
+ # update all the base packages from the updates repository
72
+ yum -t -y -e 0 update
73
+
74
+ <%= snippets "katello_registration" %>
75
+
76
+ # and add the puppet package
77
+ yum -t -y -e 0 install puppet
78
+
79
+ echo "Configuring puppet"
80
+ cat > /etc/puppet/puppet.conf << EOF
81
+ <%= snippets "puppet.conf" %>
82
+ EOF
83
+
84
+ # Setup puppet to run on system reboot
85
+ /sbin/chkconfig --level 345 puppet on
86
+
87
+ # Disable most things. Puppet will activate these if required.
88
+ echo "Disabling various system services"
89
+ <% %w{autofs gpm sendmail cups iptables ip6tables auditd arptables_jf xfs pcmcia isdn rawdevices hpoj bluetooth openibd avahi-daemon avahi-dnsconfd hidd hplip pcscd restorecond mcstrans rhnsd yum-updatesd}.each do |service| -%>
90
+ /sbin/chkconfig --level 345 <%= service %> off 2>/dev/null
91
+ <% end -%>
92
+
93
+ /usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag --server <%= @host.puppetmaster %> --no-daemonize
94
+
95
+ sync
96
+
97
+ # Inform the build system that we are done.
98
+ echo "Informing Foreman that we are built"
99
+ wget -q -O /dev/null --no-check-certificate <%= foreman_url %>
100
+ # Sleeping an hour for debug
101
+ ) 2>&1 | tee /root/install.post.log
102
+ exit 0
103
+
104
+ <%= "%end\n" if @host.operatingsystem.name == "Fedora" -%>
@@ -0,0 +1,8 @@
1
+ <% if @host.params['kt_org'] and @host.params['kt_activation_keys'] %>
2
+ # add subscription manager
3
+ yum -t -y -e 0 install subscription-manager
4
+ yum -y install <%= subscription_manager_configuration_url %>
5
+
6
+ echo "Registering the System"
7
+ subscription-manager register --org=<%= @host.params['kt_org']%> --name=<%= @host.name %> --activationkey=<%= @host.params['kt_activation_keys'] %>
8
+ <% end %>
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "foreman-katello-engine"
3
- s.version = "0.0.8"
3
+ s.version = "0.0.10"
4
4
 
5
5
  s.authors = ["Katello"]
6
6
  s.date = "2013-03-04"
7
7
  s.description = "Katello specific parts of Foreman"
8
8
  s.email = "katello-devel@redhat.com"
9
9
  s.files = %w(foreman-katello-engine.gemspec Gemfile LICENSE Rakefile README.md)
10
- s.files += Dir["app/**/*.rb"]
10
+ s.files += Dir["app/**/*"]
11
11
  s.files += Dir["config/**/*.rb"]
12
12
  s.files += Dir["db/**/*.rb"]
13
13
  s.files += Dir["lib/**/*.rb"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman-katello-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -58,6 +58,13 @@ files:
58
58
  - app/models/setting/katello.rb
59
59
  - app/helpers/foreman_katello_engine/hosts_and_hostgroups_helper.rb
60
60
  - app/helpers/foreman_katello_engine/katello_urls_helper.rb
61
+ - app/views/foreman_katello_engine/activation_keys/_host_tab_pane.html.erb
62
+ - app/views/foreman_katello_engine/activation_keys/_host_tab.html.erb
63
+ - app/views/foreman_katello_engine/activation_keys/_host_environment_select.html.erb
64
+ - app/views/foreman_katello_engine/layout/_katello_link.html.erb
65
+ - app/views/unattended/kickstart-katello.erb
66
+ - app/views/unattended/snippets/_katello_registration.erb
67
+ - app/assets/images/foreman_katello_engine/link.png
61
68
  - app/overrides/add_activation_keys_input.rb
62
69
  - app/overrides/add_katello_link.rb
63
70
  - app/controllers/foreman_katello_engine/api/environments_controller.rb