coral_core 0.2.26 → 0.2.30

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.
Files changed (46) hide show
  1. data/Gemfile +7 -2
  2. data/Gemfile.lock +84 -15
  3. data/VERSION +1 -1
  4. data/coral_core.gemspec +51 -16
  5. data/lib/{coral_core/command.rb → coral/command/shell.rb} +12 -116
  6. data/lib/coral/machine/fog.rb +215 -0
  7. data/lib/coral/network/default.rb +26 -0
  8. data/lib/coral/node/rackspace.rb +23 -0
  9. data/lib/coral_core.rb +249 -134
  10. data/lib/coral_core/config.rb +233 -275
  11. data/lib/coral_core/config/collection.rb +57 -0
  12. data/lib/coral_core/config/options.rb +70 -0
  13. data/lib/coral_core/config/project.rb +225 -0
  14. data/lib/coral_core/core.rb +19 -173
  15. data/lib/coral_core/event/puppet_event.rb +98 -0
  16. data/lib/coral_core/mixin/config_collection.rb +52 -0
  17. data/lib/coral_core/mixin/config_ops.rb +51 -0
  18. data/lib/coral_core/mixin/config_options.rb +38 -0
  19. data/lib/coral_core/mixin/lookup.rb +211 -0
  20. data/lib/coral_core/mixin/macro/object_interface.rb +292 -0
  21. data/lib/coral_core/mixin/macro/plugin_interface.rb +277 -0
  22. data/lib/coral_core/mixin/settings.rb +46 -0
  23. data/lib/coral_core/mixin/sub_config.rb +208 -0
  24. data/lib/coral_core/mod/hash.rb +29 -0
  25. data/lib/{hiera_backend.rb → coral_core/mod/hiera_backend.rb} +0 -0
  26. data/lib/coral_core/plugin.rb +261 -0
  27. data/lib/coral_core/plugin/command.rb +95 -0
  28. data/lib/coral_core/plugin/machine.rb +152 -0
  29. data/lib/coral_core/plugin/network.rb +24 -0
  30. data/lib/coral_core/plugin/node.rb +184 -0
  31. data/lib/coral_core/plugin_base.rb +147 -0
  32. data/lib/coral_core/repository.rb +471 -82
  33. data/lib/coral_core/util/cli.rb +293 -0
  34. data/lib/coral_core/util/data.rb +178 -8
  35. data/lib/coral_core/util/disk.rb +13 -0
  36. data/lib/coral_core/util/git.rb +35 -10
  37. data/lib/coral_core/{interface.rb → util/interface.rb} +31 -21
  38. data/lib/coral_core/util/process.rb +43 -0
  39. data/locales/en.yml +8 -0
  40. data/spec/coral_core/interface_spec.rb +45 -45
  41. metadata +109 -34
  42. data/.gitmodules +0 -12
  43. data/lib/coral_core/memory.rb +0 -226
  44. data/lib/coral_core/util/git/base.rb +0 -65
  45. data/lib/coral_core/util/git/lib.rb +0 -89
  46. data/lib/coral_core/util/git/remote.rb +0 -12
