corl 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/Gemfile +5 -10
  2. data/Gemfile.lock +13 -11
  3. data/README.rdoc +1 -1
  4. data/Rakefile +3 -3
  5. data/VERSION +1 -1
  6. data/bin/corl +2 -54
  7. data/bootstrap/bootstrap.sh +91 -0
  8. data/bootstrap/lib/shell/LICENSE.txt +674 -0
  9. data/bootstrap/lib/shell/command.sh +214 -0
  10. data/bootstrap/lib/shell/filesystem.sh +139 -0
  11. data/bootstrap/lib/shell/load.sh +73 -0
  12. data/bootstrap/lib/shell/os.sh +67 -0
  13. data/bootstrap/lib/shell/script.sh +160 -0
  14. data/bootstrap/lib/shell/starter.sh +64 -0
  15. data/bootstrap/lib/shell/validators.sh +50 -0
  16. data/bootstrap/os/ubuntu/00_base.sh +5 -0
  17. data/bootstrap/os/ubuntu/01_git.sh +5 -0
  18. data/bootstrap/os/ubuntu/05_ruby.sh +7 -0
  19. data/bootstrap/os/ubuntu/06_puppet.sh +38 -0
  20. data/bootstrap/os/ubuntu/10_corl.sh +9 -0
  21. data/corl.gemspec +61 -124
  22. data/lib/{corl → CORL}/action/bootstrap.rb +13 -7
  23. data/lib/CORL/action/exec.rb +39 -0
  24. data/lib/CORL/action/image.rb +31 -0
  25. data/lib/{corl → CORL}/action/images.rb +1 -1
  26. data/lib/CORL/action/lookup.rb +34 -0
  27. data/lib/{corl → CORL}/action/machines.rb +1 -1
  28. data/lib/CORL/action/provision.rb +31 -0
  29. data/lib/{corl → CORL}/action/seed.rb +3 -3
  30. data/lib/{corl → CORL}/action/spawn.rb +2 -2
  31. data/lib/CORL/action/start.rb +31 -0
  32. data/lib/CORL/action/stop.rb +31 -0
  33. data/lib/{corl → CORL}/configuration/file.rb +1 -1
  34. data/lib/{corl → CORL}/event/puppet.rb +1 -1
  35. data/lib/{corl → CORL}/extension/puppetloader.rb +1 -1
  36. data/lib/{corl → CORL}/machine/fog.rb +3 -3
  37. data/lib/{corl → CORL}/machine/physical.rb +2 -2
  38. data/lib/{corl → CORL}/network/default.rb +1 -1
  39. data/lib/{corl → CORL}/node/aws.rb +0 -4
  40. data/lib/{corl → CORL}/node/google.rb +0 -4
  41. data/lib/{corl → CORL}/node/local.rb +1 -1
  42. data/lib/{corl → CORL}/node/rackspace.rb +0 -4
  43. data/lib/{corl → CORL}/provisioner/puppetnode.rb +1 -14
  44. data/lib/{corl → CORL}/provisioner/puppetnode/resource.rb +0 -0
  45. data/lib/{corl → CORL}/provisioner/puppetnode/resource_group.rb +0 -0
  46. data/lib/{corl → CORL}/template/environment.rb +1 -1
  47. data/lib/core/facade.rb +49 -0
  48. data/lib/{corl_core → core}/mixin/action/keypair.rb +10 -10
  49. data/lib/{corl_core → core}/mixin/lookup.rb +0 -0
  50. data/lib/{corl_core → core}/mod/hiera_backend.rb +0 -0
  51. data/lib/{corl_core/mixin/action/node.rb → core/plugin/action.rb} +66 -33
  52. data/lib/{corl_core → core}/plugin/configuration.rb +2 -2
  53. data/lib/{corl/node → core/plugin}/fog.rb +5 -1
  54. data/lib/{corl_core → core}/plugin/machine.rb +2 -2
  55. data/lib/{corl_core → core}/plugin/network.rb +4 -4
  56. data/lib/{corl_core → core}/plugin/node.rb +11 -9
  57. data/lib/{corl_core → core}/plugin/provisioner.rb +2 -2
  58. data/lib/{corl_core → core}/util/ssh.rb +1 -1
  59. data/lib/corl.rb +53 -112
  60. data/lib/puppet/parser/functions/ensure.rb +0 -4
  61. data/locales/en.yml +55 -148
  62. metadata +84 -222
  63. data/lib/corl/action/add.rb +0 -69
  64. data/lib/corl/action/clone.rb +0 -40
  65. data/lib/corl/action/create.rb +0 -55
  66. data/lib/corl/action/exec.rb +0 -41
  67. data/lib/corl/action/extract.rb +0 -49
  68. data/lib/corl/action/image.rb +0 -30
  69. data/lib/corl/action/lookup.rb +0 -35
  70. data/lib/corl/action/provision.rb +0 -37
  71. data/lib/corl/action/remove.rb +0 -51
  72. data/lib/corl/action/save.rb +0 -53
  73. data/lib/corl/action/start.rb +0 -37
  74. data/lib/corl/action/stop.rb +0 -30
  75. data/lib/corl/action/update.rb +0 -37
  76. data/lib/corl/command/shell.rb +0 -164
  77. data/lib/corl/event/regex.rb +0 -52
  78. data/lib/corl/project/git.rb +0 -465
  79. data/lib/corl/project/github.rb +0 -108
  80. data/lib/corl/template/json.rb +0 -16
  81. data/lib/corl/template/wrapper.rb +0 -16
  82. data/lib/corl/template/yaml.rb +0 -16
  83. data/lib/corl/translator/json.rb +0 -27
  84. data/lib/corl/translator/yaml.rb +0 -27
  85. data/lib/corl_core/codes.rb +0 -107
  86. data/lib/corl_core/config.rb +0 -337
  87. data/lib/corl_core/config/collection.rb +0 -57
  88. data/lib/corl_core/config/options.rb +0 -70
  89. data/lib/corl_core/core.rb +0 -59
  90. data/lib/corl_core/corl.rb +0 -254
  91. data/lib/corl_core/errors.rb +0 -84
  92. data/lib/corl_core/facade.rb +0 -126
  93. data/lib/corl_core/gems.rb +0 -72
  94. data/lib/corl_core/manager.rb +0 -425
  95. data/lib/corl_core/mixin/action/commit.rb +0 -58
  96. data/lib/corl_core/mixin/action/project.rb +0 -53
  97. data/lib/corl_core/mixin/action/push.rb +0 -52
  98. data/lib/corl_core/mixin/config/collection.rb +0 -53
  99. data/lib/corl_core/mixin/config/ops.rb +0 -53
  100. data/lib/corl_core/mixin/config/options.rb +0 -39
  101. data/lib/corl_core/mixin/macro/object_interface.rb +0 -361
  102. data/lib/corl_core/mixin/macro/plugin_interface.rb +0 -380
  103. data/lib/corl_core/mixin/settings.rb +0 -46
  104. data/lib/corl_core/mixin/sub_config.rb +0 -148
  105. data/lib/corl_core/mod/hash.rb +0 -29
  106. data/lib/corl_core/plugin/action.rb +0 -381
  107. data/lib/corl_core/plugin/base.rb +0 -374
  108. data/lib/corl_core/plugin/command.rb +0 -98
  109. data/lib/corl_core/plugin/event.rb +0 -53
  110. data/lib/corl_core/plugin/extension.rb +0 -12
  111. data/lib/corl_core/plugin/project.rb +0 -927
  112. data/lib/corl_core/plugin/template.rb +0 -80
  113. data/lib/corl_core/plugin/translator.rb +0 -38
  114. data/lib/corl_core/util/cli.rb +0 -352
  115. data/lib/corl_core/util/data.rb +0 -404
  116. data/lib/corl_core/util/disk.rb +0 -114
  117. data/lib/corl_core/util/git.rb +0 -47
  118. data/lib/corl_core/util/interface.rb +0 -319
  119. data/lib/corl_core/util/liquid.rb +0 -17
  120. data/lib/corl_core/util/package.rb +0 -93
  121. data/lib/corl_core/util/shell.rb +0 -239
  122. data/spec/corl_core/interface_spec.rb +0 -489
