knife-cloudformation 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.1.8
2
+ * Update event cache handling
3
+ * Allow multiple users for node connect attempts
4
+
1
5
  ## v0.1.6
2
6
  * Adds inspect action
3
7
  * Updates to commons
Binary file
@@ -80,10 +80,26 @@ class Chef
80
80
  ui.info "Displaying stack #{ui.color(stack_name, :bold)} failure on instance #{ui.color(inst_id, :bold)}"
81
81
  opts = ssh_key ? {:keys => [ssh_key]} : {}
82
82
  remote_path = '/var/log/cfn-init.log'
83
- content = remote_file_contents(inst_addr, ssh_user, remote_path, opts)
84
- ui.info " content of #{remote_path}:"
85
- ui.info ""
86
- ui.info content
83
+ content = nil
84
+ attempt_ssh_users.each do |ssh_user_name|
85
+ begin
86
+ content = remote_file_contents(inst_addr, ssh_user_name, remote_path, opts)
87
+ break
88
+ rescue Net::SSH::AuthenticationFailed
89
+ ui.warn "Authentication failed for user: #{ssh_user_name} on instance: #{inst_addr}"
90
+ end
91
+ end
92
+ if(content)
93
+ ui.info " content of #{remote_path}:"
94
+ ui.info ""
95
+ ui.info content
96
+ else
97
+ ui.error "Failed to retreive content from node at: #{inst_addr}"
98
+ end
99
+ end
100
+
101
+ def attempt_ssh_users
102
+ ([ssh_user] + Array(Chef::Config[:knife][:cloudformation][:ssh_attempt_users])).flatten.compact
87
103
  end
88
104
 
89
105
  def ssh_user
@@ -111,7 +111,7 @@ module KnifeCloudformation
111
111
  .body['StackResources']
112
112
  end
113
113
 
114
- def refresh?(bool=false)
114
+ def refresh?(bool=nil)
115
115
  bool || (bool.nil? && @force_refresh)
116
116
  end
117
117
 
@@ -204,12 +204,17 @@ module KnifeCloudformation
204
204
  end
205
205
 
206
206
  def events(all=false)
207
- res = common.aws(:cloud_formation).describe_stack_events(name).body['StackEvents']
208
- @memo[:events] ||= []
209
- current = @memo[:events].map{|e| e['EventId']}
210
- res.delete_if{|e| current.include?(e['EventId'])}
211
- @memo[:events] += res
212
- @memo[:events].uniq!
207
+ if(@memo[:events].nil? || refresh?)
208
+ res = common.aws(:cloud_formation).describe_stack_events(name).body['StackEvents']
209
+ @memo[:events] ||= []
210
+ current = @memo[:events].map{|e| e['EventId']}
211
+ res.delete_if{|e| current.include?(e['EventId'])}
212
+ @memo[:events] += res
213
+ @memo[:events].uniq!
214
+ @memo[:events].sort!{|x,y| x['Timestamp'] <=> y['Timestamp']}
215
+ else
216
+ res = []
217
+ end
213
218
  all ? @memo[:events] : res
214
219
  end
215
220
 
@@ -56,13 +56,30 @@ module KnifeCloudformation
56
56
  module Ssher
57
57
  def remote_file_contents(address, user, path, ssh_opts={})
58
58
  require 'net/sftp'
59
- content = nil
60
- Net::SFTP.start(address, user, ssh_opts) do |con|
61
- con.file.open(path) do |f|
62
- content = f.read
59
+ content = ''
60
+ ssh_session = Net::SSH.start(address, user, ssh_opts)
61
+ con = Net::SFTP::Session.new(ssh_session)
62
+ con.loop{ con.opening? }
63
+ f_handle = con.open!(path)
64
+ data = ''
65
+ count = 0
66
+ while(data)
67
+ data = nil
68
+ request = con.read(f_handle, count, 1024) do |response|
69
+ unless(response.eof?)
70
+ if(response.ok?)
71
+ count += 1024
72
+ content << response[:data]
73
+ data = true
74
+ end
75
+ end
63
76
  end
77
+ request.wait
64
78
  end
65
- content
79
+ con.close!(f_handle)
80
+ con.close_channel
81
+ ssh_session.close
82
+ content.empty? ? nil : content
66
83
  end
67
84
  end
68
85
  end
@@ -2,5 +2,5 @@ module KnifeCloudformation
2
2
  class Version < Gem::Version
3
3
  end
4
4
 
5
- VERSION = Version.new('0.1.6')
5
+ VERSION = Version.new('0.1.8')
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-cloudformation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
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: 2013-09-20 00:00:00.000000000 Z
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -81,6 +81,7 @@ executables: []
81
81
  extensions: []
82
82
  extra_rdoc_files: []
83
83
  files:
84
+ - knife-cloudformation-0.1.6.gem
84
85
  - lib/chef/knife/cloudformation_events.rb
85
86
  - lib/chef/knife/cloudformation_base.rb
86
87
  - lib/chef/knife/cloudformation_destroy.rb