corl 0.4.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.
Files changed (132) hide show
  1. data/.document +5 -0
  2. data/.gitmodules +4 -0
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +123 -0
  5. data/LICENSE.txt +674 -0
  6. data/README.rdoc +27 -0
  7. data/Rakefile +78 -0
  8. data/VERSION +1 -0
  9. data/bin/corl +55 -0
  10. data/corl.gemspec +228 -0
  11. data/lib/corl/action/add.rb +69 -0
  12. data/lib/corl/action/bootstrap.rb +83 -0
  13. data/lib/corl/action/clone.rb +40 -0
  14. data/lib/corl/action/create.rb +55 -0
  15. data/lib/corl/action/exec.rb +41 -0
  16. data/lib/corl/action/extract.rb +49 -0
  17. data/lib/corl/action/image.rb +30 -0
  18. data/lib/corl/action/images.rb +55 -0
  19. data/lib/corl/action/lookup.rb +35 -0
  20. data/lib/corl/action/machines.rb +51 -0
  21. data/lib/corl/action/provision.rb +37 -0
  22. data/lib/corl/action/remove.rb +51 -0
  23. data/lib/corl/action/save.rb +53 -0
  24. data/lib/corl/action/seed.rb +115 -0
  25. data/lib/corl/action/spawn.rb +75 -0
  26. data/lib/corl/action/start.rb +37 -0
  27. data/lib/corl/action/stop.rb +30 -0
  28. data/lib/corl/action/update.rb +37 -0
  29. data/lib/corl/command/shell.rb +164 -0
  30. data/lib/corl/configuration/file.rb +386 -0
  31. data/lib/corl/event/puppet.rb +90 -0
  32. data/lib/corl/event/regex.rb +52 -0
  33. data/lib/corl/extension/puppetloader.rb +24 -0
  34. data/lib/corl/machine/fog.rb +310 -0
  35. data/lib/corl/machine/physical.rb +161 -0
  36. data/lib/corl/network/default.rb +26 -0
  37. data/lib/corl/node/aws.rb +90 -0
  38. data/lib/corl/node/fog.rb +198 -0
  39. data/lib/corl/node/google.rb +115 -0
  40. data/lib/corl/node/local.rb +26 -0
  41. data/lib/corl/node/rackspace.rb +89 -0
  42. data/lib/corl/project/git.rb +465 -0
  43. data/lib/corl/project/github.rb +108 -0
  44. data/lib/corl/provisioner/puppetnode/resource.rb +245 -0
  45. data/lib/corl/provisioner/puppetnode/resource_group.rb +205 -0
  46. data/lib/corl/provisioner/puppetnode.rb +407 -0
  47. data/lib/corl/template/environment.rb +73 -0
  48. data/lib/corl/template/json.rb +16 -0
  49. data/lib/corl/template/wrapper.rb +16 -0
  50. data/lib/corl/template/yaml.rb +16 -0
  51. data/lib/corl/translator/json.rb +27 -0
  52. data/lib/corl/translator/yaml.rb +27 -0
  53. data/lib/corl.rb +173 -0
  54. data/lib/corl_core/codes.rb +107 -0
  55. data/lib/corl_core/config/collection.rb +57 -0
  56. data/lib/corl_core/config/options.rb +70 -0
  57. data/lib/corl_core/config.rb +337 -0
  58. data/lib/corl_core/core.rb +59 -0
  59. data/lib/corl_core/corl.rb +254 -0
  60. data/lib/corl_core/errors.rb +84 -0
  61. data/lib/corl_core/facade.rb +126 -0
  62. data/lib/corl_core/gems.rb +72 -0
  63. data/lib/corl_core/manager.rb +425 -0
  64. data/lib/corl_core/mixin/action/commit.rb +58 -0
  65. data/lib/corl_core/mixin/action/keypair.rb +105 -0
  66. data/lib/corl_core/mixin/action/node.rb +129 -0
  67. data/lib/corl_core/mixin/action/project.rb +53 -0
  68. data/lib/corl_core/mixin/action/push.rb +52 -0
  69. data/lib/corl_core/mixin/config/collection.rb +53 -0
  70. data/lib/corl_core/mixin/config/ops.rb +53 -0
  71. data/lib/corl_core/mixin/config/options.rb +39 -0
  72. data/lib/corl_core/mixin/lookup.rb +196 -0
  73. data/lib/corl_core/mixin/macro/object_interface.rb +361 -0
  74. data/lib/corl_core/mixin/macro/plugin_interface.rb +380 -0
  75. data/lib/corl_core/mixin/settings.rb +46 -0
  76. data/lib/corl_core/mixin/sub_config.rb +148 -0
  77. data/lib/corl_core/mod/hash.rb +29 -0
  78. data/lib/corl_core/mod/hiera_backend.rb +63 -0
  79. data/lib/corl_core/plugin/action.rb +381 -0
  80. data/lib/corl_core/plugin/base.rb +374 -0
  81. data/lib/corl_core/plugin/command.rb +98 -0
  82. data/lib/corl_core/plugin/configuration.rb +177 -0
  83. data/lib/corl_core/plugin/event.rb +53 -0
  84. data/lib/corl_core/plugin/extension.rb +12 -0
  85. data/lib/corl_core/plugin/machine.rb +266 -0
  86. data/lib/corl_core/plugin/network.rb +359 -0
  87. data/lib/corl_core/plugin/node.rb +904 -0
  88. data/lib/corl_core/plugin/project.rb +927 -0
  89. data/lib/corl_core/plugin/provisioner.rb +51 -0
  90. data/lib/corl_core/plugin/template.rb +80 -0
  91. data/lib/corl_core/plugin/translator.rb +38 -0
  92. data/lib/corl_core/util/cli.rb +352 -0
  93. data/lib/corl_core/util/data.rb +404 -0
  94. data/lib/corl_core/util/disk.rb +114 -0
  95. data/lib/corl_core/util/git.rb +47 -0
  96. data/lib/corl_core/util/interface.rb +319 -0
  97. data/lib/corl_core/util/liquid.rb +17 -0
  98. data/lib/corl_core/util/package.rb +93 -0
  99. data/lib/corl_core/util/shell.rb +239 -0
  100. data/lib/corl_core/util/ssh.rb +286 -0
  101. data/lib/facter/corl_config_ready.rb +13 -0
  102. data/lib/facter/corl_exists.rb +15 -0
  103. data/lib/facter/corl_network.rb +17 -0
  104. data/lib/hiera/corl_logger.rb +18 -0
  105. data/lib/puppet/indirector/corl.rb +27 -0
  106. data/lib/puppet/indirector/data_binding/corl.rb +6 -0
  107. data/lib/puppet/parser/functions/config_initialized.rb +26 -0
  108. data/lib/puppet/parser/functions/corl_include.rb +44 -0
  109. data/lib/puppet/parser/functions/corl_resources.rb +58 -0
  110. data/lib/puppet/parser/functions/deep_merge.rb +21 -0
  111. data/lib/puppet/parser/functions/ensure.rb +29 -0
  112. data/lib/puppet/parser/functions/file_exists.rb +19 -0
  113. data/lib/puppet/parser/functions/global_array.rb +35 -0
  114. data/lib/puppet/parser/functions/global_hash.rb +35 -0
  115. data/lib/puppet/parser/functions/global_options.rb +23 -0
  116. data/lib/puppet/parser/functions/global_param.rb +43 -0
  117. data/lib/puppet/parser/functions/interpolate.rb +26 -0
  118. data/lib/puppet/parser/functions/is_false.rb +21 -0
  119. data/lib/puppet/parser/functions/is_true.rb +21 -0
  120. data/lib/puppet/parser/functions/module_array.rb +38 -0
  121. data/lib/puppet/parser/functions/module_hash.rb +38 -0
  122. data/lib/puppet/parser/functions/module_options.rb +23 -0
  123. data/lib/puppet/parser/functions/module_param.rb +48 -0
  124. data/lib/puppet/parser/functions/name.rb +21 -0
  125. data/lib/puppet/parser/functions/render.rb +33 -0
  126. data/lib/puppet/parser/functions/value.rb +21 -0
  127. data/locales/en.yml +232 -0
  128. data/spec/corl_core/interface_spec.rb +489 -0
  129. data/spec/corl_mock_input.rb +29 -0
  130. data/spec/corl_test_kernel.rb +22 -0
  131. data/spec/spec_helper.rb +15 -0
  132. metadata +406 -0