@@ -1,108 +0,0 @@
1
-
2
- corl_require(File.dirname(__FILE__), :git)
3
-
4
- #---
5
-
6
- module CORL
7
- module Project
8
- class Github < Git
9
-
10
- #-----------------------------------------------------------------------------
11
- # Project plugin interface
12
-
13
- def normalize
14
- if reference = delete(:reference, nil)
15
- myself.name = reference
16
- else
17
- if url = get(:url, nil)
18
- myself.name = url
19
- set(:url, myself.class.expand_url(url, get(:ssh, false)))
20
- end
21
- end
22
- super
23
- end
24
-
25
- #---
26
-
27
- def set_connection
28
- require 'octokit'
29
-
30
- @client = Octokit::Client.new :netrc => true
31
- @client.login
32
- end
33
-
34
- #-----------------------------------------------------------------------------
35
- # Property accessor / modifiers
36
-
37
- def client
38
- set_connection unless @client
39
- @client
40
- end
41
-
42
- #-----------------------------------------------------------------------------
43
- # Project operations
44
-
45
- def init_auth
46
- super do
47
- key_id = ENV['USER'] + '@' + lookup(:ipaddress)
48
- ssh_key = public_key_str
49
-
50
- if private_key && ssh_key
51
- begin
52
- deploy_keys = client.deploy_keys(self.name)
53
- github_id = nil
54
- keys_match = true
55
-
56
- deploy_keys.each do |key_resource|
57
- if key_resource.title == key_id
58
- github_id = key_resource.id
59
- keys_match = false if key_resource.key != ssh_key
60
- break
61
- end
62
- end
63
-
64
- if github_id
65
- unless keys_match
66
- client.edit_deploy_key(self.name, github_id, { :key => ssh_key })
67
- verify_key
68
- end
69
- else
70
- client.add_deploy_key(self.name, key_id, ssh_key)
71
- verify_key
72
- end
73
-
74
- rescue Exception => error
75
- logger.error(error.inspect)
76
- logger.error(error.message)
77
- logger.error(Util::Data.to_yaml(error.backtrace))
78
-
79
- ui.error(error.message, { :prefix => false }) if error.message
80
- end
81
- end
82
- end
83
- end
84
-
85
- #-----------------------------------------------------------------------------
86
- # Utilities
87
-
88
- def self.expand_url(path, editable = false)
89
- if editable
90
- protocol = 'git@'
91
- separator = ':'
92
- else
93
- protocol = 'https://'
94
- separator = '/'
95
- end
96
- return "#{protocol}github.com#{separator}" + path + '.git'
97
- end
98
-
99
- #---
100
-
101
- def verify_key
102
- Util::SSH.init_session('github.com', 'git', 22, private_key)
103
- Util::SSH.close('github.com', 'git')
104
- end
105
- protected :verify_key
106
- end
107
- end
108
- end
@@ -1,16 +0,0 @@
1
-
2
- module CORL
3
- module Template
4
- class Json < Plugin::Template
5
-
6
- #-----------------------------------------------------------------------------
7
- # Renderers
8
-
9
- def render_processed(data)
10
- return super do
11
- Util::Data.to_json(data)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
-
2
- module CORL
3
- module Template
4
- class Wrapper < Plugin::Template
5
-
6
- #-----------------------------------------------------------------------------
7
- # Renderers
8
-
9
- def render_processed(data)
10
- return super do
11
- get(:template_prefix, '') + data.to_s + get(:template_suffix, '')
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
-
2
- module CORL
3
- module Template
4
- class Yaml < Plugin::Template
5
-
6
- #-----------------------------------------------------------------------------
7
- # Renderers
8
-
9
- def render_processed(data)
10
- return super do
11
- Util::Data.to_yaml(data)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,27 +0,0 @@
1
-
2
- module CORL
3
- module Translator
4
- class Json < Plugin::Translator
5
-
6
- #-----------------------------------------------------------------------------
7
- # Translator operations
8
-
9
- def parse(json_text)
10
- return super do |properties|
11
- if json_text && ! json_text.empty?
12
- properties = Util::Data.parse_json(json_text)
13
- end
14
- properties
15
- end
16
- end
17
-
18
- #---
19
-
20
- def generate(properties)
21
- return super do
22
- Util::Data.to_json(properties, get(:pretty, true))
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
-
2
- module CORL
3
- module Translator
4
- class Yaml < Plugin::Translator
5
-
6
- #-----------------------------------------------------------------------------
7
- # Translator operations
8
-
9
- def parse(yaml_text)
10
- return super do |properties|
11
- if yaml_text && ! yaml_text.empty?
12
- properties = Util::Data.parse_yaml(yaml_text)
13
- end
14
- properties
15
- end
16
- end
17
-
18
- #---
19
-
20
- def generate(properties)
21
- return super do
22
- Util::Data.to_yaml(properties)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,107 +0,0 @@
1
-
2
- module CORL
3
- class Codes
4
-
5
- #-----------------------------------------------------------------------------
6
- # Code index
7
-
8
- @@registry = {}
9
- @@status_index = {}
10
- @@next_code = 0
11
-
12
- #---
13
-
14
- def self.registry
15
- @@registry
16
- end
17
-
18
- #---
19
-
20
- def self.index(status_code = nil)
21
- if status_code.nil? || ! status_code.integer?
22
- @@status_index
23
- else
24
- status_code = status_code.to_i
25
-
26
- if @@status_index.has_key?(status_code)
27
- @@status_index[status_code]
28
- else
29
- @@status_index[registry[:unknown_status]]
30
- end
31
- end
32
- end
33
-
34
- #---
35
-
36
- def self.render_index(status_code = nil)
37
- output = "Status index:\n"
38
- @@status_index.each do |code, name|
39
- name = name.gsub(/_/, ' ').capitalize
40
-
41
- if ! status_code.nil? && status_code == code
42
- output << sprintf(" [ %3i ] - %s\n", code, name)
43
- else
44
- output << sprintf(" %3i - %s\n", code, name)
45
- end
46
- end
47
- output << "\n"
48
- output
49
- end
50
-
51
- #-----------------------------------------------------------------------------
52
- # Code construction
53
-
54
- def self.code(name)
55
- name = name.to_sym
56
-
57
- unless registry.has_key?(name)
58
- status_code = @@next_code
59
- @@next_code = @@next_code + 1
60
-
61
- # TODO: Add more information to the index (like a help message)
62
- @@registry[name] = status_code
63
- @@status_index[status_code] = name.to_s
64
- end
65
- end
66
-
67
- #---
68
-
69
- def self.codes(*codes)
70
- codes.each do |name|
71
- code(name)
72
- end
73
- end
74
-
75
- #-----------------------------------------------------------------------------
76
- # Return status codes on demand
77
-
78
- def [](name)
79
- name = name.to_sym
80
-
81
- if @@registry.has_key?(name)
82
- @@registry[name]
83
- else
84
- @@registry[:unknown_status]
85
- end
86
- end
87
-
88
- #---
89
-
90
- def method_missing(method, *args, &block)
91
- self[method]
92
- end
93
-
94
- #-----------------------------------------------------------------------------
95
- # Core status codes
96
-
97
- code(:success) # This must be added first (needs to be 0)
98
- code(:help_wanted)
99
- code(:unknown_status)
100
-
101
- code(:action_unprocessed)
102
- code(:batch_error)
103
-
104
- code(:validation_failed)
105
- code(:access_denied)
106
- end
107
- end
@@ -1,337 +0,0 @@
1
-
2
- module CORL
3
- class Config
4
-
5
- #-----------------------------------------------------------------------------
6
- # Global interface
7
-
8
- extend Mixin::ConfigOptions
9
- extend Mixin::ConfigCollection
10
- extend Mixin::Lookup
11
-
12
- #-----------------------------------------------------------------------------
13
- # Instance generators
14
-
15
- def self.ensure(config)
16
- case config
17
- when CORL::Config
18
- return config
19
- when Hash
20
- return new(config)
21
- end
22
- return new
23
- end
24
-
25
- #---
26
-
27
- def self.init(options, contexts = [], hierarchy = [], defaults = {})
28
- contexts = contexts(contexts, hierarchy)
29
- config = new(get_options(contexts), defaults)
30
- config.import(options) unless Util::Data.empty?(options)
31
- return config
32
- end
33
-
34
- #---
35
-
36
- def self.init_flat(options, contexts = [], defaults = {})
37
- return init(options, contexts, [], defaults)
38
- end
39
-
40
- #-----------------------------------------------------------------------------
41
- # Constructor / Destructor
42
-
43
- def initialize(data = {}, defaults = {}, force = true)
44
- @force = force
45
- @properties = {}
46
-
47
- if defaults.is_a?(Hash) && ! defaults.empty?
48
- defaults = symbol_map(defaults)
49
- end
50
-
51
- case data
52
- when CORL::Config
53
- @properties = Util::Data.merge([ defaults, data.export ], force)
54
- when Hash
55
- @properties = {}
56
- if data.is_a?(Hash)
57
- @properties = Util::Data.merge([ defaults, symbol_map(data) ], force)
58
- end
59
- end
60
- end
61
-
62
- #-----------------------------------------------------------------------------
63
- # Checks
64
-
65
- def has_key?(keys)
66
- get(keys) ? true : false
67
- end
68
-
69
- #-----------------------------------------------------------------------------
70
- # Property accessors / modifiers
71
-
72
- def keys
73
- @properties.keys
74
- end
75
-
76
- #---
77
-
78
- def fetch(data, keys, default = nil, format = false)
79
- if keys.is_a?(String) || keys.is_a?(Symbol)
80
- keys = [ keys ]
81
- end
82
- key = keys.shift.to_sym
83
-
84
- if data.has_key?(key)
85
- value = data[key]
86
-
87
- if keys.empty?
88
- return filter(value, format)
89
- else
90
- return fetch(data[key], keys, default, format)
91
- end
92
- end
93
- return filter(default, format)
94
- end
95
- protected :fetch
96
-
97
- #---
98
-
99
- def modify(data, keys, value = nil)
100
- if keys.is_a?(String) || keys.is_a?(Symbol)
101
- keys = [ keys ]
102
- end
103
-
104
- key = keys.shift.to_sym
105
- has_key = data.has_key?(key)
106
- existing = {
107
- :key => key,
108
- :value => ( has_key ? data[key] : nil )
109
- }
110
-
111
- if keys.empty?
112
- existing[:value] = data[key] if has_key
113
-
114
- if value.nil?
115
- data.delete(key) if has_key
116
- else
117
- data[key] = value
118
- end
119
- else
120
- data[key] = {} unless has_key
121
- existing = modify(data[key], keys, value)
122
- end
123
-
124
- return existing
125
- end
126
- protected :modify
127
-
128
- #---
129
-
130
- def get(keys, default = nil, format = false)
131
- return fetch(@properties, array(keys).flatten, default, format)
132
- end
133
-
134
- #---
135
-
136
- def [](name, default = nil, format = false)
137
- get(name, default, format)
138
- end
139
-
140
- #---
141
-
142
- def get_array(keys, default = [])
143
- return get(keys, default, :array)
144
- end
145
-
146
- #---
147
-
148
- def get_hash(keys, default = {})
149
- return get(keys, default, :hash)
150
- end
151
-
152
- #---
153
-
154
- def init(keys, default = nil)
155
- return set(keys, get(keys, default))
156
- end
157
-
158
- #---
159
-
160
- def set(keys, value)
161
- modify(@properties, array(keys).flatten, value)
162
- return self
163
- end
164
-
165
- #---
166
-
167
- def []=(name, value)
168
- set(name, value)
169
- end
170
-
171
- #---
172
-
173
- def delete(keys, default = nil)
174
- existing = modify(@properties, array(keys).flatten, nil)
175
- return existing[:value] if existing[:value]
176
- return default
177
- end
178
-
179
- #---
180
-
181
- def clear
182
- @properties = {}
183
- return self
184
- end
185
-
186
- #-----------------------------------------------------------------------------
187
- # Import / Export
188
-
189
- def import_base(properties, options = {})
190
- config = Config.new(options, { :force => @force }).set(:context, :hash)
191
- import_type = config.get(:import_type, :override)
192
-
193
- properties = properties.export if properties.is_a?(CORL::Config)
194
-
195
- case properties
196
- when Hash
197
- data = [ @properties, symbol_map(properties) ]
198
- data = data.reverse if import_type != :override
199
-
200
- @properties = Util::Data.merge(data, config)
201
-
202
- when String, Symbol
203
- properties = self.class.lookup(properties.to_s, {}, config)
204
-
205
- data = [ @properties, symbol_map(properties) ]
206
- data = data.reverse if import_type != :override
207
-
208
- @properties = Util::Data.merge(data, config)
209
-
210
- when Array
211
- properties.each do |item|
212
- import_base(item, config)
213
- end
214
- end
215
-
216
- return self
217
- end
218
- protected :import_base
219
-
220
- #---
221
-
222
- def import(properties, options = {})
223
- return import_base(properties, options)
224
- end
225
-
226
- #---
227
-
228
- def defaults(defaults, options = {})
229
- config = Config.new(options).set(:import_type, :default)
230
- return import_base(defaults, config)
231
- end
232
-
233
- #---
234
-
235
- def export
236
- return @properties
237
- end
238
-
239
- #-----------------------------------------------------------------------------
240
- # Utilities
241
-
242
- def self.symbol_map(data)
243
- return Util::Data.symbol_map(data)
244
- end
245
-
246
- #---
247
-
248
- def symbol_map(data)
249
- return self.class.symbol_map(data)
250
- end
251
-
252
- #---
253
-
254
- def self.string_map(data)
255
- return Util::Data.string_map(data)
256
- end
257
-
258
- #---
259
-
260
- def string_map(data)
261
- return self.class.string_map(data)
262
- end
263
-
264
- #-----------------------------------------------------------------------------
265
-
266
- def self.filter(data, method = false)
267
- return Util::Data.filter(data, method)
268
- end
269
-
270
- #---
271
-
272
- def filter(data, method = false)
273
- return self.class.filter(data, method)
274
- end
275
-
276
- #-----------------------------------------------------------------------------
277
-
278
- def self.array(data, default = [], split_string = false)
279
- return Util::Data.array(data, default, split_string)
280
- end
281
-
282
- #---
283
-
284
- def array(data, default = [], split_string = false)
285
- return self.class.array(data, default, split_string)
286
- end
287
-
288
- #---
289
-
290
- def self.hash(data, default = {})
291
- data = data.export if data.is_a?(CORL::Config)
292
- return Util::Data.hash(data, default)
293
- end
294
-
295
- #---
296
-
297
- def hash(data, default = {})
298
- return self.class.hash(data, default)
299
- end
300
-
301
- #---
302
-
303
- def self.string(data, default = '')
304
- return Util::Data.string(data, default)
305
- end
306
-
307
- #---
308
-
309
- def string(data, default = '')
310
- return self.class.string(data, default)
311
- end
312
-
313
- #---
314
-
315
- def self.symbol(data, default = :undefined)
316
- return Util::Data.symbol(data, default)
317
- end
318
-
319
- #---
320
-
321
- def symbol(data, default = :undefined)
322
- return self.class.symbol(data, default)
323
- end
324
-
325
- #---
326
-
327
- def self.test(data)
328
- return Util::Data.test(data)
329
- end
330
-
331
- #---
332
-
333
- def test(data)
334
- return self.class.test(data)
335
- end
336
- end
337
- end