rundock 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/rundock/attribute/base.rb +30 -0
- data/lib/rundock/attribute/node_attribute.rb +21 -0
- data/lib/rundock/backend.rb +7 -0
- data/lib/rundock/builder/backend_builder.rb +7 -2
- data/lib/rundock/builder/operation_builder.rb +14 -13
- data/lib/rundock/cli.rb +4 -0
- data/lib/rundock/operation/task.rb +2 -2
- data/lib/rundock/plugin/operation/sample_operation.rb +44 -0
- data/lib/rundock/runner.rb +26 -4
- data/lib/rundock/version.rb +1 -1
- data/lib/rundock.rb +2 -0
- data/scenario_sample.yml +2 -2
- data/spec/integration/platforms/localhost/scenarios/simple_plugin_scenario.yml +10 -0
- data/spec/integration/recipes/simple_plugin_scenario_spec.rb +6 -0
- data/spec/integration/scenarios/simple_plugin_scenario.yml +14 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1185fca2a1ac6281bed2903980ac243aa515d728
|
4
|
+
data.tar.gz: 2a33d417121c653dbab71d14d20090bad52588df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee69507c2340f648f8d702d8fcb4d80153d1336633ab1eb55e3e4fd130a53f9318d408b73989aab65d3d95ef296b7790b1d5612a5c89984eb738ab76f9bf58e9
|
7
|
+
data.tar.gz: 6d319b172002d86612a4b986887dc76c0655268d36834b9e794b8c6946076985adbe1a28d07db30685bc0d4f26048dab62b77c0cf6a08362e850337b0c321495
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Rundock
|
2
|
+
module Attribute
|
3
|
+
class Base
|
4
|
+
def initialize(attr = {})
|
5
|
+
attr.each { |k, v| define_attr(k.to_sym, v) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.attr_accessor(*vars)
|
9
|
+
@attributes ||= []
|
10
|
+
@attributes.concat(vars)
|
11
|
+
super(*vars)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.list
|
15
|
+
@attributes
|
16
|
+
end
|
17
|
+
|
18
|
+
def list
|
19
|
+
self.class.list.each_with_object({}) do |a, result|
|
20
|
+
result[a] = self.send(a)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def define_attr(name, val)
|
25
|
+
self.class.send(:attr_accessor, name)
|
26
|
+
self.send("#{name}=", val)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rundock
|
2
|
+
module Attribute
|
3
|
+
class NodeAttribute < Base
|
4
|
+
attr_accessor :node
|
5
|
+
attr_accessor :nodename
|
6
|
+
attr_accessor :task_info
|
7
|
+
attr_accessor :errexit
|
8
|
+
|
9
|
+
AVAIL_TAKE_OVERS = [
|
10
|
+
:task_info,
|
11
|
+
:errexit
|
12
|
+
]
|
13
|
+
|
14
|
+
def finalize_node
|
15
|
+
list.each do |k, _v|
|
16
|
+
define_attr(k, nil) unless AVAIL_TAKE_OVERS.include?(k)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/rundock/backend.rb
CHANGED
@@ -3,6 +3,7 @@ require 'singleton'
|
|
3
3
|
require 'specinfra/core'
|
4
4
|
require 'io/console'
|
5
5
|
require 'net/ssh'
|
6
|
+
require 'net/ssh/proxy/command'
|
6
7
|
|
7
8
|
Specinfra::Configuration.error_on_missing_backend_type = true
|
8
9
|
|
@@ -64,6 +65,10 @@ module Rundock
|
|
64
65
|
def create_specinfra_backend
|
65
66
|
raise NotImplementedError
|
66
67
|
end
|
68
|
+
|
69
|
+
def method_missing(method, *args)
|
70
|
+
@backend.send(method, *args)
|
71
|
+
end
|
67
72
|
end
|
68
73
|
|
69
74
|
class Local < Base
|
@@ -88,10 +93,12 @@ module Rundock
|
|
88
93
|
ssh_opts = Net::SSH::Config.for(options[:host])
|
89
94
|
end
|
90
95
|
|
96
|
+
# priority = node_attributes > cli options
|
91
97
|
ssh_opts[:host_name] = options[:host]
|
92
98
|
ssh_opts[:keys] = Array(options[:key]) if options[:key]
|
93
99
|
ssh_opts[:password] = parse_password_from_stdin if options[:ask_password]
|
94
100
|
ssh_opts.merge!(filter_net_ssh_options(options))
|
101
|
+
ssh_opts[:proxy] = Kernel.eval(options[:proxy]) if options[:proxy]
|
95
102
|
|
96
103
|
Logger.debug(%(Net::SSH Options: "#{ssh_opts}"))
|
97
104
|
|
@@ -41,7 +41,7 @@ module Rundock
|
|
41
41
|
@options.keys.select { |o| o.to_s =~ /(\w+)_ssh_default$/ }.each do |oo|
|
42
42
|
# no use default ssh options if local
|
43
43
|
# set unless scenario file and cli options specified and not localhost
|
44
|
-
next if
|
44
|
+
next if localhost?
|
45
45
|
opt = oo.to_s.gsub(/_ssh_default/, '').to_sym
|
46
46
|
if !@node_info[@nodename.to_sym][:ssh_opts][opt] && !@options[opt]
|
47
47
|
@node_info[@nodename.to_sym][:ssh_opts][opt] = @options[oo]
|
@@ -56,7 +56,7 @@ module Rundock
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def parse_backend_type
|
59
|
-
if
|
59
|
+
if localhost? &&
|
60
60
|
!@node_info[@nodename.to_sym][:ssh_opts][:port] &&
|
61
61
|
!@node_info[@nodename.to_sym][:ssh_opts][:user] &&
|
62
62
|
!@node_info[@nodename.to_sym][:ssh_opts][:ssh_config]
|
@@ -67,6 +67,11 @@ module Rundock
|
|
67
67
|
|
68
68
|
backend_type
|
69
69
|
end
|
70
|
+
|
71
|
+
def localhost?
|
72
|
+
@nodename =~ /localhost|127\.0\.0\.1/ ||
|
73
|
+
@node_info[@nodename.to_sym][:host] =~ /localhost|127\.0\.0\.1/
|
74
|
+
end
|
70
75
|
end
|
71
76
|
end
|
72
77
|
end
|
@@ -8,8 +8,8 @@ module Rundock
|
|
8
8
|
|
9
9
|
node = nil
|
10
10
|
scen = Scenario.new
|
11
|
-
|
12
|
-
tasks.each { |k, v|
|
11
|
+
node_attribute = Rundock::Attribute::NodeAttribute.new(task_info: {})
|
12
|
+
tasks.each { |k, v| node_attribute.task_info[k] = v } if tasks
|
13
13
|
scen.node_info = node_info
|
14
14
|
scen.tasks = tasks
|
15
15
|
|
@@ -19,10 +19,10 @@ module Rundock
|
|
19
19
|
|
20
20
|
n.deep_symbolize_keys.each do |k, v|
|
21
21
|
if k == :node
|
22
|
+
node_attribute.finalize_node
|
22
23
|
backend = BackendBuilder.new(@options, v, node_info).build
|
23
24
|
node = Node.new(v, backend)
|
24
|
-
|
25
|
-
|
25
|
+
node_attribute.nodename = v
|
26
26
|
if @options[:command]
|
27
27
|
node.add_operation(build_cli_command_operation(@options[:command], @options))
|
28
28
|
end
|
@@ -34,7 +34,7 @@ module Rundock
|
|
34
34
|
|
35
35
|
next unless node
|
36
36
|
|
37
|
-
ope = build_operations(k, Array(v),
|
37
|
+
ope = build_operations(k, Array(v), node_attribute, @options)
|
38
38
|
node.add_operation(ope)
|
39
39
|
end
|
40
40
|
end
|
@@ -44,12 +44,12 @@ module Rundock
|
|
44
44
|
scen
|
45
45
|
end
|
46
46
|
|
47
|
-
def build_task(tasks, backend,
|
48
|
-
node = Node.new(
|
47
|
+
def build_task(tasks, backend, node_attribute)
|
48
|
+
node = Node.new(node_attribute.nodename, backend)
|
49
49
|
scen = Scenario.new
|
50
50
|
|
51
51
|
tasks.each do |k, v|
|
52
|
-
ope = build_operations(k, Array(v),
|
52
|
+
ope = build_operations(k, Array(v), node_attribute, nil)
|
53
53
|
node.add_operation(ope)
|
54
54
|
end
|
55
55
|
|
@@ -73,15 +73,16 @@ module Rundock
|
|
73
73
|
private
|
74
74
|
|
75
75
|
def build_cli_command_operation(command, cli_options)
|
76
|
-
|
77
|
-
|
76
|
+
node_attribute = Rundock::Attribute::NodeAttribute.new
|
77
|
+
node_attribute.errexit = !cli_options[:run_anyway]
|
78
78
|
Rundock::OperationFactory.instance(:command).create(Array(command), nil)
|
79
79
|
end
|
80
80
|
|
81
81
|
def build_operations(ope_type, ope_content, node_attributes, cli_options)
|
82
|
-
node_attributes
|
83
|
-
node_attributes
|
84
|
-
|
82
|
+
node_attributes.errexit = !cli_options[:run_anyway] if cli_options
|
83
|
+
node_attributes.errexit = true if cli_options.nil?
|
84
|
+
node_attributes.define_attr(ope_type, ope_content)
|
85
|
+
Rundock::OperationFactory.instance(ope_type).create(Array(ope_content), node_attributes.list)
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
data/lib/rundock/cli.rb
CHANGED
@@ -3,13 +3,13 @@ module Rundock
|
|
3
3
|
class Task < Base
|
4
4
|
def run(backend, attributes = {})
|
5
5
|
@instruction.each do |i|
|
6
|
-
unless attributes[:
|
6
|
+
unless attributes[:task_info].key?(i.to_sym)
|
7
7
|
Logger.warn("task not found and ignored: #{i}")
|
8
8
|
next
|
9
9
|
end
|
10
10
|
|
11
11
|
scenario = Rundock::Builder::ScenarioBuilder.new(nil, nil).build_task(
|
12
|
-
attributes[:
|
12
|
+
attributes[:task_info][i.to_sym], backend, Rundock::Attribute::NodeAttribute.new(attributes))
|
13
13
|
|
14
14
|
scenario.run
|
15
15
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rundock/operation/base'
|
2
|
+
|
3
|
+
module Rundock
|
4
|
+
module Operation
|
5
|
+
# You can use this sample as following scenario.yml for example.
|
6
|
+
#
|
7
|
+
# - node: anyhost-01
|
8
|
+
# sample_operation:
|
9
|
+
# - cmd: 'ls ~'
|
10
|
+
# all: true
|
11
|
+
# ---
|
12
|
+
# anyhost-01:
|
13
|
+
# host: 192.168.1.11
|
14
|
+
# ssh_opts:
|
15
|
+
# port: 22
|
16
|
+
# user: anyuser
|
17
|
+
# key: ~/.ssh/id_rsa
|
18
|
+
# ---
|
19
|
+
class SampleOperation < Base
|
20
|
+
def run(backend, attributes)
|
21
|
+
operation = attributes[:sample_operation][0]
|
22
|
+
|
23
|
+
cmd = ''
|
24
|
+
args_line = ''
|
25
|
+
operation.each do |k, v|
|
26
|
+
if k == :cmd
|
27
|
+
cmd = v
|
28
|
+
next
|
29
|
+
end
|
30
|
+
|
31
|
+
if v.is_a?(TrueClass)
|
32
|
+
args_line << " --#{k}"
|
33
|
+
elsif v.is_a?(String)
|
34
|
+
args_line << " --#{k} #{v}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Logger.info("do #{cmd}#{args_line}")
|
39
|
+
result = backend.run_command("#{cmd}#{args_line}")
|
40
|
+
Logger.info(result.stdout)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/rundock/runner.rb
CHANGED
@@ -4,12 +4,14 @@ require 'open-uri'
|
|
4
4
|
module Rundock
|
5
5
|
class Runner
|
6
6
|
ScenarioNotFoundError = Class.new(StandardError)
|
7
|
+
RUNDOCK_PLUGINS = %w(operation hook)
|
7
8
|
|
8
9
|
class << self
|
9
10
|
def run(options)
|
10
11
|
Logger.debug 'Starting Rundoc:'
|
11
12
|
|
12
13
|
runner = self.new(options)
|
14
|
+
runner.load_plugins
|
13
15
|
runner.build(options)
|
14
16
|
runner.run
|
15
17
|
end
|
@@ -25,10 +27,6 @@ module Rundock
|
|
25
27
|
@scenario.run
|
26
28
|
end
|
27
29
|
|
28
|
-
def run_tasks
|
29
|
-
@scenario.run
|
30
|
-
end
|
31
|
-
|
32
30
|
def build(options)
|
33
31
|
if options[:scenario] || options[:hostgroup]
|
34
32
|
if options[:scenario] && !FileTest.exist?(options[:scenario])
|
@@ -55,5 +53,29 @@ module Rundock
|
|
55
53
|
@scenario = Rundock::Builder::ScenarioBuilder.new(options, nil).build
|
56
54
|
end
|
57
55
|
end
|
56
|
+
|
57
|
+
def load_plugins
|
58
|
+
Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/plugin/**/*.rb").each do |f|
|
59
|
+
require f.gsub(/.rb$/, '')
|
60
|
+
end
|
61
|
+
|
62
|
+
gems = []
|
63
|
+
Gem::Specification.each do |gem|
|
64
|
+
gems << gem.name
|
65
|
+
end
|
66
|
+
gems.uniq!
|
67
|
+
|
68
|
+
gems.each do |g|
|
69
|
+
RUNDOCK_PLUGINS.each do |plugin|
|
70
|
+
next if g !~ /^(rundock-plugin-#{plugin})-/
|
71
|
+
next if Gem::Specification.find_by_path(g).nil?
|
72
|
+
Logger.debug("Loading rundock plugin: #{g}")
|
73
|
+
libdir = "#{Gem::Specification.find_by_path(g).full_gem_path}/lib/rundock/plugin/#{Regexp.last_match(0)}"
|
74
|
+
Dir.glob("#{libdir}/*.rb").each do |f|
|
75
|
+
require f.gsub(/.rb$/, '')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
58
80
|
end
|
59
81
|
end
|
data/lib/rundock/version.rb
CHANGED
data/lib/rundock.rb
CHANGED
@@ -7,6 +7,8 @@ require 'rundock/operation/task'
|
|
7
7
|
require 'rundock/operation/command'
|
8
8
|
require 'rundock/operation_factory'
|
9
9
|
require 'rundock/node'
|
10
|
+
require 'rundock/attribute/base'
|
11
|
+
require 'rundock/attribute/node_attribute'
|
10
12
|
require 'rundock/scenario'
|
11
13
|
require 'rundock/backend'
|
12
14
|
require 'rundock/builder/base'
|
data/scenario_sample.yml
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
- node: anyhost-01
|
2
|
+
task:
|
3
|
+
- write_echo
|
4
|
+
---
|
5
|
+
anyhost-01:
|
6
|
+
host: 172.17.42.1
|
7
|
+
ssh_opts:
|
8
|
+
port: 22222
|
9
|
+
user: tester
|
10
|
+
key: "<replaced_by_platforms>"
|
11
|
+
---
|
12
|
+
write_echo:
|
13
|
+
sample_operation:
|
14
|
+
- cmd: "echo 'Hello Rundock from SampleOperationPlugin Scenario.' > /var/tmp/hello_rundock_from_sample_operation_scenario"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rundock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hiracy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -151,6 +151,8 @@ files:
|
|
151
151
|
- default_ssh.yml
|
152
152
|
- exe/rundock
|
153
153
|
- lib/rundock.rb
|
154
|
+
- lib/rundock/attribute/base.rb
|
155
|
+
- lib/rundock/attribute/node_attribute.rb
|
154
156
|
- lib/rundock/backend.rb
|
155
157
|
- lib/rundock/builder/backend_builder.rb
|
156
158
|
- lib/rundock/builder/base.rb
|
@@ -166,6 +168,7 @@ files:
|
|
166
168
|
- lib/rundock/operation/command.rb
|
167
169
|
- lib/rundock/operation/task.rb
|
168
170
|
- lib/rundock/operation_factory.rb
|
171
|
+
- lib/rundock/plugin/operation/sample_operation.rb
|
169
172
|
- lib/rundock/runner.rb
|
170
173
|
- lib/rundock/scenario.rb
|
171
174
|
- lib/rundock/version.rb
|
@@ -176,10 +179,13 @@ files:
|
|
176
179
|
- spec/integration/platforms/centos6/setup.sh
|
177
180
|
- spec/integration/platforms/localhost/scenarios/run_anyway_scenario.yml
|
178
181
|
- spec/integration/platforms/localhost/scenarios/simple_echo_scenario.yml
|
182
|
+
- spec/integration/platforms/localhost/scenarios/simple_plugin_scenario.yml
|
179
183
|
- spec/integration/platforms/localhost/scenarios/use_default_ssh_scenario.yml
|
180
184
|
- spec/integration/recipes/simple_echo_scenario_spec.rb
|
181
185
|
- spec/integration/recipes/simple_echo_spec.rb
|
186
|
+
- spec/integration/recipes/simple_plugin_scenario_spec.rb
|
182
187
|
- spec/integration/scenarios/simple_echo_scenario.yml
|
188
|
+
- spec/integration/scenarios/simple_plugin_scenario.yml
|
183
189
|
- spec/integration/scenarios/use_default_ssh_scenario.yml
|
184
190
|
- spec/integration/spec_helper.rb
|
185
191
|
homepage: https://github.com/hiracy/rundock
|