remote_executor 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +40 -5
- data/lib/remote_executor/cli.rb +9 -7
- data/lib/remote_executor/config.rb +11 -6
- data/lib/remote_executor/system.rb +22 -0
- data/lib/remote_executor/system_config.rb +2 -14
- data/lib/remote_executor/version.rb +1 -1
- data/lib/remote_executor.rb +1 -1
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
A simplistic remote command launcher over SSH conections
|
4
4
|
|
5
|
+
|
5
6
|
== Installing
|
6
7
|
|
7
8
|
The latest stable version is published in gemcutter.
|
@@ -9,20 +10,31 @@ The latest stable version is published in gemcutter.
|
|
9
10
|
gem source --add http://gemcutter.org
|
10
11
|
gem install remote_executor
|
11
12
|
|
13
|
+
|
12
14
|
== Notes
|
13
15
|
|
14
|
-
At the moment the gem have a strong dependency of your local SSH configuration, commonly located at ${HOME}/.ssh/config, this is only
|
15
|
-
very simple mechanism for keep safe your private data, but this need a ugly configuration with a fake user name in the connection
|
16
|
+
At the moment the gem have a strong dependency of your local SSH configuration, commonly located at ${HOME}/.ssh/config, this is only
|
17
|
+
a very simple mechanism for keep safe your private data, but this need a ugly configuration with a fake user name in the connection
|
16
18
|
process. I provide a basic SSH config if your aren´t familiar with this configuration stuff
|
17
19
|
|
20
|
+
|
18
21
|
=== How to use
|
19
22
|
|
20
23
|
An example may be the next. Launch the command 'hostname' over your production farm system named 'myFarm' configured in your home
|
21
24
|
directory into the file ${HOME}/.remoteexecutorrc like this:
|
22
25
|
|
23
26
|
---
|
24
|
-
:production:
|
25
27
|
- :name: 'myFarm'
|
28
|
+
:environment: 'production'
|
29
|
+
:user: admin
|
30
|
+
:hosts:
|
31
|
+
- 'myHost1'
|
32
|
+
- 'myHost2'
|
33
|
+
- 'myHost3'
|
34
|
+
- 'myHost4'
|
35
|
+
- :name: 'myFarm'
|
36
|
+
:environment: 'production'
|
37
|
+
:user: admin
|
26
38
|
:hosts:
|
27
39
|
- 'myHost1'
|
28
40
|
- 'myHost2'
|
@@ -46,6 +58,7 @@ you need this minimal SSH configuration (${HOME}/.ssh/config) for the example
|
|
46
58
|
with this line:
|
47
59
|
|
48
60
|
remote_executor --system=myFarm --environment=production --command='hostname'
|
61
|
+
|
49
62
|
|
50
63
|
=== Configuration
|
51
64
|
|
@@ -54,13 +67,35 @@ The configuration for this gem is divided in 3 levels
|
|
54
67
|
* Via --config command option
|
55
68
|
* Via your shell environment with the variable REMOTEEXECUTOR (export REMOTEEXECUTOR="${HOME}/configs/remote_executor_settins.yml")
|
56
69
|
* Via your user preferences located in the ${HOME}/.remoteexecutorrc file
|
70
|
+
|
57
71
|
|
58
72
|
== TODO
|
59
73
|
|
60
74
|
* Document all this stuff in english... I promise
|
61
|
-
* Write some test could be a gread idea
|
75
|
+
* Write some test could be a gread idea
|
76
|
+
* Take decisions about user by hosts or user by farm
|
62
77
|
* Pullrequests are welcome... of course
|
78
|
+
|
63
79
|
|
64
80
|
== License
|
65
81
|
|
66
|
-
Copyright
|
82
|
+
Copyright (c) 2010-2030 Javier Juarez Martinezi
|
83
|
+
|
84
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
85
|
+
a copy of this software and associated documentation files (the
|
86
|
+
"Software"), to deal in the Software without restriction, including
|
87
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
88
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
89
|
+
permit persons to whom the Software is furnished to do so, subject to
|
90
|
+
the following conditions:
|
91
|
+
|
92
|
+
The above copyright notice and this permission notice shall be
|
93
|
+
included in all copies or substantial portions of the Software.
|
94
|
+
|
95
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
96
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
97
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
98
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
99
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
100
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
101
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/remote_executor/cli.rb
CHANGED
@@ -4,19 +4,21 @@ module RemoteExecutor
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class Cli
|
7
|
-
|
8
|
-
def self.execute( name, environment, command )
|
9
7
|
|
10
|
-
|
8
|
+
DEFAULT_SSH_OPTIONS = { :config=>true }
|
9
|
+
|
10
|
+
def self.execute( name, environment, command, ssh_options=DEFAULT_SSH_OPTIONS )
|
11
|
+
|
12
|
+
system = System.new( SystemConfig.instance.find_system( name ) )
|
11
13
|
|
12
|
-
if(
|
14
|
+
if( system.environment == environment )
|
13
15
|
|
14
|
-
|
16
|
+
system.hosts.each do |host|
|
15
17
|
|
16
|
-
Net::SSH.start( host,
|
18
|
+
Net::SSH.start( host, system.user, ssh_options ) { |ssh| ssh.exec( "#{command}" ) }
|
17
19
|
end
|
18
20
|
else
|
19
|
-
raise BadEnvironment.new( "Bad environment..." )
|
21
|
+
raise BadEnvironment.new( "Bad environment: '#{system.environment}' for target: '#{system.name}'..." )
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -9,15 +9,20 @@ module RemoteExecutor
|
|
9
9
|
# Get the default configuration over Choice, environment and user default settings
|
10
10
|
def self.get_config_file( config_key )
|
11
11
|
|
12
|
-
|
12
|
+
if( Choice.choices[:config] )
|
13
|
+
return Choice.choices[:config]
|
14
|
+
end
|
13
15
|
|
14
|
-
environment_var = ENV["#{config_key.upcase}"]
|
15
|
-
|
16
|
+
if( environment_var = ENV["#{config_key.upcase}"] )
|
17
|
+
return environment_var
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
if( user_config_file = File.join( "#{ENV['HOME']}", ".#{config_key.downcase}rc" ) )
|
21
|
+
|
22
|
+
return user_config_file if File.exist?( user_config_file )
|
23
|
+
end
|
19
24
|
|
20
|
-
raise YAMLFileNotFound.new( "Configuration
|
25
|
+
raise YAMLFileNotFound.new( "Configuration not found" )
|
21
26
|
end
|
22
27
|
|
23
28
|
def initialize()
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RemoteExecutor
|
2
|
+
|
3
|
+
class System < Struct.new( :name, :environment, :user, :hosts )
|
4
|
+
|
5
|
+
public
|
6
|
+
def initialize( params )
|
7
|
+
|
8
|
+
unless params && params.class == Hash
|
9
|
+
fail "Bad parameters"
|
10
|
+
end
|
11
|
+
|
12
|
+
if( params[:name] &&
|
13
|
+
params[:environment] &&
|
14
|
+
params[:user] &&
|
15
|
+
params[:hosts] )
|
16
|
+
|
17
|
+
super( params[:name], params[:environment], params[:user], params[:hosts] )
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -8,21 +8,9 @@ module RemoteExecutor
|
|
8
8
|
|
9
9
|
def find_system( system_name )
|
10
10
|
|
11
|
-
@config.each { |
|
11
|
+
@config.each { |system| return system if( system[:name] == system_name ) }
|
12
12
|
|
13
|
-
raise ConfigurationError.new( "System #{system_name} not found" )
|
13
|
+
raise ConfigurationError.new( "System: '#{system_name}' not found in #{@config.inspect}" )
|
14
14
|
end
|
15
|
-
|
16
|
-
def find_environment( system_name )
|
17
|
-
@config.each { |s| return s[:environment].to_sym if( s[:name] == system_name) }
|
18
|
-
|
19
|
-
raise ConfigurationError.new( "The system #{system_name} do not have declared environment" )
|
20
|
-
end
|
21
|
-
|
22
|
-
def find_hosts( system_name )
|
23
|
-
@config.each { |s| return s[:hosts] if( s[:name] == system_name) }
|
24
|
-
|
25
|
-
raise ConfigurationError.new( "The system #{system_name} do not have host lists, WTF!!!" )
|
26
|
-
end
|
27
15
|
end
|
28
16
|
end
|
data/lib/remote_executor.rb
CHANGED
@@ -7,7 +7,7 @@ end
|
|
7
7
|
$:.unshift File.join( File.dirname( __FILE__), 'remote_executor' )
|
8
8
|
|
9
9
|
begin
|
10
|
-
%w[version config system_config options_parser cli].each { |lib| require lib }
|
10
|
+
%w[version config system_config system options_parser cli].each { |lib| require lib }
|
11
11
|
rescue LoadError => e
|
12
12
|
fail "Some lib dependencies can not be loaded: #{e.message}"
|
13
13
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_executor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Javier Juarez
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/remote_executor/cli.rb
|
61
61
|
- lib/remote_executor/config.rb
|
62
62
|
- lib/remote_executor/options_parser.rb
|
63
|
+
- lib/remote_executor/system.rb
|
63
64
|
- lib/remote_executor/system_config.rb
|
64
65
|
- lib/remote_executor/version.rb
|
65
66
|
- README.rdoc
|