staypuft 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,17 +53,40 @@ module Staypuft
53
53
 
54
54
  def associate_host
55
55
  hostgroup = ::Hostgroup.find params[:hostgroup_id]
56
- hosts = Array(::Host::Base.find *params[:host_ids])
57
- hosts.each do |host|
58
- host = host.becomes(::Host::Managed)
56
+
57
+ targeted_hosts = Array(::Host::Base.find *params[:host_ids])
58
+ assigned_hosts = hostgroup.hosts
59
+ hosts_to_assign = targeted_hosts - assigned_hosts
60
+ hosts_to_remove = assigned_hosts - targeted_hosts
61
+
62
+ hosts_to_assign.each do |discovered_host|
63
+ host = discovered_host.becomes(::Host::Managed)
59
64
  host.type = 'Host::Managed'
60
65
  host.managed = true
61
66
  host.build = false
62
67
  host.hostgroup = hostgroup
68
+
69
+ # root_pass is not copied for some reason
70
+ host.root_pass = hostgroup.root_pass
71
+
72
+ # I do not why but the final save! adds following condytion to the update SQL command
73
+ # "WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."id" = 283"
74
+ # which will not find the record since it's still Host::Discovered.
75
+ # Using #update_column to change it directly in DB
76
+ # (discovered_host is used to avoid same WHERE condition problem here).
77
+ # FIXME this is definitely ugly, needs to be properly fixed
78
+ discovered_host.update_column :type, 'Host::Managed'
79
+
63
80
  host.save!
64
81
  end
82
+
83
+ hosts_to_remove.each do |host|
84
+ host.hostgroup = nil
85
+ host.save!
86
+ end
87
+
65
88
  redirect_to deployment_path(id: ::Staypuft::Deployment.first)
66
89
  end
67
-
68
90
  end
91
+
69
92
  end
@@ -47,35 +47,44 @@
47
47
  <% @deployment.child_hostgroups.each_with_index do |child_hostgroup, i| %>
48
48
  <div class="tab-pane <%= 'active' if i == 0 %>" id="<%= child_hostgroup.name.parameterize.underscore %>">
49
49
  <h3><%= _("Hosts") %></h3>
50
- <%= form_tag(associate_host_deployments_path, class: 'form-horizontal well association') do |f| %>
51
- <p>
52
- <%= submit_tag _("Apply"), :class => "btn btn-primary btn-sm" %>
53
- </p>
54
- <%= hidden_field_tag :hostgroup_id, child_hostgroup.id %>
55
- <table class="table table-bordered table-striped table-condensed">
56
- <thead>
57
- <tr>
58
- <th class="ca">
59
- <%= check_box_tag :check_all %>
60
- </th>
61
- <th><%= sort :name, :as => _('Name') %></th>
62
- <th class="hidden-s hidden-xs"><%= sort :mac, :as => _('MAC Address') %></th>
63
- <th class="hidden-s hidden-xs"><%= sort :type, :as => _('Type') %></th>
64
- </tr>
65
- </thead>
66
- <tbody>
67
- <% child_hostgroup.own_and_free_hosts.each do |host| %>
68
- <tr class="checkbox_highlight <%= "success" if child_hostgroup.host_ids.include?(host.id) %>">
69
- <td class="ca">
70
- <%= check_box_tag "host_ids[]", host.id, child_hostgroup.host_ids.include?(host.id), :id => "host_ids_#{host.id}" %>
71
- </td>
72
- <td class="ellipsis"><%= host.name %></td>
73
- <td class="hidden-s hidden-xs"><%= host.mac %></td>
74
- <td class="hidden-s hidden-xs"><%= host.type %></td>
50
+ <% if child_hostgroup.own_and_free_hosts.present? %>
51
+ <%= form_tag(associate_host_deployments_path, class: 'form-horizontal well association') do |f| %>
52
+ <p>
53
+ <%= submit_tag _("Apply"), :class => "btn btn-primary btn-sm" %>
54
+ </p>
55
+ <%= hidden_field_tag :hostgroup_id, child_hostgroup.id %>
56
+ <table class="table table-bordered table-striped table-condensed">
57
+ <thead>
58
+ <tr>
59
+ <th class="ca">
60
+ <%= check_box_tag :check_all %>
61
+ </th>
62
+ <th><%= sort :name, :as => _('Name') %></th>
63
+ <th class="hidden-s hidden-xs"><%= sort :mac, :as => _('MAC Address') %></th>
64
+ <th class="hidden-s hidden-xs"><%= sort :type, :as => _('Type') %></th>
75
65
  </tr>
