rundock 1.1.7 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41eab756e59dece15df6f146b5e1c7bfe5130165
4
- data.tar.gz: e06935ab43506d934940fead88343ac6b2f28f8c
3
+ metadata.gz: 6f82ec4374a46a20026e0417e0c7f66d7d057e8b
4
+ data.tar.gz: 8b580b3c626012b28be9fbc2613f97f87ee9f212
5
5
  SHA512:
6
- metadata.gz: c8b825b2ba472f9acdd8e0a0a640ce53ba2c9fc2fdc0b65ddc25a020a2eb47b09d4d953104ab3d3d6d3724b8fed50df88fc55e4873ac2fec599aab3b11d64fb6
7
- data.tar.gz: 1612a61ce7d34945b7782bfa16fde756a5b8426bd06ecb2b4354c7bbb3f57b04d580ebf44c03f359fb410f17ce7f2a644bae259fb6077fb4ebb3740ac9bf447b
6
+ metadata.gz: 6be0922ed3c5b1da9b1af40872eff0f329ee40743a6f66c6cc55a68ca61e810971920dfe35522487e54a83051ca549e039361ed9fd1a23980fea9ad762896426
7
+ data.tar.gz: beab9f72f9ace44c0e65e9222f1df9489306565204fda69ff213c25f60317bd51838ae75db528d88cf4ef3b2f5771fcfb37601a462ac4c53f80489e76408016b
data/.rubocop.yml CHANGED
@@ -66,7 +66,10 @@ Style/NumericLiterals:
66
66
  Style/NumericPredicate:
67
67
  Enabled: false
68
68
 
69
- Style/MethodMissing:
69
+ Style/MethodMissingSuper:
70
+ Enabled: false
71
+
72
+ Style/MissingRespondToMissing:
70
73
  Enabled: false
71
74
 
72
75
  Style/FormatStringToken:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v1.2.0
2
+
3
+ Update
4
+
5
+ - Support target plugins
6
+
1
7
  ## v1.1.7
2
8
 
3
9
  Update
@@ -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 = nil
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 == :target
15
+ if %i[target target_group].include?(sk)
16
16
  target_builder = TargetBuilder.new(@options)
17
- target = target_builder.build(sv, targets)
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, target_builder.parsed_node_options[n.name.to_sym])
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
- if node_attribute.nil?
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
- TargetNoSupportError = Class.new(NotImplementedError)
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
- # host type specified if target not found.
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
- backend_builder = BackendBuilder.new(@options, target_name, target_info)
17
- backend = backend_builder.build
18
- @parsed_node_options = { target_name.to_sym => backend_builder.parsed_options }
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
- raise TargetNoSupportError
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
- Node.new(target_name, backend)
24
- end
25
-
26
- def build_group(target_group_name, target_info)
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
@@ -3,8 +3,6 @@ require 'yaml'
3
3
  module Rundock
4
4
  module Builder
5
5
  class TaskBuilder < Base
6
- DEFAULT_TASKS_FILE_PATH = './tasks.yml'
7
-
8
6
  def build(scenario_tasks)
9
7
  tasks = if scenario_tasks.nil?
10
8
  {}
@@ -143,19 +143,16 @@ module Rundock
143
143
  end
144
144
 
145
145
  def colorize(msg, severity)
146
- col = if @color
147
- @color
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
- case severity
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
@@ -4,7 +4,7 @@ require 'open-uri'
4
4
  module Rundock
5
5
  class Runner
6
6
  ScenarioNotFoundError = Class.new(StandardError)
7
- RUNDOCK_PLUGINS = %w[operation hook]
7
+ RUNDOCK_PLUGINS = %w[operation hook target]
8
8
 
9
9
  class << self
10
10
  def run(options)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rundock
2
- VERSION = '1.1.7'
2
+ VERSION = '1.2.0'
3
3
  end
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.1.7
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-05-11 00:00:00.000000000 Z
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