ironfan 4.0.8 → 4.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v4.0.9:
2
+ * Making bootstrap work again (fixes #159)
3
+
1
4
  # v4.0.8:
2
5
  * Removed .delegates_to, .parallelize in favor of manual delegation (via .each) and .parallel, to remove assumption that calls must be in the context of the individual object (preparation for fixing bootstrapping)
3
6
  * Adding cluster and facet roles to server run list (fixes #160)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.8
1
+ 4.0.9
@@ -5,7 +5,7 @@ bash <<'EOF' || echo "Chef bootstrap failed!"
5
5
  #
6
6
  # * installs ruby 1.9.2 (not 1.8.7) from source
7
7
  # * upgrades rubygems rather than installing from source
8
- # * pushes the node identity into the first-boot.json
8
+ # * pushes the computer identity into the first-boot.json
9
9
  # * installs the chef-client service and kicks off the first run of chef
10
10
 
11
11
  set -e
@@ -127,13 +127,13 @@ echo -e "`date` \n\n**** \n**** Creating chef client script:\n****\n"
127
127
  (
128
128
  cat <<'EOP'
129
129
  <%= config_content %>
130
- <%= @config[:node].chef_client_script_content %>
130
+ <%= @config[:computer].chef_client_script_content %>
131
131
  EOP
132
132
  ) > /etc/chef/client.rb
133
133
 
134
134
  (
135
135
  cat <<'EOP'
136
- <%= { "run_list" => @run_list, "cluster_name" => @config[:node].cluster_name, "facet_name" => @config[:node].facet_name, "facet_index" => @config[:node].facet_index }.to_json %>
136
+ <%= { "run_list" => @run_list, "cluster_name" => @config[:server].cluster_name, "facet_name" => @config[:server].facet_name, "facet_index" => @config[:server].index }.to_json %>
137
137
  EOP
138
138
  ) > /etc/chef/first-boot.json
139
139
 
@@ -5,7 +5,7 @@ bash <<'EOF' || echo "Chef bootstrap failed!"
5
5
  #
6
6
  # * installs ruby 1.9.2 (not 1.8.7) using the system ruby
7
7
  # * upgrades rubygems rather than installing from source
8
- # * pushes the node identity into the first-boot.json
8
+ # * pushes the computer identity into the first-boot.json
9
9
  # * installs the chef-client service and kicks off the first run of chef
10
10
 
11
11
  set -e
@@ -115,13 +115,13 @@ echo -e "`date` \n\n**** \n**** Creating chef client script:\n****\n"
115
115
  (
116
116
  cat <<'EOP'
117
117
  <%= config_content %>
118
- <%= @config[:node].chef_client_script_content %>
118
+ <%= @config[:computer].chef_client_script_content %>
119
119
  EOP
120
120
  ) > /etc/chef/client.rb
121
121
 
122
122
  (
123
123
  cat <<'EOP'
124
- <%= { "run_list" => @run_list, "cluster_name" => @config[:node].cluster_name, "facet_name" => @config[:node].facet_name, "facet_index" => @config[:node].facet_index }.to_json %>
124
+ <%= { "run_list" => @run_list, "cluster_name" => @config[:server].cluster_name, "facet_name" => @config[:server].facet_name, "facet_index" => @config[:server].index }.to_json %>
125
125
  EOP
126
126
  ) > /etc/chef/first-boot.json
127
127
 
data/ironfan.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ironfan"
8
- s.version = "4.0.8"
8
+ s.version = "4.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Infochimps"]
@@ -5,7 +5,7 @@ bash <<'EOF' || echo "Chef bootstrap failed!"
5
5
  #
6
6
  # * installs ruby 1.9.2 (not 1.8.7) from source
7
7
  # * upgrades rubygems rather than installing from source
8
- # * pushes the node identity into the first-boot.json
8
+ # * pushes the computer identity into the first-boot.json
9
9
  # * installs the chef-client service and kicks off the first run of chef
10
10
 
11
11
  set -e
@@ -109,13 +109,13 @@ echo -e "`date` \n\n**** \n**** Creating chef client script:\n****\n"
109
109
  (
110
110
  cat <<'EOP'
111
111
  <%= config_content %>
112
- <%= @config[:node].chef_client_script_content %>
112
+ <%= @config[:computer].chef_client_script_content %>
113
113
  EOP
114
114
  ) > /etc/chef/client.rb
115
115
 
116
116
  (
117
117
  cat <<'EOP'
118
- <%= { "run_list" => @run_list, "cluster_name" => @config[:node].cluster_name, "facet_name" => @config[:node].facet_name, "facet_index" => @config[:node].facet_index }.to_json %>
118
+ <%= { "run_list" => @run_list, "cluster_name" => @config[:server].cluster_name, "facet_name" => @config[:server].facet_name, "facet_index" => @config[:server].index }.to_json %>
119
119
  EOP
120
120
  ) > /etc/chef/first-boot.json
121
121
 
@@ -5,7 +5,7 @@ bash <<'EOF' || echo "Chef bootstrap failed!"
5
5
  #
6
6
  # * installs ruby 1.9.2 (not 1.8.7) from source
7
7
  # * upgrades rubygems rather than installing from source
8
- # * pushes the node identity into the first-boot.json
8
+ # * pushes the computer identity into the first-boot.json
9
9
  # * installs the chef-client service and kicks off the first run of chef
10
10
 
11
11
  set -e
@@ -127,13 +127,13 @@ echo -e "`date` \n\n**** \n**** Creating chef client script:\n****\n"
127
127
  (
128
128
  cat <<'EOP'
129
129
  <%= config_content %>
130
- <%= @config[:node].chef_client_script_content %>
130
+ <%= @config[:computer].chef_client_script_content %>
131
131
  EOP
132
132
  ) > /etc/chef/client.rb
133
133
 
134
134
  (
135
135
  cat <<'EOP'
136
- <%= { "run_list" => @run_list, "cluster_name" => @config[:node].cluster_name, "facet_name" => @config[:node].facet_name, "facet_index" => @config[:node].facet_index }.to_json %>
136
+ <%= { "run_list" => @run_list, "cluster_name" => @config[:server].cluster_name, "facet_name" => @config[:server].facet_name, "facet_index" => @config[:server].index }.to_json %>
137
137
  EOP
138
138
  ) > /etc/chef/first-boot.json
139
139
 
@@ -5,7 +5,7 @@ bash <<'EOF' || echo "Chef bootstrap failed!"
5
5
  #
6
6
  # * installs ruby 1.9.2 (not 1.8.7) using the system ruby
7
7
  # * upgrades rubygems rather than installing from source
8
- # * pushes the node identity into the first-boot.json
8
+ # * pushes the computer identity into the first-boot.json
9
9
  # * installs the chef-client service and kicks off the first run of chef
10
10
 
11
11
  set -e
@@ -115,13 +115,13 @@ echo -e "`date` \n\n**** \n**** Creating chef client script:\n****\n"
115
115
  (
116
116
  cat <<'EOP'
117
117
  <%= config_content %>
118
- <%= @config[:node].chef_client_script_content %>
118
+ <%= @config[:computer].chef_client_script_content %>
119
119
  EOP
120
120
  ) > /etc/chef/client.rb
121
121
 
122
122
  (
123
123
  cat <<'EOP'
124
- <%= { "run_list" => @run_list, "cluster_name" => @config[:node].cluster_name, "facet_name" => @config[:node].facet_name, "facet_index" => @config[:node].facet_index }.to_json %>
124
+ <%= { "run_list" => @run_list, "cluster_name" => @config[:server].cluster_name, "facet_name" => @config[:server].facet_name, "facet_index" => @config[:server].index }.to_json %>
125
125
  EOP
126
126
  ) > /etc/chef/first-boot.json
127
127
 
@@ -60,9 +60,8 @@ class Chef
60
60
 
61
61
  def perform_execution(target)
62
62
  # Execute across all servers in parallel
63
- threads = target.servers.map{ |server| Thread.new(server) { |svr| run_bootstrap(svr, svr.public_hostname) } }
64
- # Wait for the threads to finish and return the array of thread's exit value
65
- threads.map{ |t| t.join.value }
63
+ Ironfan.parallel(target.values) {|computer| run_bootstrap(computer)}
64
+ # threads = target.servers.map{ |server| Thread.new(server) { |svr| run_bootstrap(svr, svr.public_hostname) } }
66
65
  end
67
66
 
68
67
  def confirm_execution(target)
@@ -51,7 +51,7 @@ class Chef
51
51
 
52
52
  option :bootstrap,
53
53
  :long => "--[no-]bootstrap",
54
- :description => "Also bootstrap the launched node (default is NOT to bootstrap)",
54
+ :description => "Also bootstrap the launched machine (default is NOT to bootstrap)",
55
55
  :boolean => true,
56
56
  :default => false
57
57
 
@@ -81,61 +81,60 @@ class Chef
81
81
  display(target)
82
82
  target.launch
83
83
 
84
- Chef::Log.warn("Need to set up target.parallelize")
85
- # TODO:
86
- # # As each server finishes, configure it
87
- # watcher_threads = target.parallelize do |svr|
88
- # perform_after_launch_tasks(svr)
89
- # end
90
- #
84
+ # As each server finishes, configure it
85
+ Ironfan.parallel(target.values) do |computer|
86
+ perform_after_launch_tasks(computer)
87
+ end
91
88
  # progressbar_for_threads(watcher_threads)
92
89
 
93
90
  display(target)
94
91
  end
95
92
 
96
- # def perform_after_launch_tasks(server)
97
- # # Wait for node creation on amazon side
93
+ def perform_after_launch_tasks(computer)
94
+ # Wait for machine creation on amazon side
98
95
  # server.fog_server.wait_for{ ready? }
99
- #
100
- # # Try SSH
101
- # unless config[:dry_run]
96
+ computer.machine.wait_for{ ready? }
97
+
98
+ # Try SSH
99
+ unless config[:dry_run]
102
100
  # nil until tcp_test_ssh(server.fog_server.dns_name){ sleep @initial_sleep_delay ||= 10 }
103
- # end
104
- #
101
+ nil until tcp_test_ssh(computer.machine.dns_name){ sleep @initial_sleep_delay ||= 10 }
102
+ end
103
+
105
104
  # # Make sure our list of volumes is accurate
106
105
  # Ironfan.fetch_fog_volumes
107
106
  # server.discover_volumes!
108
- #
109
- # # Attach volumes, etc
107
+
108
+ # Attach volumes, etc
110
109
  # server.sync_to_cloud
111
- #
112
- # # Run Bootstrap
113
- # if config[:bootstrap]
114
- # run_bootstrap(server, server.fog_server.dns_name)
115
- # end
116
- # end
117
- #
118
- # def tcp_test_ssh(hostname)
119
- # tcp_socket = TCPSocket.new(hostname, 22)
120
- # readable = IO.select([tcp_socket], nil, nil, 5)
121
- # if readable
122
- # Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
123
- # yield
124
- # true
125
- # else
126
- # false
127
- # end
128
- # rescue Errno::ETIMEDOUT
129
- # false
130
- # rescue Errno::ECONNREFUSED
131
- # sleep 2
132
- # false
133
- # rescue Errno::EHOSTUNREACH
134
- # sleep 2
135
- # false
136
- # ensure
137
- # tcp_socket && tcp_socket.close
138
- # end
110
+ computer.save
111
+
112
+ # Run Bootstrap
113
+ Chef::Log.warn "UNTESTED --bootstrap"
114
+ run_bootstrap(computer) if config[:bootstrap]
115
+ end
116
+
117
+ def tcp_test_ssh(hostname)
118
+ tcp_socket = TCPSocket.new(hostname, 22)
119
+ readable = IO.select([tcp_socket], nil, nil, 5)
120
+ if readable
121
+ Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
122
+ yield
123
+ true
124
+ else
125
+ false
126
+ end
127
+ rescue Errno::ETIMEDOUT
128
+ false
129
+ rescue Errno::ECONNREFUSED
130
+ sleep 2
131
+ false
132
+ rescue Errno::EHOSTUNREACH
133
+ sleep 2
134
+ false
135
+ ensure
136
+ tcp_socket && tcp_socket.close
137
+ end
139
138
 
140
139
  def warn_or_die_on_bogus_servers(target)
141
140
  ui.info("")
@@ -51,8 +51,8 @@ module Ironfan
51
51
  end
52
52
 
53
53
  # method to nodes should be filtered on
54
- def relevant?(server)
55
- server.exists?
54
+ def relevant?(computer)
55
+ computer.running?
56
56
  end
57
57
 
58
58
  # override in subclass to confirm risky actions
@@ -114,28 +114,33 @@ module Ironfan
114
114
  ui.info ''
115
115
  end
116
116
 
117
- def bootstrapper(server, hostname)
117
+ def bootstrapper(computer)
118
+ server = computer.server
119
+ cloud = server.selected_cloud
120
+ hostname = computer.machine.dns_name
121
+
118
122
  bootstrap = Chef::Knife::Bootstrap.new
119
123
  bootstrap.config.merge!(config)
120
124
 
121
125
  bootstrap.name_args = [ hostname ]
122
- bootstrap.config[:node] = server
123
- bootstrap.config[:run_list] = server.combined_run_list
124
- bootstrap.config[:ssh_user] = config[:ssh_user] || server.cloud.ssh_user
126
+ bootstrap.config[:computer] = computer
127
+ bootstrap.config[:server] = server
128
+ bootstrap.config[:run_list] = server.run_list
129
+ bootstrap.config[:ssh_user] = config[:ssh_user] || cloud.ssh_user
125
130
  bootstrap.config[:attribute] = config[:attribute]
126
- bootstrap.config[:identity_file] = config[:identity_file] || server.cloud.ssh_identity_file
127
- bootstrap.config[:distro] = config[:distro] || server.cloud.bootstrap_distro
131
+ bootstrap.config[:identity_file] = config[:identity_file] || computer.ssh_identity_file
132
+ bootstrap.config[:distro] = config[:distro] || cloud.bootstrap_distro
128
133
  bootstrap.config[:use_sudo] = true unless config[:use_sudo] == false
129
134
  bootstrap.config[:chef_node_name] = server.fullname
130
- bootstrap.config[:client_key] = server.client_key.body if server.client_key.body
135
+ bootstrap.config[:client_key] = ( computer.client.private_key rescue nil )
131
136
 
132
137
  bootstrap
133
138
  end
134
139
 
135
- def run_bootstrap(node, hostname)
136
- bs = bootstrapper(node, hostname)
140
+ def run_bootstrap(computer)
141
+ bs = bootstrapper(computer)
137
142
  if config[:skip].to_s == 'true'
138
- ui.info "Skipping: bootstrap #{hostname} with #{JSON.pretty_generate(bs.config)}"
143
+ ui.info "Skipping: bootstrap #{computer.name} with #{JSON.pretty_generate(bs.config)}"
139
144
  return
140
145
  end
141
146
  begin
@@ -144,7 +149,7 @@ module Ironfan
144
149
  ui.warn e
145
150
  ui.warn e.backtrace
146
151
  ui.warn ""
147
- ui.warn node.inspect
152
+ ui.warn computer.inspect
148
153
  ui.warn ""
149
154
  end
150
155
  end
@@ -110,6 +110,18 @@ module Ironfan
110
110
  end
111
111
  end
112
112
 
113
+ def chef_client_script_content
114
+ cloud = server.selected_cloud
115
+ return @chef_client_script_content if @chef_client_script_content
116
+ return unless cloud.chef_client_script
117
+ script_filename = File.expand_path("../../../config/#{cloud.chef_client_script}", File.dirname(File.realdirpath(__FILE__)))
118
+ @chef_client_script_content = Ironfan.safely{ File.read(script_filename) }
119
+ end
120
+
121
+ def ssh_identity_file
122
+ resources[:key_pair].key_filename
123
+ end
124
+
113
125
  # def ensure_resource(type)
114
126
  # if type.multiple?
115
127
  # existing = resources[type.resource_id]
@@ -89,6 +89,10 @@ module Ironfan
89
89
  values
90
90
  end
91
91
 
92
+ def ssh_key
93
+ keypair = cloud.keypair || computer.server.cluster_name
94
+ end
95
+
92
96
  #
93
97
  # Discovery
94
98
  #
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ironfan
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 4.0.8
5
+ version: 4.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Infochimps
@@ -232,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
232
232
  requirements:
233
233
  - - ">="
234
234
  - !ruby/object:Gem::Version
235
- hash: -2934265328136200700
235
+ hash: 2386087126154656208
236
236
  segments:
237
237
  - 0
238
238
  version: "0"