knife-zero 0.3.0.pre → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -2
- data/README.md +2 -13
- data/lib/chef/knife/chef_client.rb +13 -47
- data/lib/chef/knife/zero_base.rb +0 -21
- data/lib/chef/knife/zero_bootstrap.rb +1 -5
- data/lib/knife-zero/bootstrap_ssh.rb +7 -57
- data/lib/knife-zero/common.rb +7 -0
- data/lib/knife-zero/net-ssh-multi-patch.rb +31 -0
- data/lib/knife-zero/version.rb +1 -1
- metadata +6 -5
- data/lib/knife-zero/helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b49630ab7f49b0d6124a0a36f17b15c486832c0
|
4
|
+
data.tar.gz: 0062f6d3d584a135c438865e71df980a18986604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b57450d3140a1d518e4908bf8d8419956cd41cc6bbf5b6cad62450cc2bfef2af1c3824e5ae6a871557a53e221da3e82e0367044223e7b98ebf1c5a7bdb7b9b9
|
7
|
+
data.tar.gz: ab553ebadbc9e3c9608d0916e9e36c90e2b92b222c490bb3182e6855a68ebd4b9ce2282659e21cf473c1397a6313fa08724968228f05931932d1293c5b427c90
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -44,12 +44,7 @@ knife zero chef_client QUERY (options)
|
|
44
44
|
Install Chef to remote node and run chef-client under chef-zero via tcp-forward.
|
45
45
|
|
46
46
|
Supported options are mostly the same as `knife bootstrap`.
|
47
|
-
|
48
|
-
#### Specific options(s)
|
49
|
-
|
50
|
-
```
|
51
|
-
-W, --why-run Enable whyrun mode on chef-client run at remote node.
|
52
|
-
```
|
47
|
+
And it supports why-run(`-W, --why-run`).
|
53
48
|
|
54
49
|
#### Example
|
55
50
|
|
@@ -120,13 +115,7 @@ xxx.xxx.xxx.xxx 08:41:37 up 143 days, 2:32, 4 users, load average: 0.00, 0.0
|
|
120
115
|
Search nodes from local chef-repo directory, and run command at remote node.
|
121
116
|
|
122
117
|
Supported options are mostly the same as `knife ssh`.
|
123
|
-
|
124
|
-
#### Specific options(s)
|
125
|
-
|
126
|
-
```
|
127
|
-
-W, --why-run Enable whyrun mode on chef-client run at remote node.
|
128
|
-
-C, --concurrency NUMBER (0.3.0 or later) Number of concurrency. (default: 1) ; not avaiable on some platforms like Windows and NetBSD 4.
|
129
|
-
```
|
118
|
+
And it supports why-run(`-W, --why-run`).
|
130
119
|
|
131
120
|
#### Example
|
132
121
|
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'chef/knife'
|
2
2
|
require 'chef/knife/zero_base'
|
3
|
-
require 'knife-zero/
|
3
|
+
require 'knife-zero/bootstrap_ssh'
|
4
4
|
|
5
5
|
class Chef
|
6
6
|
class Knife
|
7
|
-
class ZeroChefClient < Chef::Knife::
|
7
|
+
class ZeroChefClient < Chef::Knife::BootstrapSsh
|
8
8
|
include Chef::Knife::ZeroBase
|
9
|
-
include ::Knife::Zero::Helper
|
10
|
-
|
11
9
|
deps do
|
12
|
-
require 'chef/node'
|
13
|
-
require 'chef/environment'
|
14
|
-
require 'chef/api_client'
|
15
|
-
require 'chef/search/query'
|
16
|
-
require 'knife-zero/bootstrap_ssh'
|
17
10
|
Chef::Knife::BootstrapSsh.load_deps
|
18
11
|
end
|
19
12
|
|
20
13
|
banner "knife zero chef_client QUERY (options)"
|
21
14
|
|
15
|
+
option :concurrency,
|
16
|
+
:short => "-C NUM",
|
17
|
+
:long => "--concurrency NUM",
|
18
|
+
:description => "The number of concurrent connections",
|
19
|
+
:default => nil,
|
20
|
+
:proc => lambda { |o| o.to_i }
|
21
|
+
|
22
22
|
option :attribute,
|
23
23
|
:short => "-a ATTR",
|
24
24
|
:long => "--attribute ATTR",
|
@@ -30,48 +30,14 @@ class Chef
|
|
30
30
|
:description => "execute the chef-client via sudo",
|
31
31
|
:boolean => true
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
:description => "Number of concurrency. (default: 1) ; not avaiable on some platforms like Windows and NetBSD 4.",
|
37
|
-
:proc => lambda { |s| s.to_i },
|
38
|
-
:default => 1
|
39
|
-
|
40
|
-
def run
|
41
|
-
configure_attribute
|
42
|
-
configure_user
|
43
|
-
configure_password
|
44
|
-
configure_identity_file
|
45
|
-
list = search_nodes
|
46
|
-
|
47
|
-
pids = []
|
48
|
-
list.each do |n|
|
49
|
-
# Note: fork(2) is not avaiable on some platforms like Windows and NetBSD 4.
|
50
|
-
if (Process.respond_to?(:fork) && !Chef::Platform.windows?)
|
51
|
-
pids << Process.fork {
|
52
|
-
Chef::Log.debug("Start session for #{n}")
|
53
|
-
session = knife_ssh
|
54
|
-
session.configure_session(n)
|
55
|
-
session.ssh_command(start_chef_client)
|
56
|
-
}
|
57
|
-
until count_alive_pids(pids) < @config[:concurrency]
|
58
|
-
sleep 1
|
59
|
-
end
|
60
|
-
else
|
61
|
-
Chef::Log.debug("Start session for #{n}")
|
62
|
-
session = knife_ssh
|
63
|
-
session.configure_session(n)
|
64
|
-
session.ssh_command(start_chef_client)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
result = Process.waitall
|
69
|
-
## NOTE: should report if includes fail...?
|
33
|
+
def initialize(argv=[])
|
34
|
+
super
|
35
|
+
@name_args = [@name_args[0], start_chef_client]
|
70
36
|
end
|
71
37
|
|
72
38
|
def start_chef_client
|
73
39
|
client_path = @config[:use_sudo] ? 'sudo ' : ''
|
74
|
-
client_path = @config[:chef_client_path] ? "#{client_path}#{@config[:chef_client_path]}" : "#{client_path}chef-client"
|
40
|
+
client_path = @config[:chef_client_path] ? "#{client_path}#{@config[:chef_client_path]}" : "#{client_path}chef-client"
|
75
41
|
s = "#{client_path}"
|
76
42
|
s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2
|
77
43
|
s << " -S http://127.0.0.1:8889"
|
data/lib/chef/knife/zero_base.rb
CHANGED
@@ -7,11 +7,6 @@ class Chef
|
|
7
7
|
includer.class_eval do
|
8
8
|
deps do
|
9
9
|
Chef::Config[:local_mode] = true
|
10
|
-
require 'knife-zero/core/bootstrap_context'
|
11
|
-
require 'chef/json_compat'
|
12
|
-
require 'tempfile'
|
13
|
-
require 'highline'
|
14
|
-
require 'net/ssh'
|
15
10
|
Chef::Knife::Ssh.load_deps
|
16
11
|
end
|
17
12
|
|
@@ -64,22 +59,6 @@ class Chef
|
|
64
59
|
end
|
65
60
|
end
|
66
61
|
|
67
|
-
def knife_ssh
|
68
|
-
ssh = Chef::Knife::BootstrapSsh.new
|
69
|
-
ssh.ui = ui
|
70
|
-
ssh.name_args = [ server_name, ssh_command ] unless ssh.name_args.empty?
|
71
|
-
ssh.config[:ssh_user] = Chef::Config[:knife][:ssh_user] || config[:ssh_user]
|
72
|
-
ssh.config[:ssh_password] = config[:ssh_password]
|
73
|
-
ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
|
74
|
-
ssh.config[:ssh_gateway] = Chef::Config[:knife][:ssh_gateway] || config[:ssh_gateway]
|
75
|
-
ssh.config[:forward_agent] = Chef::Config[:knife][:forward_agent] || config[:forward_agent]
|
76
|
-
ssh.config[:identity_file] = Chef::Config[:knife][:identity_file] || config[:identity_file]
|
77
|
-
ssh.config[:manual] = true
|
78
|
-
ssh.config[:host_key_verify] = Chef::Config[:knife][:host_key_verify] || config[:host_key_verify]
|
79
|
-
ssh.config[:on_error] = :raise
|
80
|
-
ssh
|
81
|
-
end
|
82
|
-
|
83
62
|
private
|
84
63
|
|
85
64
|
def locate_config_value(key)
|
@@ -7,6 +7,7 @@ class Chef
|
|
7
7
|
class ZeroBootstrap < Chef::Knife::Bootstrap
|
8
8
|
include Chef::Knife::ZeroBase
|
9
9
|
deps do
|
10
|
+
require 'knife-zero/core/bootstrap_context'
|
10
11
|
require 'knife-zero/bootstrap_ssh'
|
11
12
|
Chef::Knife::BootstrapSsh.load_deps
|
12
13
|
end
|
@@ -127,11 +128,6 @@ class Chef
|
|
127
128
|
ssh.config[:on_error] = :raise
|
128
129
|
ssh
|
129
130
|
end
|
130
|
-
|
131
|
-
alias :default_run :run
|
132
|
-
def run
|
133
|
-
default_run
|
134
|
-
end
|
135
131
|
end
|
136
132
|
end
|
137
133
|
end
|
@@ -3,38 +3,11 @@ require 'chef/knife/ssh'
|
|
3
3
|
class Chef
|
4
4
|
class Knife
|
5
5
|
class BootstrapSsh < Chef::Knife::Ssh
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Chef::Log.debug("Configration for #{host}")
|
11
|
-
session_opts = {}
|
12
|
-
|
13
|
-
ssh_config = Net::SSH.configuration_for(host)
|
14
|
-
|
15
|
-
# Chef::Config[:knife][:ssh_user] is parsed in #configure_user and written to config[:ssh_user]
|
16
|
-
user = config[:ssh_user] || ssh_config[:user]
|
17
|
-
hostspec = user ? "#{user}@#{host}" : host
|
18
|
-
session_opts[:keys] = File.expand_path(config[:identity_file]) if config[:identity_file]
|
19
|
-
session_opts[:keys_only] = true if config[:identity_file]
|
20
|
-
session_opts[:password] = config[:ssh_password] if config[:ssh_password]
|
21
|
-
session_opts[:forward_agent] = config[:forward_agent]
|
22
|
-
session_opts[:port] = config[:ssh_port] ||
|
23
|
-
ssh_port || # Use cloud port if available
|
24
|
-
Chef::Config[:knife][:ssh_port] ||
|
25
|
-
ssh_config[:port]
|
26
|
-
session_opts[:logger] = Chef::Log.logger if Chef::Log.level == :debug
|
27
|
-
|
28
|
-
if !config[:host_key_verify]
|
29
|
-
session_opts[:paranoid] = false
|
30
|
-
session_opts[:user_known_hosts_file] = "/dev/null"
|
31
|
-
end
|
32
|
-
|
33
|
-
## use nomal Net::SSH instead of Net::SSH::Multi for simply tcpforward.
|
34
|
-
@session ||= Net::SSH.start(host, user, session_opts)
|
6
|
+
deps do
|
7
|
+
Chef::Knife::Ssh.load_deps
|
8
|
+
require "knife-zero/net-ssh-multi-patch"
|
35
9
|
end
|
36
10
|
|
37
|
-
|
38
11
|
def ssh_command(command, subsession=nil)
|
39
12
|
chef_zero_port = config[:chef_zero_port] ||
|
40
13
|
Chef::Config[:knife][:chef_zero_port] ||
|
@@ -42,35 +15,12 @@ class Chef
|
|
42
15
|
chef_zero_host = config[:chef_zero_host] ||
|
43
16
|
Chef::Config[:knife][:chef_zero_host] ||
|
44
17
|
'127.0.0.1'
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
command = fixup_sudo(command)
|
49
|
-
command.force_encoding('binary') if command.respond_to?(:force_encoding)
|
50
|
-
|
51
|
-
Chef::Log.debug("Creating tcp-foward channel to #{chef_zero_host}:#{chef_zero_port}")
|
52
|
-
session.forward.remote(8889, chef_zero_host, chef_zero_port)
|
53
|
-
subsession.open_channel do |ch|
|
54
|
-
ch.request_pty
|
55
|
-
ch.exec command do |ch, success|
|
56
|
-
raise ArgumentError, "Cannot execute #{command}" unless success
|
57
|
-
ch.on_data do |ichannel, data|
|
58
|
-
## Patched
|
59
|
-
print_data(ichannel.connection.host, data)
|
60
|
-
if data =~ /^knife sudo password: /
|
61
|
-
print_data(ichannel.connection.host, "\n")
|
62
|
-
ichannel.send_data("#{get_password}\n")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
ch.on_request "exit-status" do |ichannel, data|
|
66
|
-
exit_status = [exit_status, data.read_long].max
|
67
|
-
end
|
68
|
-
end
|
18
|
+
(subsession || session).servers.each do |server|
|
19
|
+
session = server.session(true)
|
20
|
+
session.forward.remote(8889, chef_zero_host, chef_zero_port)
|
69
21
|
end
|
70
|
-
|
71
|
-
exit_status
|
22
|
+
super
|
72
23
|
end
|
73
24
|
end
|
74
25
|
end
|
75
26
|
end
|
76
|
-
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'net/ssh/multi/version'
|
2
|
+
|
3
|
+
if Net::SSH::Multi::Version::STRING == "1.1.0" || Net::SSH::Multi::Version::STRING == "1.2.0"
|
4
|
+
|
5
|
+
require 'net/ssh/multi'
|
6
|
+
|
7
|
+
module Net::SSH::Multi
|
8
|
+
class PendingConnection
|
9
|
+
class ForwardRecording
|
10
|
+
def initialize
|
11
|
+
@recordings = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def remote(port, host, remote_port, remote_host="127.0.0.1")
|
15
|
+
@recordings << [:remote, port, host, remote_port, remote_host]
|
16
|
+
end
|
17
|
+
|
18
|
+
def replay_on(session)
|
19
|
+
forward = session.forward
|
20
|
+
@recordings.each {|args| forward.send *args}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def forward
|
25
|
+
forward = ForwardRecording.new
|
26
|
+
@recordings << forward
|
27
|
+
forward
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/knife-zero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sawanoboly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,8 +72,9 @@ files:
|
|
72
72
|
- lib/chef/knife/zero_base.rb
|
73
73
|
- lib/chef/knife/zero_bootstrap.rb
|
74
74
|
- lib/knife-zero/bootstrap_ssh.rb
|
75
|
+
- lib/knife-zero/common.rb
|
75
76
|
- lib/knife-zero/core/bootstrap_context.rb
|
76
|
-
- lib/knife-zero/
|
77
|
+
- lib/knife-zero/net-ssh-multi-patch.rb
|
77
78
|
- lib/knife-zero/version.rb
|
78
79
|
homepage: ''
|
79
80
|
licenses:
|
@@ -90,9 +91,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
91
|
version: '0'
|
91
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
93
|
requirements:
|
93
|
-
- - "
|
94
|
+
- - ">="
|
94
95
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
96
|
+
version: '0'
|
96
97
|
requirements: []
|
97
98
|
rubyforge_project:
|
98
99
|
rubygems_version: 2.2.2
|
data/lib/knife-zero/helper.rb
DELETED