data/lib/corl.rb ADDED
@@ -0,0 +1,173 @@
1
+
2
+ #*******************************************************************************
3
+ # CORL Core Library
4
+ #
5
+ # This provides core data elements and utilities used in the CORL gems.
6
+ #
7
+ # Author:: Adrian Webb (mailto:adrian.webb@coralnexus.com)
8
+ # License:: GPLv3
9
+
10
+ #-------------------------------------------------------------------------------
11
+ # Global namespace
12
+
13
+ module Kernel
14
+
15
+ def dbg(data, label = '')
16
+ # Invocations of this function should NOT be committed to the project
17
+ require 'pp'
18
+
19
+ puts '>>----------------------'
20
+ unless label.empty?
21
+ puts label
22
+ puts '---'
23
+ end
24
+ pp data
25
+ puts '<<'
26
+ end
27
+
28
+ #---
29
+
30
+ def corl_locate(command)
31
+ command = command.to_s
32
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
33
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
34
+ exts.each do |ext|
35
+ exe = File.join(path, "#{command}#{ext}")
36
+ return exe if File.executable?(exe)
37
+ end
38
+ end
39
+ return nil
40
+ end
41
+
42
+ #---
43
+
44
+ def corl_require(base_dir, name)
45
+ name = name.to_s
46
+ top_level_file = File.join(base_dir, "#{name}.rb")
47
+
48
+ require top_level_file if File.exists?(top_level_file)
49
+
50
+ directory = File.join(base_dir, name)
51
+
52
+ if File.directory?(directory)
53
+ Dir.glob(File.join(directory, '**', '*.rb')).each do |sub_file|
54
+ require sub_file
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ #-------------------------------------------------------------------------------
61
+ # Top level properties
62
+
63
+ lib_dir = File.dirname(__FILE__)
64
+ core_dir = File.join(lib_dir, 'corl_core')
65
+ mixin_dir = File.join(core_dir, 'mixin')
66
+ mixin_config_dir = File.join(mixin_dir, 'config')
67
+ mixin_action_dir = File.join(mixin_dir, 'action')
68
+ macro_dir = File.join(mixin_dir, 'macro')
69
+ util_dir = File.join(core_dir, 'util')
70
+ mod_dir = File.join(core_dir, 'mod')
71
+ plugin_dir = File.join(core_dir, 'plugin')
72
+
73
+ #-------------------------------------------------------------------------------
74
+ # CORL requirements
75
+
76
+ git_location = corl_locate('git')
77
+
78
+ $:.unshift(lib_dir) unless $:.include?(lib_dir) || $:.include?(File.expand_path(lib_dir))
79
+
80
+ #---
81
+
82
+ require 'rubygems'
83
+
84
+ require 'pp'
85
+ require 'i18n'
86
+ require 'log4r'
87
+ require 'log4r/configurator'
88
+ require 'base64'
89
+ require 'sshkey'
90
+ require 'deep_merge'
91
+ require 'hiera'
92
+ require 'facter'
93
+ require 'yaml'
94
+ require 'multi_json'
95
+ require 'digest/sha1'
96
+ require 'optparse'
97
+ require 'thread' # Eventually depreciated
98
+ require 'celluloid'
99
+ require 'celluloid/autostart'
100
+ require 'tmpdir'
101
+
102
+ #---
103
+
104
+ # TODO: Make this dynamically settable
105
+
106
+ I18n.enforce_available_locales = false
107
+ I18n.load_path << File.expand_path(File.join('..', 'locales', 'en.yml'), lib_dir)
108
+
109
+ #---
110
+
111
+ if git_location
112
+ require 'grit'
113
+ corl_require(util_dir, :git)
114
+ end
115
+
116
+ #---
117
+
118
+ # Object modifications (100% pure monkey patches)
119
+ Dir.glob(File.join(mod_dir, '*.rb')).each do |file|
120
+ require file
121
+ end
122
+
123
+ #---
124
+
125
+ # Mixins for classes
126
+ Dir.glob(File.join(mixin_dir, '*.rb')).each do |file|
127
+ require file
128
+ end
129
+ Dir.glob(File.join(mixin_config_dir, '*.rb')).each do |file|
130
+ require file
131
+ end
132
+ Dir.glob(File.join(mixin_action_dir, '*.rb')).each do |file|
133
+ require file
134
+ end
135
+ Dir.glob(File.join(macro_dir, '*.rb')).each do |file|
136
+ require file
137
+ end
138
+
139
+ #---
140
+
141
+ # Include bootstrap classes
142
+ corl_require(core_dir, :errors)
143
+ corl_require(core_dir, :codes)
144
+ corl_require(util_dir, :data)
145
+ corl_require(core_dir, :config)
146
+ corl_require(util_dir, :interface)
147
+ corl_require(core_dir, :core)
148
+
149
+ #---
150
+
151
+ # Include core utilities
152
+ [ :liquid,
153
+ :cli,
154
+ :disk,
155
+ :package,
156
+ :shell,
157
+ :ssh
158
+ ].each do |name|
159
+ corl_require(util_dir, name)
160
+ end
161
+
162
+ # Include core systems
163
+ corl_require(core_dir, :corl)
164
+ corl_require(core_dir, :gems)
165
+ corl_require(core_dir, :manager)
166
+ corl_require(plugin_dir, :base)
167
+ corl_require(core_dir, :plugin)
168
+ corl_require(core_dir, :facade)
169
+
170
+ #-------------------------------------------------------------------------------
171
+ # CORL initialization
172
+
173
+ CORL.initialize
@@ -0,0 +1,107 @@
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
@@ -0,0 +1,57 @@
1
+
2
+ module CORL
3
+ class Config
4
+ class Collection
5
+
6
+ #-----------------------------------------------------------------------------
7
+ # Property accessor / modifiers
8
+
9
+ @@properties = {}
10
+
11
+ #---
12
+
13
+ def self.all
14
+ return @@properties
15
+ end
16
+
17
+ #---
18
+
19
+ def self.get(name)
20
+ return @@properties[name.to_sym]
21
+ end
22
+
23
+ #---
24
+
25
+ def self.set(name, value)
26
+ @@properties[name.to_sym] = value
27
+ end
28
+
29
+ #---
30
+
31
+ def self.delete(name)
32
+ @@properties.delete(name.to_sym)
33
+ end
34
+
35
+ #---
36
+
37
+ def self.clear
38
+ @@properties = {}
39
+ end
40
+
41
+ #---
42
+
43
+ def self.save
44
+ log_options = Options.get(:corl_log)
45
+
46
+ unless Util::Data.empty?(log_options[:config_log])
47
+ config_log = log_options[:config_log]
48
+
49
+ if log_options[:config_store]
50
+ Util::Disk.write(config_log, MultiJson.dump(@@properties, :pretty => true))
51
+ Util::Disk.close(config_log)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,70 @@
1
+
2
+ module CORL
3
+ class Config
4
+ class Options
5
+
6
+ #-----------------------------------------------------------------------------
7
+ # Property accessors / modifiers
8
+
9
+ @@options = {}
10
+
11
+ #---
12
+
13
+ def self.contexts(contexts = [], hierarchy = [])
14
+ contexts = [ 'all', contexts ].flatten
15
+
16
+ unless hierarchy.is_a?(Array)
17
+ hierarchy = ( ! Util::Data.empty?(hierarchy) ? [ hierarchy ].flatten : [] )
18
+ end
19
+
20
+ hierarchy.each do |group|
21
+ group_contexts = Util::Data.prefix(group, contexts)
22
+ contexts = [ contexts, group_contexts ].flatten
23
+ end
24
+
25
+ return contexts
26
+ end
27
+
28
+ #---
29
+
30
+ def self.get(contexts, force = true)
31
+ options = {}
32
+
33
+ unless contexts.is_a?(Array)
34
+ contexts = ( ! Util::Data.empty?(contexts) ? [ contexts ].flatten : [] )
35
+ end
36
+ contexts.each do |name|
37
+ name = name.to_sym
38
+ if @@options.has_key?(name)
39
+ options = Util::Data.merge([ options, @@options[name] ], force)
40
+ end
41
+ end
42
+ return options
43
+ end
44
+
45
+ #---
46
+
47
+ def self.set(contexts, options, force = true)
48
+ unless contexts.is_a?(Array)
49
+ contexts = ( ! Util::Data.empty?(contexts) ? [ contexts ].flatten : [] )
50
+ end
51
+ contexts.each do |name|
52
+ name = name.to_sym
53
+ current_options = ( @@options.has_key?(name) ? @@options[name] : {} )
54
+ @@options[name] = Util::Data.merge([ current_options, Config.symbol_map(options) ], force)
55
+ end
56
+ end
57
+
58
+ #---
59
+
60
+ def self.clear(contexts)
61
+ unless contexts.is_a?(Array)
62
+ contexts = [ contexts ]
63
+ end
64
+ contexts.each do |name|
65
+ @@options.delete(name.to_sym)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end