rundock 1.1.7 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +6 -0
- data/lib/rundock/builder/operation_builder.rb +6 -19
- data/lib/rundock/builder/target_builder.rb +17 -38
- data/lib/rundock/builder/task_builder.rb +0 -2
- data/lib/rundock/logger.rb +9 -12
- data/lib/rundock/plugin/target/group.rb +22 -0
- data/lib/rundock/plugin/target/host.rb +14 -0
- data/lib/rundock/runner.rb +1 -1
- data/lib/rundock/target/base.rb +21 -0
- data/lib/rundock/target_factory.rb +31 -0
- data/lib/rundock/version.rb +1 -1
- data/lib/rundock.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f82ec4374a46a20026e0417e0c7f66d7d057e8b
|
4
|
+
data.tar.gz: 8b580b3c626012b28be9fbc2613f97f87ee9f212
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6be0922ed3c5b1da9b1af40872eff0f329ee40743a6f66c6cc55a68ca61e810971920dfe35522487e54a83051ca549e039361ed9fd1a23980fea9ad762896426
|
7
|
+
data.tar.gz: beab9f72f9ace44c0e65e9222f1df9489306565204fda69ff213c25f60317bd51838ae75db528d88cf4ef3b2f5771fcfb37601a462ac4c53f80489e76408016b
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,7 @@ module Rundock
|
|
2
2
|
module Builder
|
3
3
|
class OperationBuilder < Base
|
4
4
|
def build_first(scenario, targets, tasks, hooks)
|
5
|
-
parsing_node_attribute =
|
5
|
+
parsing_node_attribute = Rundock::Attribute::NodeAttribute.new(task_info: {})
|
6
6
|
scen = Scenario.new
|
7
7
|
scen.tasks = tasks
|
8
8
|
|
@@ -12,21 +12,12 @@ module Rundock
|
|
12
12
|
hook_contents = []
|
13
13
|
|
14
14
|
sn.deep_symbolize_keys.each do |sk, sv|
|
15
|
-
if sk
|
15
|
+
if %i[target target_group].include?(sk)
|
16
16
|
target_builder = TargetBuilder.new(@options)
|
17
|
-
|
18
|
-
|
19
|
-
if target.is_a?(Node)
|
20
|
-
nodes = Array(target)
|
21
|
-
parsing_node_attribute = build_node_attribute(scen, sv, parsing_node_attribute, tasks, target_builder.parsed_node_options[sv.to_sym])
|
22
|
-
operations = Array(build_cli_command_operation(@options[:command], parsing_node_attribute, @options)) if @options[:command]
|
23
|
-
end
|
24
|
-
elsif sk == :target_group
|
25
|
-
target_builder = TargetBuilder.new(@options)
|
26
|
-
nodes = target_builder.build_group(sv, targets)
|
17
|
+
nodes, target_options = target_builder.build(sv, targets)
|
27
18
|
nodes.each do |n|
|
28
19
|
if n.is_a?(Node)
|
29
|
-
parsing_node_attribute = build_node_attribute(scen, n.name, parsing_node_attribute, tasks,
|
20
|
+
parsing_node_attribute = build_node_attribute(scen, n.name, parsing_node_attribute, tasks, target_options[n.name.to_sym])
|
30
21
|
operations = Array(build_cli_command_operation(@options[:command], parsing_node_attribute, @options)) if @options[:command]
|
31
22
|
end
|
32
23
|
end
|
@@ -94,14 +85,10 @@ module Rundock
|
|
94
85
|
private
|
95
86
|
|
96
87
|
def build_node_attribute(scenario, nodename, node_attribute, tasks, parsed_options)
|
97
|
-
|
98
|
-
node_attribute = Rundock::Attribute::NodeAttribute.new(task_info: {})
|
99
|
-
else
|
100
|
-
node_attribute.init_except_take_over_state
|
101
|
-
end
|
102
|
-
|
88
|
+
node_attribute.init_except_take_over_state
|
103
89
|
node_attribute.nodename = nodename
|
104
90
|
tasks.each { |k, v| node_attribute.task_info[k] = v } if tasks
|
91
|
+
|
105
92
|
scenario.node_info[nodename.to_sym] = node_attribute.nodeinfo = parsed_options
|
106
93
|
|
107
94
|
node_attribute
|
@@ -1,51 +1,30 @@
|
|
1
1
|
module Rundock
|
2
2
|
module Builder
|
3
3
|
class TargetBuilder < Base
|
4
|
-
|
5
|
-
TargetGroupNotFoundError = Class.new(StandardError)
|
6
|
-
|
7
|
-
attr_accessor :parsed_node_options
|
4
|
+
DEFAULT_TARGET_TYPE = 'host'
|
8
5
|
|
9
6
|
def build(target_name, target_info)
|
10
|
-
|
11
|
-
if target_info.nil? ||
|
12
|
-
!target_info.key?(target_name.to_sym) ||
|
13
|
-
!target_info[target_name.to_sym].key?(:target_type) ||
|
14
|
-
target_info[target_name.to_sym][:target_type] == 'host'
|
7
|
+
target_type = DEFAULT_TARGET_TYPE
|
15
8
|
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
if target_info.nil? ||
|
10
|
+
!target_info.key?(target_name.to_sym)
|
11
|
+
target_info = { target_name.to_sym => {} }
|
12
|
+
target_type = DEFAULT_TARGET_TYPE
|
19
13
|
else
|
20
|
-
|
14
|
+
target_type = if target_info[target_name.to_sym].key?(:target_type)
|
15
|
+
target_info[target_name.to_sym][:target_type]
|
16
|
+
else
|
17
|
+
DEFAULT_TARGET_TYPE
|
18
|
+
end
|
21
19
|
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if !target_info.nil? &&
|
28
|
-
target_info.key?(target_group_name.to_sym) &&
|
29
|
-
target_info[target_group_name.to_sym][:target_type] == 'group' &&
|
30
|
-
target_info[target_group_name.to_sym].key?(:targets) &&
|
31
|
-
target_info[target_group_name.to_sym][:targets].is_a?(Array)
|
32
|
-
|
33
|
-
targets = target_info[target_group_name.to_sym][:targets]
|
34
|
-
nodes = []
|
35
|
-
@parsed_node_options = {}
|
36
|
-
|
37
|
-
targets.each do |n|
|
38
|
-
backend_builder = BackendBuilder.new(@options, n, target_info)
|
39
|
-
backend = backend_builder.build
|
40
|
-
|
41
|
-
@parsed_node_options[n.to_sym] = backend_builder.parsed_options
|
42
|
-
nodes << Node.new(n, backend)
|
43
|
-
end
|
44
|
-
|
45
|
-
nodes
|
46
|
-
else
|
47
|
-
raise TargetGroupNotFoundError
|
21
|
+
begin
|
22
|
+
target = Rundock::TargetFactory.instance(target_type).create(target_name, target_info[target_name.to_sym])
|
23
|
+
rescue Rundock::TargetFactory::TargetNotSupportedError
|
24
|
+
Logger.error("target type not supported: #{target_type}")
|
48
25
|
end
|
26
|
+
|
27
|
+
target.create_nodes(target_info, @options)
|
49
28
|
end
|
50
29
|
end
|
51
30
|
end
|
data/lib/rundock/logger.rb
CHANGED
@@ -143,19 +143,16 @@ module Rundock
|
|
143
143
|
end
|
144
144
|
|
145
145
|
def colorize(msg, severity)
|
146
|
-
col =
|
147
|
-
|
146
|
+
col = @color ||
|
147
|
+
case severity
|
148
|
+
when 'INFO'
|
149
|
+
:clear
|
150
|
+
when 'WARN'
|
151
|
+
:yellow
|
152
|
+
when 'ERROR'
|
153
|
+
:red
|
148
154
|
else
|
149
|
-
|
150
|
-
when 'INFO'
|
151
|
-
:clear
|
152
|
-
when 'WARN'
|
153
|
-
:yellow
|
154
|
-
when 'ERROR'
|
155
|
-
:red
|
156
|
-
else
|
157
|
-
:clear
|
158
|
-
end
|
155
|
+
:clear
|
159
156
|
end
|
160
157
|
|
161
158
|
ANSI.public_send(col) { msg }
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rundock/target/base'
|
2
|
+
|
3
|
+
module Rundock
|
4
|
+
module Target
|
5
|
+
class Group < Base
|
6
|
+
def create_nodes(target_info = {}, options = {})
|
7
|
+
targets = @contents[:targets]
|
8
|
+
|
9
|
+
nodes = []
|
10
|
+
|
11
|
+
targets.each do |n|
|
12
|
+
backend_builder = Rundock::Builder::BackendBuilder.new(options, n, target_info)
|
13
|
+
backend = backend_builder.build
|
14
|
+
@parsed_options[n.to_sym] = backend_builder.parsed_options
|
15
|
+
nodes << Node.new(n, backend)
|
16
|
+
end
|
17
|
+
|
18
|
+
[nodes, @parsed_options]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rundock/target/base'
|
2
|
+
|
3
|
+
module Rundock
|
4
|
+
module Target
|
5
|
+
class Host < Base
|
6
|
+
def create_nodes(target_info = {}, options = {})
|
7
|
+
backend_builder = Rundock::Builder::BackendBuilder.new(options, @name, target_info)
|
8
|
+
backend = backend_builder.build
|
9
|
+
@parsed_options = { @name.to_sym => backend_builder.parsed_options }
|
10
|
+
[Array(Node.new(@name, backend)), @parsed_options]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rundock/runner.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rundock
|
2
|
+
module Target
|
3
|
+
class Base
|
4
|
+
TargetNotImplementedError = Class.new(NotImplementedError)
|
5
|
+
|
6
|
+
attr_reader :name
|
7
|
+
attr_reader :contents
|
8
|
+
attr_reader :parsed_options
|
9
|
+
|
10
|
+
def initialize(name, contents = {})
|
11
|
+
@name = name
|
12
|
+
@contents = contents
|
13
|
+
@parsed_options = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_nodes(target_info = {}, options = {})
|
17
|
+
raise TargetNotImplementedError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rundock
|
2
|
+
class TargetFactory
|
3
|
+
TargetNotSupportedError = Class.new(StandardError)
|
4
|
+
|
5
|
+
def self.instance(type)
|
6
|
+
self.new(type)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(type)
|
10
|
+
@type = type
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(name, attributes)
|
14
|
+
klass = "Rundock::Target::#{@type.to_s.to_camel_case}"
|
15
|
+
Logger.debug("initialize #{klass} target")
|
16
|
+
raise TargetNotSupportedError unless Rundock::Target::Base.subclasses.map(&:to_s).include?(klass)
|
17
|
+
|
18
|
+
obj = nil
|
19
|
+
klass.split('::').map do |k|
|
20
|
+
obj = if obj.nil?
|
21
|
+
Kernel.const_get(k)
|
22
|
+
else
|
23
|
+
obj = obj.const_get(k)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
target = obj.new(name, attributes)
|
28
|
+
target
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/rundock/version.rb
CHANGED
data/lib/rundock.rb
CHANGED
@@ -9,6 +9,8 @@ require 'rundock/operation/command'
|
|
9
9
|
require 'rundock/operation_factory'
|
10
10
|
require 'rundock/hook_factory'
|
11
11
|
require 'rundock/hook/base'
|
12
|
+
require 'rundock/target_factory'
|
13
|
+
require 'rundock/target/base'
|
12
14
|
require 'rundock/node'
|
13
15
|
require 'rundock/attribute/base'
|
14
16
|
require 'rundock/attribute/node_attribute'
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hiracy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -197,8 +197,12 @@ files:
|
|
197
197
|
- lib/rundock/plugin/operation/deploy.rb
|
198
198
|
- lib/rundock/plugin/operation/host_inventory.rb
|
199
199
|
- lib/rundock/plugin/operation/sample_operation.rb
|
200
|
+
- lib/rundock/plugin/target/group.rb
|
201
|
+
- lib/rundock/plugin/target/host.rb
|
200
202
|
- lib/rundock/runner.rb
|
201
203
|
- lib/rundock/scenario.rb
|
204
|
+
- lib/rundock/target/base.rb
|
205
|
+
- lib/rundock/target_factory.rb
|
202
206
|
- lib/rundock/version.rb
|
203
207
|
- rundock.gemspec
|
204
208
|
- scenario_sample.yml
|