cm 0.1.4 → 0.1.6

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.
@@ -27,25 +27,48 @@ class PlanAction < Nucleon.plugin_class(:nucleon, :cm_action)
27
27
  'cm.action.plan.base.options.plan',
28
28
  'cm.action.plan.base.errors.plan'
29
29
  ]
30
- register_str :plan_path, Dir.pwd, [
31
- 'cm.action.plan.base.options.plan_path',
32
- 'cm.action.plan.base.errors.plan_path'
30
+ register_str :plan_path, Dir.pwd, 'cm.action.plan.base.options.plan_path'
31
+
32
+ register_configuration_provider :manifest_provider, :file, [
33
+ 'cm.action.plan.base.options.manifest_provider',
34
+ 'cm.action.plan.base.errors.manifest_provider'
35
+ ]
36
+ register_str :manifest, 'plan.yaml', 'cm.action.plan.base.options.manifest'
37
+
38
+ register_configuration_provider :config_provider, :directory, [
39
+ 'cm.action.plan.base.options.config_provider',
40
+ 'cm.action.plan.base.errors.config_provider'
33
41
  ]
34
- register_str :manifest, 'plan.yml', [
35
- 'cm.action.plan.base.options.manifest',
36
- 'cm.action.plan.base.errors.manifest'
42
+ register_str :config_path, Dir.pwd, 'cm.action.plan.base.options.config_path'
43
+
44
+ register_configuration_provider :token_provider, :file, [
45
+ 'cm.action.plan.base.options.token_provider',
46
+ 'cm.action.plan.base.errors.token_provider'
37
47
  ]
38
- register_directory :config_path, Dir.pwd, [
39
- 'cm.action.plan.base.options.config_path',
40
- 'cm.action.plan.base.errors.config_path'
48
+ register_directory :token_path, Dir.pwd, [
49
+ 'cm.action.plan.base.options.token_path',
50
+ 'cm.action.plan.base.errors.token_path'
41
51
  ]
52
+ register_str :token_file, 'tokens.json', 'cm.action.plan.base.options.token_file'
53
+
42
54
  register_directory :key_path, Dir.pwd, [
43
55
  'cm.action.plan.base.options.key_path',
44
56
  'cm.action.plan.base.errors.key_path'
45
57
  ]
46
58
  register_bool :trap, false, 'cm.action.plan.options.trap'
47
59
 
48
- project_config
60
+ register_sequence_provider :sequence_provider, Nucleon.type_default(:CM, :sequence), [
61
+ 'cm.action.plan.base.options.sequence_provider',
62
+ 'cm.action.plan.base.errors.sequence_provider'
63
+ ]
64
+ register_batch_provider :batch_provider, Nucleon.type_default(:CM, :batch), [
65
+ 'cm.action.plan.base.options.batch_provider',
66
+ 'cm.action.plan.base.errors.batch_provider'
67
+ ]
68
+ register_resource_provider :default_resource_provider, Nucleon.type_default(:CM, :resource), [
69
+ 'cm.action.plan.base.options.default_resource_provider',
70
+ 'cm.action.plan.base.errors.default_resource_provider'
71
+ ]
49
72
 
50
73
  yield if block_given?
51
74
  end
@@ -72,14 +95,20 @@ class PlanAction < Nucleon.plugin_class(:nucleon, :cm_action)
72
95
 
73
96
  def initialize_plan
74
97
  @plan = CM.plan(plugin_name, extended_config(:plan, {
75
- :path => settings[:plan_path],
76
- :config_directory => settings[:config_path],
77
- :key_directory => settings[:key_path],
78
- :manifest_file => settings[:manifest],
79
- :project_provider => settings[:project_provider],
80
- :url => settings[:project_reference],
81
- :revision => settings[:project_revision],
82
- :trap => settings[:trap]
98
+ :action_settings => Nucleon::Config.ensure(settings).export,
99
+ :path => settings[:plan_path],
100
+ :config_provider => settings[:config_provider],
101
+ :config_path => settings[:config_path],
102
+ :key_directory => settings[:key_path],
103
+ :manifest_provider => settings[:manifest_provider],
104
+ :manifest_file => settings[:manifest],
105
+ :token_provider => settings[:token_provider],
106
+ :token_directory => settings[:token_path],
107
+ :token_file => settings[:token_file],
108
+ :trap => settings[:trap],
109
+ :sequence_provider => settings[:sequence_provider],
110
+ :batch_provider => settings[:batch_provider],
111
+ :default_resource_provider => settings[:default_resource_provider]
83
112
  }), settings[:plan_provider])
84
113
  end
85
114
  end
@@ -1,11 +1,7 @@
1
1
 
2
- nucleon_require(File.dirname(__FILE__), :parallel_base)
3
-
4
- #---
5
-
6
2
  module CM
7
3
  module Plugin
8
- class Job < Nucleon.plugin_class(:nucleon, :parallel_base)
4
+ class Resource < Nucleon.plugin_class(:nucleon, :base)
9
5
 
10
6
  def self.register_ids
11
7
  [ :id ]
@@ -17,7 +13,7 @@ class Job < Nucleon.plugin_class(:nucleon, :parallel_base)
17
13
  def normalize(reload)
18
14
  super
19
15
 
20
- @sequence = delete(:sequence, nil) unless reload
16
+ @plan = delete(:plan, nil) unless reload
21
17
 
22
18
  yield if block_given?
23
19
  end
@@ -25,8 +21,6 @@ class Job < Nucleon.plugin_class(:nucleon, :parallel_base)
25
21
  #---
26
22
 
27
23
  def init_tokens
28
- @tokens = {}
29
-
30
24
  collect_tokens = lambda do |local_settings, token|
31
25
  local_settings.each do |name, value|
32
26
  setting_token = [ array(token), name ].flatten
@@ -35,7 +29,7 @@ class Job < Nucleon.plugin_class(:nucleon, :parallel_base)
35
29
  collect_tokens.call(value, setting_token)
36
30
  else
37
31
  token_base = setting_token.shift
38
- sequence.set_token(token_base, setting_token, value)
32
+ plan.set_token(token_base, setting_token, value)
39
33
  end
40
34
  end
41
35
  end
@@ -54,8 +48,8 @@ class Job < Nucleon.plugin_class(:nucleon, :parallel_base)
54
48
  #-----------------------------------------------------------------------------
55
49
  # Property accessors / modifiers
56
50
 
57
- def sequence
58
- @sequence
51
+ def plan
52
+ @plan
59
53
  end
60
54
 
61
55
  #---
@@ -74,23 +68,48 @@ class Job < Nucleon.plugin_class(:nucleon, :parallel_base)
74
68
  hash(settings[:parameters])
75
69
  end
76
70
 
71
+ #---
72
+
73
+ def data
74
+ hash(@data)
75
+ end
76
+
77
+ def data=data
78
+ @data = hash(data)
79
+ end
80
+
77
81
  #-----------------------------------------------------------------------------
78
82
  # Operations
79
83
 
80
- def execute
84
+ def execute(operation)
81
85
  if initialized?
86
+ method = "operation_#{operation}"
82
87
  success = true
83
88
 
84
89
  execute_functions
85
90
  interpolate_parameters
86
91
 
87
- success = yield if block_given?
92
+ if respond_to?(method)
93
+ success = send(method)
94
+ end
88
95
  else
89
96
  success = false
90
97
  end
91
98
  success
92
99
  end
93
100
 
101
+ #---
102
+
103
+ def operation_deploy
104
+ yield if block_given?
105
+ end
106
+
107
+ #---
108
+
109
+ def operation_destroy
110
+ yield if block_given?
111
+ end
112
+
94
113
  #-----------------------------------------------------------------------------
95
114
  # Utilities
96
115
 
@@ -135,7 +154,7 @@ class Job < Nucleon.plugin_class(:nucleon, :parallel_base)
135
154
  def interpolate_parameters
136
155
  interpolate_value = lambda do |base_config, name, value|
137
156
  interpolations = false
138
- sequence.tokens.each do |token_name, token_value|
157
+ plan.tokens.each do |token_name, token_value|
139
158
  if value.is_a?(String) && value.gsub!(/\{\{#{token_name}\}\}/, token_value.to_s)
140
159
  interpolations = true
141
160
  end
@@ -1,11 +1,7 @@
1
1
 
2
- nucleon_require(File.dirname(__FILE__), :parallel_base)
3
-
4
- #---
5
-
6
2
  module CM
7
3
  module Plugin
8
- class Sequence < Nucleon.plugin_class(:nucleon, :parallel_base)
4
+ class Sequence < Nucleon.plugin_class(:nucleon, :base)
9
5
 
10
6
  #-----------------------------------------------------------------------------
11
7
  # Plugin interface
@@ -13,107 +9,66 @@ class Sequence < Nucleon.plugin_class(:nucleon, :parallel_base)
13
9
  def normalize(reload)
14
10
  super
15
11
 
16
- init_tokens
17
- init_jobs
12
+ @plan = delete(:plan, nil) unless reload
18
13
 
14
+ init_resources
19
15
  yield if block_given?
20
16
  end
21
17
 
22
18
  #---
23
19
 
24
- def init_jobs
25
- @jobs = []
26
- get_array(:jobs).each do |job_config|
27
- if job_config.has_key?(:aggregate) # Array
28
- @jobs << create_batch(job_config[:aggregate])
20
+ def init_resources
21
+ @resources = []
22
+ get_array(:resources).each do |resource_config|
23
+ resource_config = Nucleon::Config.ensure(resource_config)
24
+
25
+ if resource_config.has_key?(:aggregate) # Array
26
+ @resources << plan.create_batch(resource_config[:aggregate])
29
27
  else # Atomic
30
- @jobs << create_job(job_config)
28
+ @resources << plan.create_resource(resource_config)
31
29
  end
32
30
  end
33
- @jobs
34
- end
35
-
36
- #---
37
-
38
- def init_tokens
39
- clear_tokens
40
-
41
- collect_tokens = lambda do |local_settings, token|
42
- local_settings.each do |name, value|
43
- setting_token = [ array(token), name ].flatten
44
-
45
- if value.is_a?(Hash)
46
- collect_tokens.call(value, setting_token)
47
- else
48
- token_base = setting_token.shift
49
- set_token(token_base, setting_token, value)
50
- end
51
- end
52
- end
53
-
54
- # Generate config tokens
55
- collect_tokens.call(settings, 'config')
31
+ @resources
56
32
  end
57
33
 
58
34
  #-----------------------------------------------------------------------------
59
35
  # Checks
60
36
 
61
37
  def initialized?(options = {})
62
- !@jobs.empty?
38
+ !@resources.empty?
63
39
  end
64
40
 
65
41
  #-----------------------------------------------------------------------------
66
42
  # Property accessors / modifiers
67
43
 
68
- def settings
69
- get_hash(:settings)
44
+ def plan
45
+ @plan
70
46
  end
71
47
 
72
48
  #---
73
49
 
74
- def tokens
75
- @tokens
76
- end
77
-
78
- def set_token(id, location, value)
79
- @tokens["#{id}:#{array(location).join('.')}"] = value
80
- end
81
-
82
- def remove_token(id, location)
83
- @tokens.delete("#{id}:#{array(location).join('.')}")
84
- end
85
-
86
- def clear_tokens
87
- @tokens = {}
50
+ def settings
51
+ get_hash(:settings)
88
52
  end
89
53
 
90
54
  #---
91
55
 
92
- def jobs
93
- @jobs
94
- end
95
-
96
- def jobs=jobs
97
- set(:jobs, Nucleon::Util::Data.array(jobs))
98
- init_jobs
99
- init_tokens
56
+ def resources
57
+ @resources
100
58
  end
101
59
 
102
- #---
103
-
104
- def trap
105
- get(:trap, false)
60
+ def resources=resources
61
+ set(:resources, Nucleon::Util::Data.array(resources))
62
+ init_resources
106
63
  end
107
64
 
108
65
  #-----------------------------------------------------------------------------
109
66
  # Operations
110
67
 
111
- def forward(options)
112
- config = Nucleon::Config.ensure(options)
113
-
68
+ def forward(operation)
114
69
  if initialized?
115
70
  success = true
116
- success = yield(config, success) if block_given?
71
+ success = yield(success) if block_given?
117
72
  else
118
73
  success = false
119
74
  end
@@ -122,12 +77,10 @@ class Sequence < Nucleon.plugin_class(:nucleon, :parallel_base)
122
77
 
123
78
  #---
124
79
 
125
- def reverse(options)
126
- config = Nucleon::Config.ensure(options)
127
-
80
+ def reverse(operation)
128
81
  if initialized?
129
82
  success = true
130
- success = yield(config, success) if block_given?
83
+ success = yield(success) if block_given?
131
84
  else
132
85
  success = false
133
86
  end
@@ -137,42 +90,6 @@ class Sequence < Nucleon.plugin_class(:nucleon, :parallel_base)
137
90
  #-----------------------------------------------------------------------------
138
91
  # Utilities
139
92
 
140
- def step
141
- answer = ask('Continue? (yes|no): ', { :i18n => false })
142
- answer.match(/^[Yy][Ee][Ss]$/) ? false : true
143
- end
144
-
145
- #---
146
-
147
- def create_sequence(jobs)
148
- CM.sequence({
149
- :settings => settings,
150
- :jobs => jobs,
151
- :trap => trap,
152
- :new => true,
153
- }, get(:sequence_provider, :default))
154
- end
155
-
156
- #---
157
-
158
- def create_batch(jobs)
159
- CM.batch({
160
- :sequence => myself,
161
- :jobs => jobs,
162
- :new => true
163
- }, get(:batch_provider, :celluloid))
164
- end
165
-
166
- #---
167
-
168
- def create_job(settings)
169
- settings[:type] ||= get(:default_job_provider, :variables)
170
- CM.job({
171
- :sequence => myself,
172
- :settings => settings,
173
- :id => settings[:name]
174
- }, settings[:type])
175
- end
176
93
  end
177
94
  end
178
95
  end
@@ -0,0 +1,53 @@
1
+
2
+ module Nucleon
3
+ module Action
4
+ module Resource
5
+ class Run < Nucleon.plugin_class(:nucleon, :plan_action)
6
+
7
+ #-----------------------------------------------------------------------------
8
+ # Info
9
+
10
+ def self.describe
11
+ super(:resource, :run, 500)
12
+ end
13
+
14
+ #-----------------------------------------------------------------------------
15
+ # Checks
16
+
17
+ def strict?
18
+ false
19
+ end
20
+
21
+ #-----------------------------------------------------------------------------
22
+ # Settings
23
+
24
+ def configure
25
+ super do
26
+ codes :run_failed
27
+
28
+ register_str :provider, nil
29
+ register_str :operation, nil
30
+ end
31
+ end
32
+
33
+ #---
34
+
35
+ def arguments
36
+ [:provider, :operation]
37
+ end
38
+
39
+ #-----------------------------------------------------------------------------
40
+ # Action operations
41
+
42
+ def execute
43
+ super do
44
+ resource = plan.create_resource(settings[:resource_config])
45
+ success = resource.execute(settings[:operation])
46
+
47
+ myself.status = code.run_failed unless success
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end