knife-cssh 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/chef/knife/cssh-summon.rb +85 -2
- data/lib/knife-cssh.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b140d9a065370a3698b0b55e56284ebcc8cccd1
|
4
|
+
data.tar.gz: fb6867caba3f6a95f5786c0488162bb09100d1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ec2c45d19bab083ec44e801f4d1a87a487a5faba412063de10c435c8b4b9b7072fd50fc55db4e081b5f809f1b10d943e0e9d4ead609b23fb4a1150181ed372f
|
7
|
+
data.tar.gz: fc1fee5218d680ce6fbbf0f0fd4f3d570c5c333c3e7bed60dc3c789b6439067a87b8d8f87f3f1ae5b7a193f95248271212113ece0993eae6e9601d06bd393fbd
|
data/README.md
CHANGED
@@ -1,19 +1,71 @@
|
|
1
1
|
require 'chef/knife'
|
2
2
|
|
3
3
|
module KnifeCssh
|
4
|
+
|
5
|
+
def self.which(*cmds)
|
6
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
7
|
+
|
8
|
+
cmds.each do |cmd|
|
9
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
10
|
+
exts.each do |ext|
|
11
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
12
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
return nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find_command(*cmds)
|
21
|
+
cmd = self.which *cmds
|
22
|
+
return cmd if not cmd.nil?
|
23
|
+
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
4
27
|
class CsshSummon < Chef::Knife
|
5
28
|
|
6
29
|
banner "knife cssh summon QUERY"
|
7
30
|
|
31
|
+
option :login,
|
32
|
+
:short => '-l USER',
|
33
|
+
:long => '--login USER',
|
34
|
+
:description => 'Username to use for login',
|
35
|
+
:default => ENV['USER']
|
36
|
+
|
37
|
+
option :cssh_command,
|
38
|
+
:short => '-c COMMAND',
|
39
|
+
:long => '--cssh-command COMMAND',
|
40
|
+
:description => 'Command to use instead of cssh/csshX',
|
41
|
+
:default => KnifeCssh::find_command('csshX', 'cssh'),
|
42
|
+
:proc => Proc.new { |cmd| KnifeCssh::find_command(cmd) }
|
43
|
+
|
44
|
+
SPECIFIC_OPTIONS = {
|
45
|
+
'tmux-cssh' => {
|
46
|
+
:user_switch => '-u'
|
47
|
+
},
|
48
|
+
:default => {
|
49
|
+
:user_switch => '-l'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
8
53
|
deps do
|
9
54
|
require 'chef/node'
|
10
55
|
require 'chef/environment'
|
11
56
|
require 'chef/api_client'
|
12
57
|
require 'chef/knife/search'
|
58
|
+
require 'shellwords'
|
13
59
|
end
|
14
60
|
|
15
61
|
def run
|
16
62
|
# this chef is mainly from chef own knife search command
|
63
|
+
if name_args.length < 1
|
64
|
+
puts 'Missing argument QUERY!'
|
65
|
+
show_usage
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
17
69
|
query = name_args[0]
|
18
70
|
q = Chef::Search::Query.new
|
19
71
|
escaped_query = URI.escape(query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
@@ -21,7 +73,8 @@ module KnifeCssh
|
|
21
73
|
|
22
74
|
begin
|
23
75
|
q.search('node', escaped_query, 'X_CHEF_id_CHEF_X asc', 0, 100) do |item|
|
24
|
-
|
76
|
+
remote_host = extract_host item
|
77
|
+
result_items.push remote_host if not remote_host.nil?
|
25
78
|
end
|
26
79
|
rescue Net::HTTPServerException => e
|
27
80
|
msg = Chef::JSONCompat.from_json(e.response.body)["error"].first
|
@@ -29,7 +82,37 @@ module KnifeCssh
|
|
29
82
|
exit 1
|
30
83
|
end
|
31
84
|
|
32
|
-
|
85
|
+
call_cssh result_items
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def extract_host(item)
|
91
|
+
return item[:ec2][:public_ipv4] if item.has_key? :ec2
|
92
|
+
return item[:ipaddress] if not item[:ipaddress].nil?
|
93
|
+
item[:fqdn]
|
94
|
+
end
|
95
|
+
|
96
|
+
def call_cssh(hosts)
|
97
|
+
if config[:cssh_command].nil?
|
98
|
+
puts "Unable to find any suitable cssh command on PATH!"
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
|
102
|
+
%x[#{config[:cssh_command]} #{get_impl_opt :user_switch} #{config[:login].shellescape} #{hosts.join(" ")}]
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_impl_opt(key)
|
106
|
+
cmdname = cssh_command_name
|
107
|
+
if SPECIFIC_OPTIONS.has_key?(cmdname) and SPECIFIC_OPTIONS[cmdname].has_key?(key)
|
108
|
+
return SPECIFIC_OPTIONS[cmdname][key]
|
109
|
+
end
|
110
|
+
|
111
|
+
SPECIFIC_OPTIONS[:default][key]
|
112
|
+
end
|
113
|
+
|
114
|
+
def cssh_command_name
|
115
|
+
File.basename config[:cssh_command]
|
33
116
|
end
|
34
117
|
end
|
35
118
|
end
|
data/lib/knife-cssh.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-cssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Szalay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Summon cssh from a chef search
|
14
14
|
email: nico@rottenbytes.info
|