@@ -0,0 +1,98 @@
1
+ module Coral
2
+ class PuppetEvent < Event
3
+
4
+ #-----------------------------------------------------------------------------
5
+ # Properties
6
+
7
+ TYPE = :puppet
8
+
9
+ #-----------------------------------------------------------------------------
10
+ # Constructor / Destructor
11
+
12
+ def initialize(options = {})
13
+ options[:type] = TYPE
14
+
15
+ super(options)
16
+
17
+ if options.has_key?(:string)
18
+ items = options[:string].split(':')
19
+ self.element = items[0]
20
+ self.operation = items[1]
21
+ self.message = items[2]
22
+ end
23
+ end
24
+
25
+ #-----------------------------------------------------------------------------
26
+ # Property accessors / modifiers
27
+
28
+ def element
29
+ return property(:element, '', :string)
30
+ end
31
+
32
+ #---
33
+
34
+ def element=element
35
+ set_property(:element, string(element))
36
+ end
37
+
38
+ #---
39
+
40
+ def operation
41
+ return property(:operation, '', :string)
42
+ end
43
+
44
+ #---
45
+
46
+ def operation=operation
47
+ set_property(:operation, string(operation))
48
+ end
49
+
50
+ #--
51
+
52
+ def message
53
+ return property(:message, '', :string)
54
+ end
55
+
56
+ #---
57
+
58
+ def message=message
59
+ set_property(:message, string(message))
60
+ end
61
+
62
+ #-----------------------------------------------------------------------------
63
+ # Import / Export
64
+
65
+ def export
66
+ return "#{type}:#{element}:#{operation}:#{message}"
67
+ end
68
+
69
+ #-----------------------------------------------------------------------------
70
+ # Event handling
71
+
72
+ def check(source)
73
+ if source.match(/notice:\s+(.+?):\s+(.+)\s*/i)
74
+ source_element = $1
75
+ source_operation = ''
76
+ source_message = $2
77
+
78
+ source_elements = source_element.split('/')
79
+ source_operation = source_elements.pop.strip unless source_elements.last.match(/[\[\]]/)
80
+
81
+ if source_operation
82
+ source_element = source_elements.join('/').strip
83
+
84
+ logger.debug("#{source_element} includes: #{element} -- " + ( source_element.include?(element) ? 'true' : 'false' ))
85
+ logger.debug("#{source_operation} is: #{operation} -- " + ( source_operation == operation ? 'true' : 'false' ))
86
+ logger.debug("#{source_message} includes: #{message} -- " + ( source_message.include?(message) ? 'true' : 'false' ))
87
+
88
+ if source_element.include?(element) && source_operation == operation && source_message.include?(message)
89
+ logger.debug("MATCH! -> #{element} - #{operation} - #{message}")
90
+ return true
91
+ end
92
+ end
93
+ end
94
+ logger.debug("nothing -> #{element} - #{operation} - #{message}")
95
+ return false
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,52 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::ConfigCollection
5
+ #
6
+
7
+ module Coral
8
+ module Mixin
9
+ module ConfigCollection
10
+ #-----------------------------------------------------------------------------
11
+ # Configuration collection interface
12
+
13
+ def all_properties
14
+ return Config::Collection.all
15
+ end
16
+
17
+ #---
18
+
19
+ def get_property(name)
20
+ return Config::Collection.get(name)
21
+ end
22
+
23
+ #---
24
+
25
+ def set_property(name, value)
26
+ Config::Collection.set(name, value)
27
+ return self
28
+ end
29
+
30
+ #---
31
+
32
+ def delete_property(name)
33
+ Config::Collection.delete(name)
34
+ return self
35
+ end
36
+
37
+ #---
38
+
39
+ def clear_properties
40
+ Config::Collection.clear
41
+ return self
42
+ end
43
+
44
+ #---
45
+
46
+ def save_properties
47
+ Config::Collection.save
48
+ return self
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,51 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::ConfigOps
5
+ #
6
+
7
+ module Coral
8
+ module Mixin
9
+ module ConfigOps
10
+ #-----------------------------------------------------------------------------
11
+ # Parsing
12
+
13
+ def parse(statement, options = {})
14
+ config = Config.ensure(options)
15
+
16
+ # statement = 'common->php::apache::memory_limit = 32M'
17
+ # statement = 'identity -> test -> users::user[admin][shell]'
18
+ # statement = 'servers->development->dev.loc->facts[server_environment]=vagrant'
19
+ # statement = 'cloud->settings[debug][puppet][options] = ["--debug"]'
20
+
21
+ reference, new_value = statement.split(/\=/)
22
+ new_value = new_value.join('=').strip if new_value && new_value.is_a?(Array)
23
+
24
+ config_elements = reference.gsub(/\s+/, '').split(/\-\>/)
25
+ property = config_elements.pop
26
+ config_file = config_elements.pop
27
+
28
+ if config_directory = config.get(:directory, nil)
29
+ config_path = File.join(repo.directory, config_directory, *config_elements)
30
+ else
31
+ config_path = File.join(repo.directory, *config_elements)
32
+ end
33
+
34
+ return nil unless property && config_file
35
+
36
+ config_file = "#{config_file}." + config.get(:ext, 'json')
37
+ property = property.gsub(/\]$/, '').split(/\]?\[/)
38
+ data = open(config_path, config_file, config)
39
+
40
+ return {
41
+ :path => config_path,
42
+ :file => config_file,
43
+ :property => property,
44
+ :conf => data,
45
+ :current_value => (data ? data.get(property) : nil),
46
+ :new_value => eval(new_value)
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::ConfigOptions
5
+ #
6
+
7
+ module Coral
8
+ module Mixin
9
+ module ConfigOptions
10
+ #-----------------------------------------------------------------------------
11
+ # Configuration options interface
12
+
13
+ def contexts(contexts = [], hierarchy = [])
14
+ return Config::Options.contexts(contexts, hierarchy)
15
+ end
16
+
17
+ #---
18
+
19
+ def get_options(contexts, force = true)
20
+ return Config::Options.get(contexts, force)
21
+ end
22
+
23
+ #---
24
+
25
+ def set_options(contexts, options, force = true)
26
+ Config::Options.set(contexts, options, force)
27
+ return self
28
+ end
29
+
30
+ #---
31
+
32
+ def clear_options(contexts)
33
+ Config::Options.clear(contexts)
34
+ return self
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,211 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::Lookup
5
+ #
6
+
7
+ module Coral
8
+ module Mixin
9
+ module Lookup
10
+ #-----------------------------------------------------------------------------
11
+ # Hiera configuration
12
+
13
+ @@hiera = nil
14
+
15
+ #---
16
+
17
+ def hiera_config
18
+ config_file = Puppet.settings[:hiera_config]
19
+ config = {}
20
+
21
+ if File.exist?(config_file)
22
+ config = Hiera::Config.load(config_file)
23
+ else
24
+ ui.warn("Config file #{config_file} not found, using Hiera defaults")
25
+ end
26
+
27
+ config[:logger] = 'puppet'
28
+ return config
29
+ end
30
+
31
+ #---
32
+
33
+ def hiera
34
+ @@hiera = Hiera.new(:config => hiera_config) unless @@hiera
35
+ return @@hiera
36
+ end
37
+
38
+ #-----------------------------------------------------------------------------
39
+ # Configuration lookup interface
40
+
41
+ def initialized?(options = {})
42
+ config = Config.ensure(options)
43
+
44
+ begin
45
+ require 'hiera'
46
+ puppet_scope = config.get(:puppet_scope, scope)
47
+
48
+ prefix_text = config.get(:prefix_text, '::')
49
+ init_fact = prefix_text + config.get(:init_fact, 'hiera_ready')
50
+
51
+ if Puppet::Parser::Functions.function('hiera') && puppet_scope.respond_to?('[]')
52
+ return true if Util::Data.true?(puppet_scope[init_fact])
53
+ end
54
+ return false
55
+
56
+ rescue Exception # Prevent abortions.
57
+ end
58
+ return false
59
+ end
60
+
61
+ #---
62
+
63
+ def lookup(properties, default = nil, options = {})
64
+ config = Config.ensure(options)
65
+ value = nil
66
+
67
+ hiera_scope = config.get(:hiera_scope, {})
68
+ context = config.get(:context, :priority)
69
+ override = config.get(:override, nil)
70
+
71
+ puppet_scope = config.get(:puppet_scope, scope)
72
+
73
+ base_names = config.get(:search, nil)
74
+
75
+ search_name = config.get(:search_name, true)
76
+ reverse_lookup = config.get(:reverse_lookup, true)
77
+
78
+ return_property = config.get(:return_property, false)
79
+
80
+ unless properties.is_a?(Array)
81
+ properties = [ properties ].flatten
82
+ end
83
+
84
+ first_property = nil
85
+ properties.each do |property|
86
+ first_property = property unless first_property
87
+
88
+ if initialized?(config)
89
+ unless hiera_scope.respond_to?('[]')
90
+ hiera_scope = Hiera::Scope.new(hiera_scope)
91
+ end
92
+ value = hiera.lookup(property, nil, hiera_scope, override, context)
93
+ end
94
+
95
+ if Util::Data.undef?(value)
96
+ log_level = Puppet::Util::Log.level
97
+ Puppet::Util::Log.level = :err # Don't want failed parameter lookup warnings here.
98
+
99
+ if base_names
100
+ if base_names.is_a?(String)
101
+ base_names = [ base_names ]
102
+ end
103
+ base_names = base_names.reverse if reverse_lookup
104
+
105
+ base_names.each do |base|
106
+ value = puppet_scope.lookupvar("::#{base}::#{property}")
107
+ break unless Util::Data.undef?(value)
108
+ end
109
+ end
110
+ if Util::Data.undef?(value) && search_name
111
+ value = puppet_scope.lookupvar("::#{property}")
112
+ end
113
+ Puppet::Util::Log.level = log_level
114
+ end
115
+ end
116
+ value = default if Util::Data.undef?(value)
117
+ value = Util::Data.value(value)
118
+
119
+ if ! @@properties.has_key?(first_property) || ! Util::Data.undef?(value)
120
+ Config::Collection.set(first_property, value)
121
+ end
122
+ return value, first_property if return_property
123
+ return value
124
+ end
125
+
126
+ #---
127
+
128
+ def lookup_array(properties, default = [], options = {})
129
+ config = Config.ensure(options)
130
+ value, property = lookup(properties, nil, config.import({ :return_property => true }))
131
+
132
+ if Util::Data.undef?(value)
133
+ value = default
134
+
135
+ elsif ! Util::Data.empty?(default)
136
+ if config.get(:merge, false)
137
+ value = Util::Data.merge([default, value], config)
138
+ end
139
+ end
140
+
141
+ unless value.is_a?(Array)
142
+ value = ( Util::Data.empty?(value) ? [] : [ value ] )
143
+ end
144
+
145
+ Config::Collection.set(property, value)
146
+ return value
147
+ end
148
+
149
+ #---
150
+
151
+ def lookup_hash(properties, default = {}, options = {})
152
+ config = Config.ensure(options)
153
+ value, property = lookup(properties, nil, config.import({ :return_property => true }))
154
+
155
+ if Util::Data.undef?(value)
156
+ value = default
157
+
158
+ elsif ! Util::Data.empty?(default)
159
+ if config.get(:merge, false)
160
+ value = Util::Data.merge([default, value], config)
161
+ end
162
+ end
163
+
164
+ unless value.is_a?(Hash)
165
+ value = ( Util::Data.empty?(value) ? {} : { :value => value } )
166
+ end
167
+
168
+ Config::Collection.set(property, value)
169
+ return value
170
+ end
171
+
172
+ #---
173
+
174
+ def normalize(data, override = nil, options = {})
175
+ config = Config.ensure(options)
176
+ results = {}
177
+
178
+ unless Util::Data.undef?(override)
179
+ case data
180
+ when String, Symbol
181
+ data = [ data, override ] if data != override
182
+ when Array
183
+ data << override unless data.include?(override)
184
+ when Hash
185
+ data = [ data, override ]
186
+ end
187
+ end
188
+
189
+ case data
190
+ when String, Symbol
191
+ results = lookup(data.to_s, {}, config)
192
+
193
+ when Array
194
+ data.each do |item|
195
+ if item.is_a?(String) || item.is_a?(Symbol)
196
+ item = lookup(item.to_s, {}, config)
197
+ end
198
+ unless Util::Data.undef?(item)
199
+ results = Util::Data.merge([ results, item ], config)
200
+ end
201
+ end
202
+
203
+ when Hash
204
+ results = data
205
+ end
206
+
207
+ return results
208
+ end
209
+ end
210
+ end
211
+ end