octo 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/octo +26 -7
- data/lib/octo/profile.rb +19 -9
- data/lib/octo.rb +30 -2
- data/octo.gemspec +3 -1
- metadata +41 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f725787f4c6ae31626f1eceed7504ed32eb98f3
|
4
|
+
data.tar.gz: 3e3214b8d920d863483ba69b558ec78a5696dccc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95a553226385139f430c0ab7b3cce4b7e4d254a040e30e24dd348e59eaa79f0457167ab3626ea2a34036c93f2a658d9241ff48810076f7bc4026d10efd4c3aae
|
7
|
+
data.tar.gz: bed80746eeecec5bb79b557c27ad18000155e7999d3e04e19438dcabd244413ff3ae73a506fe7eb2981181fc0bf3b14f2d2ee6df928084144cda94b2d8ca28c5
|
data/bin/octo
CHANGED
@@ -20,6 +20,9 @@ include GLI::App
|
|
20
20
|
|
21
21
|
program_desc 'Run commands on multiple hosts'
|
22
22
|
|
23
|
+
desc 'Set the mode tht octo will run in (eg. ssh, mysql)'
|
24
|
+
flag [:m, :mode], must_match: /(mysql)|(ssh)/i, default_value: 'ssh', type: String
|
25
|
+
|
23
26
|
octo = nil
|
24
27
|
pre do |global_opts, command, opts, args|
|
25
28
|
octo = Octo.new(opts)
|
@@ -35,17 +38,19 @@ command :profile do |profile|
|
|
35
38
|
profile.command :list do |list|
|
36
39
|
list.action do |global_opts, opts, args|
|
37
40
|
if args.empty?
|
38
|
-
octo.
|
41
|
+
octo.config[global_opts[:m]].each do |profile, servers|
|
39
42
|
puts "#{profile}:"
|
40
|
-
|
43
|
+
servers.each do |server|
|
41
44
|
puts "- #{server}"
|
42
45
|
end
|
43
46
|
end
|
44
47
|
else
|
45
|
-
|
48
|
+
unless octo.profile_exists? global_opts[:m], args.first
|
49
|
+
exit_now!("#{args.first} is not a defined profile")
|
50
|
+
end
|
46
51
|
|
47
52
|
puts "#{args.first}:"
|
48
|
-
octo.
|
53
|
+
octo.list(global_opts[:m], args.first).each do |server|
|
49
54
|
puts "- #{server}"
|
50
55
|
end
|
51
56
|
end
|
@@ -57,7 +62,7 @@ command :profile do |profile|
|
|
57
62
|
profile.long_desc 'Add a host to a profile, the host should be specified using the form user@hostname, eg. nan@nine27.com.'
|
58
63
|
profile.command :add do |add|
|
59
64
|
add.action do |global_opts, opts, args|
|
60
|
-
octo.add args[0], args[1]
|
65
|
+
octo.add global_opts[:m], args[0], args[1]
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
@@ -66,7 +71,11 @@ command :profile do |profile|
|
|
66
71
|
profile.arg_name 'profile server'
|
67
72
|
profile.command :rm do |rm|
|
68
73
|
rm.action do |global_opts, opts, args|
|
69
|
-
octo.
|
74
|
+
unless octo.profile_exists? global_opts[:m], args.first
|
75
|
+
exit_now!("#{args.first} is not a defined profile")
|
76
|
+
end
|
77
|
+
|
78
|
+
octo.rm global_opts[:m], args[0], args[1]
|
70
79
|
end
|
71
80
|
end
|
72
81
|
end
|
@@ -76,7 +85,17 @@ long_desc 'Run a command in parallel on all configured hosts in the profile, eg.
|
|
76
85
|
octo run cluster_1 \'tail -f /var/log/httpd/error_log\'.'
|
77
86
|
command :run do |cmd|
|
78
87
|
cmd.action do |global_opts, tops, args|
|
79
|
-
octo.
|
88
|
+
unless octo.profile_exists? global_opts[:m], args.first
|
89
|
+
exit_now!("#{args.first} is not a defined profile")
|
90
|
+
end
|
91
|
+
|
92
|
+
case global_opts[:m]
|
93
|
+
when 'ssh'
|
94
|
+
octo.run_ssh args[0], args[1]
|
95
|
+
when 'mysql'
|
96
|
+
exit_now!("No query specified") if args[1].nil? || args[1].empty?
|
97
|
+
octo.run_mysql args[0], args[1]
|
98
|
+
end
|
80
99
|
end
|
81
100
|
end
|
82
101
|
|
data/lib/octo/profile.rb
CHANGED
@@ -7,22 +7,32 @@ module Octo::Profile
|
|
7
7
|
"#{Dir.home}/.octorc"
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def profile_exists?(type, profile)
|
11
|
+
@config[type].keys.include? profile
|
12
|
+
end
|
13
|
+
|
14
|
+
def list(type, profile = nil)
|
11
15
|
if profile.nil?
|
12
|
-
@config.keys
|
16
|
+
@config[type].keys
|
13
17
|
else
|
14
|
-
@config[
|
18
|
+
@config[type].each do |name, servers|
|
19
|
+
if name == profile
|
20
|
+
return servers
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
return nil
|
15
25
|
end
|
16
26
|
end
|
17
27
|
|
18
|
-
def add(profile, server)
|
19
|
-
@config[profile] = [] if @config[profile].nil?
|
20
|
-
@config[profile] << server
|
28
|
+
def add(type, profile, server)
|
29
|
+
@config[type][profile] = [] if @config[type][profile].nil?
|
30
|
+
@config[type][profile] << server
|
21
31
|
end
|
22
32
|
|
23
|
-
def rm(profile, server)
|
24
|
-
@config[profile].delete(server)
|
25
|
-
@config.delete(profile) if @config[profile].empty?
|
33
|
+
def rm(type, profile, server)
|
34
|
+
@config[type][profile].delete(server)
|
35
|
+
@config[type].delete(profile) if @config[type][profile].empty?
|
26
36
|
end
|
27
37
|
|
28
38
|
def load
|
data/lib/octo.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'net/ssh/multi'
|
3
|
+
require 'mysql2'
|
4
|
+
require 'terminal-table'
|
3
5
|
require 'term/ansicolor'
|
4
6
|
|
5
7
|
class Octo
|
@@ -16,9 +18,9 @@ class Octo
|
|
16
18
|
self.load
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
21
|
+
def run_ssh(profile, command)
|
20
22
|
Net::SSH::Multi.start do |session|
|
21
|
-
@config[profile].each do |server|
|
23
|
+
@config['ssh'][profile].each do |server|
|
22
24
|
session.use server
|
23
25
|
end
|
24
26
|
|
@@ -31,4 +33,30 @@ class Octo
|
|
31
33
|
session.loop
|
32
34
|
end
|
33
35
|
end
|
36
|
+
|
37
|
+
def run_mysql(profile, query)
|
38
|
+
@config['mysql'][profile].each do |server|
|
39
|
+
print "Running query on #{server}... "
|
40
|
+
|
41
|
+
begin
|
42
|
+
server_data = server.match(/(.+):(.+)@(.+)\/(.+)/)
|
43
|
+
client = Mysql2::Client.new(username: server_data[1],
|
44
|
+
password: server_data[2],
|
45
|
+
host: server_data[3],
|
46
|
+
database: server_data[4])
|
47
|
+
|
48
|
+
results = client.query(query)
|
49
|
+
puts "#{results.count} results"
|
50
|
+
table = Terminal::Table.new(headings: results.fields) do |t|
|
51
|
+
results.each(as: :array) do |row|
|
52
|
+
t << row
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
puts table
|
57
|
+
rescue Exception => e
|
58
|
+
puts "ERROR: #{e.inspect}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
34
62
|
end
|
data/octo.gemspec
CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'octo'
|
3
3
|
s.summary = 'Run commands in parallel on multiple hosts'
|
4
4
|
s.description = 'A lightweight script that allows you to run commands in parallel on multiple hosts'
|
5
|
-
s.version = '0.0.
|
5
|
+
s.version = '0.0.5'
|
6
6
|
s.author = 'Nan Zhong'
|
7
7
|
s.email = 'nan@nine27.com'
|
8
8
|
s.homepage = 'https://github.com/nanzhong/octo'
|
@@ -11,6 +11,8 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.executables << 'octo'
|
12
12
|
|
13
13
|
s.add_dependency 'net-ssh-multi'
|
14
|
+
s.add_dependency 'mysql2'
|
14
15
|
s.add_dependency 'gli'
|
15
16
|
s.add_dependency 'term-ansicolor'
|
17
|
+
s.add_dependency 'terminal-table'
|
16
18
|
end
|
metadata
CHANGED
@@ -1,62 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nan Zhong
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: net-ssh-multi
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mysql2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
28
39
|
- !ruby/object:Gem::Version
|
29
40
|
version: '0'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: gli
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
|
-
- -
|
45
|
+
- - '>='
|
36
46
|
- !ruby/object:Gem::Version
|
37
47
|
version: '0'
|
38
48
|
type: :runtime
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - '>='
|
44
53
|
- !ruby/object:Gem::Version
|
45
54
|
version: '0'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: term-ansicolor
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: terminal-table
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
52
74
|
- !ruby/object:Gem::Version
|
53
75
|
version: '0'
|
54
76
|
type: :runtime
|
55
77
|
prerelease: false
|
56
78
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
79
|
requirements:
|
59
|
-
- -
|
80
|
+
- - '>='
|
60
81
|
- !ruby/object:Gem::Version
|
61
82
|
version: '0'
|
62
83
|
description: A lightweight script that allows you to run commands in parallel on multiple
|
@@ -74,26 +95,25 @@ files:
|
|
74
95
|
- octo.gemspec
|
75
96
|
homepage: https://github.com/nanzhong/octo
|
76
97
|
licenses: []
|
98
|
+
metadata: {}
|
77
99
|
post_install_message:
|
78
100
|
rdoc_options: []
|
79
101
|
require_paths:
|
80
102
|
- lib
|
81
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
104
|
requirements:
|
84
|
-
- -
|
105
|
+
- - '>='
|
85
106
|
- !ruby/object:Gem::Version
|
86
107
|
version: '0'
|
87
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
109
|
requirements:
|
90
|
-
- -
|
110
|
+
- - '>='
|
91
111
|
- !ruby/object:Gem::Version
|
92
112
|
version: '0'
|
93
113
|
requirements: []
|
94
114
|
rubyforge_project:
|
95
|
-
rubygems_version:
|
115
|
+
rubygems_version: 2.0.0
|
96
116
|
signing_key:
|
97
|
-
specification_version:
|
117
|
+
specification_version: 4
|
98
118
|
summary: Run commands in parallel on multiple hosts
|
99
119
|
test_files: []
|