76
- <% end %>
77
- </tbody>
78
- </table>
66
+ </thead>
67
+ <tbody>
68
+ <% child_hostgroup.own_and_free_hosts.each do |host| %>
69
+ <tr class="checkbox_highlight <%= "success" if child_hostgroup.host_ids.include?(host.id) %>">
70
+ <td class="ca">
71
+ <%= check_box_tag "host_ids[]", host.id, child_hostgroup.host_ids.include?(host.id), :id => "host_ids_#{host.id}" %>
72
+ </td>
73
+ <td class="ellipsis"><%= host.name %></td>
74
+ <td class="hidden-s hidden-xs"><%= host.mac %></td>
75
+ <td class="hidden-s hidden-xs"><%= host.type %></td>
76
+ </tr>
77
+ <% end %>
78
+ </tbody>
79
+ </table>
80
+ <% end %>
81
+ <% else %>
82
+ <div class="well association">
83
+ <div class="alert alert-warning">
84
+ <span class="glyphicon glyphicon-warning-sign">&nbsp;</span>
85
+ <%= _("All available hosts have been already assigned.") %>
86
+ </div>
87
+ </div>
79
88
  <% end %>
80
89
  </div>
81
90
  <% end %>
@@ -1 +1,5 @@
1
1
  gemspec path: '../staypuft'
2
+
3
+ gem 'foreman_discovery',
4
+ git: 'https://github.com/theforeman/foreman_discovery.git',
5
+ branch: 'develop'
data/db/seeds.rb CHANGED
@@ -68,6 +68,7 @@ params = {
68
68
  "ovs_vlan_ranges" => '',
69
69
  "ovs_bridge_mappings" => [],
70
70
  "ovs_bridge_uplinks" => [],
71
+ "ovs_tunnel_iface" => 'eth0',
71
72
  "tenant_network_type" => 'gre',
72
73
  "enable_tunneling" => 'True',
73
74
  "ovs_vxlan_udp_port" => '4789',
@@ -44,20 +44,14 @@ module Staypuft
44
44
  end
45
45
 
46
46
  initializer "load default settings" do |app|
47
- if (Setting.table_exists? rescue(false))
47
+ if (Setting.table_exists? rescue false)
48
48
  Setting::StaypuftProvisioning.load_defaults
49
49
  end
50
50
  end
51
51
 
52
52
  initializer 'staypuft.configure_assets', :group => :assets do
53
- SETTINGS[:staypuft] = {
54
- :assets => {
55
- :precompile => [
56
- 'staypuft/staypuft.js',
57
- 'staypuft/staypuft.css'
58
- ],
59
- }
60
- }
53
+ SETTINGS[:staypuft] =
54
+ { assets: { precompile: %w(staypuft/staypuft.js staypuft/staypuft.css) } }
61
55
  end
62
56
 
63
57
  end
@@ -1,3 +1,3 @@
1
1
  module Staypuft
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staypuft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-08 00:00:00.000000000 Z
12
+ date: 2014-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: foreman-tasks
@@ -95,7 +95,6 @@ files:
95
95
  - app/lib/actions/staypuft/host/build.rb
96
96
  - app/lib/actions/staypuft/host/create.rb
97
97
  - app/lib/actions/staypuft/host/deploy.rb
98
- - app/lib/actions/staypuft/host/provision.rb
99
98
  - app/lib/actions/staypuft/host/puppet_run.rb
100
99
  - app/lib/actions/staypuft/host/wait_until_host_ready.rb
101
100
  - app/lib/actions/staypuft/host/wait_until_installed.rb
@@ -1,50 +0,0 @@
1
- #
2
- # Copyright 2014 Red Hat, Inc.
3
- #
4
- # This software is licensed to you under the GNU General Public
5
- # License as published by the Free Software Foundation; either version
6
- # 2 of the License (GPLv2) or (at your option) any later version.
7
- # There is NO WARRANTY for this software, express or implied,
8
- # including the implied warranties of MERCHANTABILITY,
9
- # NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10
- # have received a copy of GPLv2 along with this software; if not, see
11
- # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12
-
13
- module Actions
14
- module Staypuft
15
- module Host
16
-
17
- # creates and provisions Host waiting until it's ready
18
- class Provision < Actions::Base
19
-
20
- middleware.use Actions::Staypuft::Middleware::AsCurrentUser
21
-
22
- def plan(name, hostgroup, compute_resource)
23
- Type! hostgroup, ::Hostgroup
24
- Type! compute_resource, ComputeResource
25
-
26
- input[:name] = name
27
-
28
- sequence do
29
- creation = plan_action Host::Create, name, hostgroup, compute_resource
30
- plan_action Host::Build, creation.output[:host][:id]
31
- plan_action Host::WaitUntilInstalled, creation.output[:host][:id]
32
- # TODO: wait until restarted
33
- end
34
- end
35
-
36
- def humanized_input
37
- input[:name]
38
- end
39
-
40
- def task_output
41
- planned_actions(Host::Create).first.output
42
- end
43
-
44
- def humanized_output
45
- task_output.fetch(:host, {})[:name]
46
- end
47
- end
48
- end
49
- end
50
- end