cm 0.1.2 → 0.1.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.
@@ -0,0 +1,88 @@
1
+
2
+ nucleon_require(File.dirname(__FILE__), :parallel_base)
3
+
4
+ #---
5
+
6
+ module CM
7
+ module Plugin
8
+ class Configuration < Nucleon.plugin_class(:nucleon, :parallel_base)
9
+
10
+ include Nucleon::Mixin::SubConfig
11
+
12
+ #---
13
+
14
+ def self.register_ids
15
+ [ :name ]
16
+ end
17
+
18
+ #-----------------------------------------------------------------------------
19
+ # Plugin interface
20
+
21
+ def normalize(reload)
22
+ super
23
+
24
+ logger.debug("Initializing source sub configuration")
25
+ init_subconfig(true) unless reload
26
+
27
+ yield if block_given?
28
+ parse
29
+ end
30
+
31
+ #-----------------------------------------------------------------------------
32
+ # Checks
33
+
34
+ def initialized?(options = {})
35
+ true
36
+ end
37
+
38
+ #-----------------------------------------------------------------------------
39
+ # Property accessors / modifiers
40
+
41
+ #-----------------------------------------------------------------------------
42
+ # Operations
43
+
44
+ def wipe
45
+ if initialized?
46
+ clear
47
+ yield if block_given?
48
+ end
49
+ end
50
+
51
+ #---
52
+
53
+ def parse(wipe = true)
54
+ if initialized?
55
+ clear if wipe
56
+ yield if block_given?
57
+ end
58
+ export
59
+ end
60
+
61
+ #---
62
+
63
+ def save
64
+ if initialized?
65
+ yield if block_given?
66
+ end
67
+ end
68
+
69
+ #---
70
+
71
+ def override(properties, keys = nil)
72
+ if initialized?
73
+ if keys.nil?
74
+ import(properties)
75
+ else
76
+ set(keys, Nucleon::Config.new(get(keys), {}, true, false).import(properties).export)
77
+ end
78
+ yield if block_given?
79
+ end
80
+ myself
81
+ end
82
+
83
+ #-----------------------------------------------------------------------------
84
+ # Utilities
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,86 @@
1
+
2
+ nucleon_require(File.dirname(__FILE__), :configuration)
3
+
4
+ #---
5
+
6
+ module CM
7
+ module Plugin
8
+ class DiskConfiguration < Nucleon.plugin_class(:CM, :configuration)
9
+
10
+ def self.register_ids
11
+ [ :name, :path ]
12
+ end
13
+
14
+ #-----------------------------------------------------------------------------
15
+ # Plugin interface
16
+
17
+ def normalize(reload)
18
+ super
19
+ yield if block_given?
20
+ end
21
+
22
+ #-----------------------------------------------------------------------------
23
+ # Checks
24
+
25
+ #-----------------------------------------------------------------------------
26
+ # Property accessors / modifiers
27
+
28
+ def path
29
+ _get(:path)
30
+ end
31
+
32
+ #---
33
+
34
+ def translator_error
35
+ _get(:translator_error, 'translator')
36
+ end
37
+
38
+ def config_error
39
+ _get(:config_error, 'config')
40
+ end
41
+
42
+ #-----------------------------------------------------------------------------
43
+ # Operations
44
+
45
+ #-----------------------------------------------------------------------------
46
+ # Utilities
47
+
48
+ def parse_config(file)
49
+ begin
50
+ provider = File.extname(file).sub(/^\./, '')
51
+ translator = Nucleon.translator({}, provider) if provider
52
+
53
+ raise render_message("#{translator_error}.parse", { :provider => provider, :file => file }) unless translator
54
+ config_data = translator.parse(Nucleon::Util::Disk.read(file))
55
+
56
+ rescue => error
57
+ error("#{config_error}.parse", { :file => file })
58
+ error(error.message, { :i18n => false })
59
+ config_data = nil
60
+ end
61
+ config_data
62
+ end
63
+ protected :parse_config
64
+
65
+ #---
66
+
67
+ def save_config(file, properties)
68
+ begin
69
+ provider = File.extname(file).sub(/^\./, '')
70
+ properties = Nucleon::Config.ensure(properties).export
71
+ translator = Nucleon.translator({}, provider) if provider
72
+
73
+ raise render_message("#{translator_error}.save", { :provider => provider, :file => file }) unless translator
74
+ success = Nucleon::Util::Disk.write(file, translator.generate(properties))
75
+
76
+ rescue => error
77
+ error("#{config_error}.save", { :file => file })
78
+ error(error.message, { :i18n => false })
79
+ success = false
80
+ end
81
+ success
82
+ end
83
+ protected :save_config
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,46 @@
1
+
2
+ nucleon_require(File.dirname(__FILE__), :parallel_base)
3
+
4
+ #---
5
+
6
+ module CM
7
+ module Plugin
8
+ class Job < Nucleon.plugin_class(:nucleon, :parallel_base)
9
+
10
+ #-----------------------------------------------------------------------------
11
+ # Plugin interface
12
+
13
+ def normalize(reload)
14
+ super
15
+ yield if block_given?
16
+ end
17
+
18
+ #-----------------------------------------------------------------------------
19
+ # Checks
20
+
21
+ def initialized?(options = {})
22
+ true
23
+ end
24
+
25
+ #-----------------------------------------------------------------------------
26
+ # Property accessors / modifiers
27
+
28
+ #-----------------------------------------------------------------------------
29
+ # Operations
30
+
31
+ def execute(settings)
32
+ if initialized?
33
+ success = true
34
+ success = yield if block_given?
35
+ else
36
+ success = false
37
+ end
38
+ success
39
+ end
40
+
41
+ #-----------------------------------------------------------------------------
42
+ # Utilities
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+
2
+ module Nucleon
3
+ module Plugin
4
+ class ParallelBase < Nucleon.plugin_class(:nucleon, :base)
5
+
6
+ include Parallel # All sub providers are parallel capable
7
+
8
+ #-----------------------------------------------------------------------------
9
+ # Plugin interface
10
+
11
+ def normalize(reload)
12
+ super
13
+ yield if block_given?
14
+ end
15
+
16
+ #-----------------------------------------------------------------------------
17
+ # Checks
18
+
19
+ def initialized?(options = {})
20
+ true
21
+ end
22
+
23
+ #-----------------------------------------------------------------------------
24
+ # Property accessors / modifiers
25
+
26
+ #-----------------------------------------------------------------------------
27
+ # Operations
28
+
29
+ #-----------------------------------------------------------------------------
30
+ # Utilities
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,193 @@
1
+
2
+ nucleon_require(File.dirname(__FILE__), :disk_configuration)
3
+
4
+ #---
5
+
6
+ module CM
7
+ module Plugin
8
+ class Plan < Nucleon.plugin_class(:CM, :disk_configuration)
9
+
10
+ #-----------------------------------------------------------------------------
11
+ # Plugin interface
12
+
13
+ def normalize(reload)
14
+ super
15
+
16
+ @project = Nucleon.project(extended_config(:plan_project, {
17
+ :provider => _get(:project_provider, Nucleon.type_default(:nucleon, :project)),
18
+ :directory => _get(:path, Dir.pwd),
19
+ :url => _get(:url),
20
+ :revision => _get(:revision, :master),
21
+ :create => true,
22
+ :pull => true,
23
+ :nucleon_resave => false,
24
+ :nucleon_cache => false,
25
+ :nucleon_file => false
26
+ }))
27
+
28
+ if project
29
+ @loaded_config = CM.configuration(extended_config(:config_data, {
30
+ :provider => _get(:config_provider, :directory),
31
+ :path => config_directory
32
+ }))
33
+
34
+ yield if block_given?
35
+ end
36
+ end
37
+
38
+ #-----------------------------------------------------------------------------
39
+ # Checks
40
+
41
+ def initialized?(options = {})
42
+ project && loaded_config
43
+ end
44
+
45
+ #-----------------------------------------------------------------------------
46
+ # Property accessors / modifiers
47
+
48
+ def project
49
+ @project
50
+ end
51
+
52
+ def loaded_config
53
+ @loaded_config
54
+ end
55
+
56
+ #---
57
+
58
+ def path
59
+ project.directory
60
+ end
61
+
62
+ def key_directory
63
+ _get(:key_directory, path)
64
+ end
65
+
66
+ #---
67
+
68
+ def manifest_file
69
+ _get(:manifest_file, 'plan.yml')
70
+ end
71
+
72
+ def manifest_path
73
+ ::File.join(path, manifest_file)
74
+ end
75
+
76
+ def manifest
77
+ export
78
+ end
79
+
80
+ def manifest_config
81
+ get_hash(:config)
82
+ end
83
+
84
+ def manifest_jobs
85
+ get_array(:jobs)
86
+ end
87
+
88
+ #---
89
+
90
+ def config_directory
91
+ _get(:config_directory, path)
92
+ end
93
+
94
+ def output_file
95
+ _get(:output_file, "rendered.#{manifest_file.gsub(/#{File::SEPARATOR}+/, '.')}")
96
+ end
97
+
98
+ def target_path
99
+ ::File.join(config_directory, output_file)
100
+ end
101
+
102
+
103
+ #---
104
+
105
+ def url
106
+ project.url
107
+ end
108
+
109
+ def revision
110
+ project.revision
111
+ end
112
+
113
+ #---
114
+
115
+ def sequence
116
+ @sequence
117
+ end
118
+
119
+ #-----------------------------------------------------------------------------
120
+ # Operations
121
+
122
+ def load
123
+ success = true
124
+
125
+ if initialized?
126
+ # Initialize plan manifest (default config and jobs)
127
+ wipe
128
+ import(CM.configuration(extended_config(:manifest_data, {
129
+ :provider => _get(:manifest_provider, :file),
130
+ :path => manifest_path
131
+ })).export)
132
+
133
+ # Merge in configuration overlay (private config)
134
+ override(loaded_config.get_hash(:config), :config)
135
+
136
+ # Initialize job sequence
137
+ @sequence = CM.sequence({
138
+ :jobs => manifest_jobs,
139
+ :settings => manifest_config
140
+ }, _get(:sequence_provider, :default))
141
+
142
+ yield if block_given?
143
+ end
144
+ success
145
+ end
146
+
147
+ #---
148
+
149
+ def execute(operation, options = {})
150
+ success = true
151
+
152
+ if initialized?
153
+ if ::File.exist?(manifest_path)
154
+ method = "operation_#{operation}"
155
+ success = send(method, options) if respond_to?(method) && load
156
+ success = save if success
157
+ success
158
+ else
159
+ error('manifest_file', { :file => manifest_path })
160
+ success = false
161
+ end
162
+ else
163
+ success = false
164
+ end
165
+ success
166
+ end
167
+
168
+ #---
169
+
170
+ def operation_deploy(options)
171
+ config = Nucleon::Config.ensure(options)
172
+ sequence.forward(config)
173
+ end
174
+
175
+ #---
176
+
177
+ def operation_destroy(options)
178
+ config = Nucleon::Config.ensure(options)
179
+ sequence.reverse(config)
180
+ end
181
+
182
+ #---
183
+
184
+ def save
185
+ save_config(target_path, { :config => manifest_config })
186
+ end
187
+
188
+ #-----------------------------------------------------------------------------
189
+ # Utilities
190
+
191
+ end
192
+ end
193
+ end