corl 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Gemfile.lock +1 -1
  2. data/VERSION +1 -1
  3. data/corl.gemspec +12 -7
  4. data/lib/CORL/action/build.rb +30 -0
  5. data/lib/CORL/action/provision.rb +34 -8
  6. data/lib/CORL/configuration/file.rb +50 -64
  7. data/lib/CORL/provisioner/puppetnode.rb +186 -314
  8. data/lib/core/mixin/lookup.rb +20 -15
  9. data/lib/core/mixin/macro/network_settings.rb +52 -0
  10. data/lib/core/plugin/action.rb +1 -1
  11. data/lib/core/plugin/configuration.rb +43 -4
  12. data/lib/core/plugin/network.rb +16 -3
  13. data/lib/core/plugin/node.rb +69 -2
  14. data/lib/core/plugin/provisioner.rb +286 -11
  15. data/lib/{CORL/provisioner/puppetnode → core/util/puppet}/resource.rb +36 -40
  16. data/lib/{CORL/provisioner/puppetnode → core/util/puppet}/resource_group.rb +33 -41
  17. data/lib/core/util/puppet.rb +303 -0
  18. data/lib/corl.rb +34 -11
  19. data/lib/facter/corl_build.rb +8 -0
  20. data/lib/facter/corl_exists.rb +3 -3
  21. data/lib/facter/corl_network.rb +1 -1
  22. data/lib/facter/custom_facts.rb +24 -0
  23. data/lib/facter/vagrant_exists.rb +15 -0
  24. data/lib/hiera/corl_logger.rb +1 -1
  25. data/lib/puppet/indirector/corl.rb +2 -2
  26. data/lib/puppet/parser/functions/corl_include.rb +10 -14
  27. data/lib/puppet/parser/functions/corl_initialize.rb +15 -0
  28. data/lib/puppet/parser/functions/{deep_merge.rb → corl_merge.rb} +4 -4
  29. data/lib/puppet/parser/functions/corl_resources.rb +9 -4
  30. data/lib/puppet/parser/functions/global_array.rb +1 -1
  31. data/lib/puppet/parser/functions/global_hash.rb +1 -1
  32. data/lib/puppet/parser/functions/global_param.rb +1 -1
  33. data/lib/puppet/parser/functions/interpolate.rb +1 -1
  34. data/lib/puppet/parser/functions/module_array.rb +8 -9
  35. data/lib/puppet/parser/functions/module_hash.rb +7 -8
  36. data/lib/puppet/parser/functions/module_param.rb +4 -5
  37. data/lib/puppet/parser/functions/name.rb +1 -1
  38. data/lib/puppet/parser/functions/render.rb +5 -5
  39. metadata +34 -29
  40. data/lib/CORL/extension/puppetloader.rb +0 -24
  41. data/lib/puppet/parser/functions/config_initialized.rb +0 -26
data/lib/corl.rb CHANGED
@@ -17,6 +17,7 @@ lib_dir = File.dirname(__FILE__)
17
17
  core_dir = File.join(lib_dir, 'core')
18
18
  mixin_dir = File.join(core_dir, 'mixin')
19
19
  mixin_action_dir = File.join(mixin_dir, 'action')
20
+ macro_dir = File.join(mixin_dir, 'macro')
20
21
  util_dir = File.join(core_dir, 'util')
21
22
  mod_dir = File.join(core_dir, 'mod')
22
23
 
@@ -34,15 +35,19 @@ CORL = Nucleon
34
35
 
35
36
  require 'hiera'
36
37
  require 'facter'
38
+ require 'puppet'
39
+ require 'puppet/configurer'
37
40
 
38
- #---
41
+ #-------------------------------------------------------------------------------
42
+ # Localization
39
43
 
40
44
  # TODO: Make this dynamically settable
41
45
 
42
46
  I18n.enforce_available_locales = false
43
47
  I18n.load_path << File.expand_path(File.join('..', 'locales', 'en.yml'), lib_dir)
44
48
 
45
- #---
49
+ #-------------------------------------------------------------------------------
50
+ # Include CORL libraries
46
51
 
47
52
  # Mixins for classes
48
53
  Dir.glob(File.join(mixin_dir, '*.rb')).each do |file|
@@ -51,17 +56,41 @@ end
51
56
  Dir.glob(File.join(mixin_action_dir, '*.rb')).each do |file|
52
57
  require file
53
58
  end
59
+ Dir.glob(File.join(macro_dir, '*.rb')).each do |file|
60
+ require file
61
+ end
54
62
 
55
63
  #---
56
64
 
57
65
  # Include CORL utilities
58
- #[].each do |name|
59
- # nucleon_require(util_dir, name)
60
- #end
66
+ [ :puppet ].each do |name|
67
+ nucleon_require(util_dir, name)
68
+ end
61
69
 
62
70
  # Special errors
63
71
  nucleon_require(core_dir, :errors)
64
72
 
73
+ #-------------------------------------------------------------------------------
74
+ # Class and module additions / updates
75
+
76
+ module Nucleon
77
+ class Config
78
+ extend Mixin::Lookup
79
+ include Mixin::Lookup
80
+ end
81
+
82
+ #---
83
+
84
+ module Plugin
85
+ class Base
86
+ extend Mixin::Macro::NetworkSettings
87
+ end
88
+ end
89
+ end
90
+
91
+ #-------------------------------------------------------------------------------
92
+ # Include CORL plugins
93
+
65
94
  # Include facade
66
95
  nucleon_require(core_dir, :facade)
67
96
 
@@ -77,12 +106,6 @@ module CORL
77
106
  File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
78
107
  end
79
108
 
80
- #-----------------------------------------------------------------------------
81
-
82
- class Config
83
- include Mixin::Lookup
84
- end
85
-
86
109
  #-----------------------------------------------------------------------------
87
110
  # CORL initialization
88
111
 
@@ -0,0 +1,8 @@
1
+
2
+ Facter.add(:corl_build) do
3
+ confine :kernel => :linux # TODO: Extend this to work with more systems
4
+
5
+ setcode do
6
+ File.join(Facter.value('corl_network'), 'build')
7
+ end
8
+ end
@@ -3,13 +3,13 @@ Facter.add(:corl_exists) do
3
3
  confine :kernel => :linux
4
4
 
5
5
  setcode do
6
+ corl_exists = nil
6
7
  begin
7
8
  Facter::Util::Resolution::exec('gem list corl -i 2> /dev/null')
8
9
  corl_exists = true if $?.exitstatus == 0
9
10
 
10
11
  rescue Exception # Prevent abortions.
11
- end
12
-
13
- corl_exists ? true : nil
12
+ end
13
+ corl_exists
14
14
  end
15
15
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  Facter.add(:corl_network) do
3
- confine :kernel => :linux
3
+ confine :kernel => :linux # TODO: Extend this to work with more systems
4
4
 
5
5
  setcode do
6
6
  require 'corl'
@@ -0,0 +1,24 @@
1
+
2
+ begin
3
+ require 'corl'
4
+
5
+ # Load network if it exists
6
+ if CORL.admin?
7
+ network_path = Facter.value("corl_network")
8
+ network_config = CORL.config(:network, { :directory => network_path, :name => network_path })
9
+ network = CORL.network(CORL.sha1(network_config), network_config, :default)
10
+
11
+ if network && node = network.local_node
12
+ CORL::Util::Data.hash(node[:facts]).each do |name, value|
13
+ Facter.add(name) do
14
+ confine :kernel => :linux # TODO: Extend this to work with more systems
15
+
16
+ setcode do
17
+ value
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ rescue # Prevent abortions if does not exist
24
+ end
@@ -0,0 +1,15 @@
1
+
2
+ Facter.add(:vagrant_exists) do
3
+ confine :kernel => :linux
4
+
5
+ setcode do
6
+ vagrant_exists = nil
7
+ begin
8
+ Facter::Util::Resolution::exec('id vagrant 2> /dev/null')
9
+ vagrant_exists = true if $?.exitstatus == 0
10
+
11
+ rescue Exception # Prevent abortions.
12
+ end
13
+ vagrant_exists
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
 
2
2
  class Hiera
3
- module CORL_logger
3
+ module Corl_logger
4
4
  class << self
5
5
  def suitable?
6
6
  defined?(::CORL) == "constant"
@@ -13,12 +13,12 @@ class Puppet::Indirector::CORL < Puppet::Indirector::Terminus
13
13
  #---
14
14
 
15
15
  def find(request)
16
- config = CORL::Config.init({}, [ :all, :param, :data_binding ], {
16
+ config = CORL::Config.init_flat({}, [ :param, :data_binding ], {
17
+ :provisioner => :puppetnode,
17
18
  :hiera_scope => request.options[:variables],
18
19
  :puppet_scope => request.options[:variables],
19
20
  :search => 'core::default',
20
21
  :search_name => false,
21
- :init_fact => 'corl_config_ready',
22
22
  :force => true,
23
23
  :merge => true
24
24
  })
@@ -25,20 +25,16 @@ If no value is found in the defined sources, it does not include any classes.
25
25
 
26
26
  var_name = args[0]
27
27
  parameters = ( args.size > 1 ? args[1] : {} )
28
- options = ( args.size > 2 ? args[2] : {} )
29
-
30
- unless CORL.provisioner(:puppet).include(var_name, parameters, options)
31
- # Throw an error if we didn't evaluate all of the classes.
32
- str = "Could not find class"
33
- str += "es" if missing.length > 1
34
-
35
- str += " " + missing.join(", ")
36
-
37
- if n = namespaces and ! n.empty? and n != [""]
38
- str += " in namespaces #{@namespaces.join(", ")}"
39
- end
40
- self.fail Puppet::ParseError, str
41
- end
28
+ options = ( args.size > 2 ? args[2] : {} )
29
+
30
+ config = CORL::Config.init_flat(options, [ :include ], {
31
+ :hiera_scope => self,
32
+ :puppet_scope => self,
33
+ :search => 'core::default',
34
+ :force => true,
35
+ :merge => true
36
+ })
37
+ CORL::Util::Puppet.include(var_name, parameters, config)
42
38
  end
43
39
  end
44
40
  end
@@ -0,0 +1,15 @@
1
+ #
2
+ # corl_initialize.rb
3
+ #
4
+ # Initialize the CORL plugin system through Puppet
5
+ #
6
+ module Puppet::Parser::Functions
7
+ newfunction(:corl_initialize, :doc => <<-EOS
8
+ This function initializes the CORL plugin system through Puppet.
9
+ EOS
10
+ ) do |args|
11
+ CORL.run do
12
+ CORL::Util::Puppet.register_plugins({ :puppet_scope => self })
13
+ end
14
+ end
15
+ end
@@ -1,17 +1,17 @@
1
1
  #
2
- # deep_merge.rb
2
+ # corl_merge.rb
3
3
  #
4
4
  # Merges multiple hashes together recursively.
5
5
  #
6
6
  module Puppet::Parser::Functions
7
- newfunction(:deep_merge, :type => :rvalue, :doc => <<-EOS
8
- This function Merges multiple hashes together recursively.
7
+ newfunction(:corl_merge, :type => :rvalue, :doc => <<-EOS
8
+ This function merges multiple hashes together recursively.
9
9
  EOS
10
10
  ) do |args|
11
11
 
12
12
  value = nil
13
13
  CORL.run do
14
- raise(Puppet::ParseError, "deep_merge(): Define at least one hash " +
14
+ raise(Puppet::ParseError, "corl_merge(): Define at least one hash " +
15
15
  "given (#{args.size} for 1)") if args.size < 1
16
16
 
17
17
  value = CORL::Util::Data.merge(args)
@@ -39,20 +39,25 @@ If no resources are found, it returns without creating anything.
39
39
  options = ( args[4] ? args[4] : {} )
40
40
 
41
41
  config = CORL::Config.init_flat(options, [ :resource, :corl_resources ], {
42
+ :provisioner => :puppetnode,
42
43
  :hiera_scope => self,
43
44
  :puppet_scope => self,
44
45
  :search => 'core::default',
45
- :init_fact => 'hiera_ready',
46
46
  :force => true,
47
47
  :merge => true,
48
48
  :resource_prefix => tag,
49
49
  :title_prefix => tag
50
- })
50
+ })
51
+ unless tag.empty?
52
+ config[:tag] = tag
53
+ config[:resource_prefix] = tag
54
+ config[:title_prefix] = tag
55
+ end
51
56
 
52
57
  resources = CORL::Config.normalize(resources, override_var, config)
53
58
  defaults = CORL::Config.normalize(defaults, default_var, config)
54
-
55
- CORL.provisioner(:puppet).add(definition_name, resources, defaults, config)
59
+
60
+ CORL::Util::Puppet.add(definition_name, resources, defaults, config)
56
61
  end
57
62
  end
58
63
  end
@@ -21,10 +21,10 @@ If no value is found in the defined sources, it returns an empty array ([])
21
21
  options = ( args.size > 2 ? args[2] : {} )
22
22
 
23
23
  config = CORL::Config.init_flat(options, [ :param, :global_array ], {
24
+ :provisioner => :puppetnode,
24
25
  :hiera_scope => self,
25
26
  :puppet_scope => self,
26
27
  :search => 'core::default',
27
- :init_fact => 'hiera_ready',
28
28
  :force => true,
29
29
  :merge => true
30
30
  })
@@ -21,10 +21,10 @@ If no value is found in the defined sources, it returns an empty hash ({})
21
21
  options = ( args.size > 2 ? args[2] : {} )
22
22
 
23
23
  config = CORL::Config.init_flat(options, [ :param, :global_hash ], {
24
+ :provisioner => :puppetnode,
24
25
  :hiera_scope => self,
25
26
  :puppet_scope => self,
26
27
  :search => 'core::default',
27
- :init_fact => 'hiera_ready',
28
28
  :force => true,
29
29
  :merge => true
30
30
  })
@@ -29,10 +29,10 @@ If no value is found in the defined sources, it returns an empty string ('')
29
29
  options = ( args.size > 2 ? args[2] : {} )
30
30
 
31
31
  config = CORL::Config.init_flat(options, [ :param, :global_param ], {
32
+ :provisioner => :puppetnode,
32
33
  :hiera_scope => self,
33
34
  :puppet_scope => self,
34
35
  :search => 'core::default',
35
- :init_fact => 'hiera_ready',
36
36
  :force => true,
37
37
  :merge => true
38
38
  })
@@ -19,7 +19,7 @@ This function interpolates values from one hash to another for configuration inj
19
19
  options = ( args.size > 2 ? args[2] : {} )
20
20
 
21
21
  config = CORL::Config.init_flat(options, [ :data, :interpolate ])
22
- value = CORL::Util::Data.interpolate(value, data, config.options)
22
+ value = CORL::Util::Data.interpolate(value, data, config.export)
23
23
  end
24
24
  return value
25
25
  end
@@ -14,24 +14,23 @@ If no value is found in the defined sources, it returns an empty array ([])
14
14
  raise(Puppet::ParseError, "module_array(): Define at least the variable name " +
15
15
  "given (#{args.size} for 1)") if args.size < 1
16
16
 
17
- var_name = args[0]
18
- default_value = ( args.size > 1 ? args[1] : [] )
19
- options = ( args.size > 2 ? args[2] : {} )
20
-
21
- module_name = self.source.module_name
22
- module_var_name = "#{module_name}::#{var_name}"
23
- default_var_name = "#{module_name}::default::#{var_name}"
17
+ var_name = args[0]
18
+ default = ( args.size > 1 ? args[1] : [] )
19
+ options = ( args.size > 2 ? args[2] : {} )
20
+
21
+ module_name = self.source.module_name
22
+ module_var_name = "#{module_name}::#{var_name}"
24
23
 
25
24
  config = CORL::Config.init(options, [ :param, :module_array ], module_name, {
25
+ :provisioner => :puppetnode,
26
26
  :hiera_scope => self,
27
27
  :puppet_scope => self,
28
28
  :search => 'core::default',
29
29
  :search_name => false,
30
- :init_fact => 'hiera_ready',
31
30
  :force => true,
32
31
  :merge => true
33
32
  })
34
- value = CORL::Config.lookup_array([ module_var_name, default_var_name ], default, config)
33
+ value = CORL::Config.lookup_array(module_var_name, default, config)
35
34
  end
36
35
  return value
37
36
  end
@@ -14,24 +14,23 @@ If no value is found in the defined sources, it returns an empty hash ({})
14
14
  raise(Puppet::ParseError, "module_hash(): Define at least the variable name " +
15
15
  "given (#{args.size} for 1)") if args.size < 1
16
16
 
17
- var_name = args[0]
18
- default_value = ( args.size > 1 ? args[1] : {} )
19
- options = ( args.size > 2 ? args[2] : {} )
17
+ var_name = args[0]
18
+ default = ( args.size > 1 ? args[1] : {} )
19
+ options = ( args.size > 2 ? args[2] : {} )
20
20
 
21
- module_name = self.source.module_name
22
- module_var_name = "#{module_name}::#{var_name}"
23
- default_var_name = "#{module_name}::default::#{var_name}"
21
+ module_name = self.source.module_name
22
+ module_var_name = "#{module_name}::#{var_name}"
24
23
 
25
24
  config = CORL::Config.init(options, [ :param, :module_hash ], module_name, {
25
+ :provisioner => :puppetnode,
26
26
  :hiera_scope => self,
27
27
  :puppet_scope => self,
28
28
  :search => 'core::default',
29
29
  :search_name => false,
30
- :init_fact => 'hiera_ready',
31
30
  :force => true,
32
31
  :merge => true
33
32
  })
34
- value = CORL::Config.lookup_hash([ module_var_name, default_var_name ], default, config)
33
+ value = CORL::Config.lookup_hash(module_var_name, default, config)
35
34
  end
36
35
  return value
37
36
  end
@@ -28,20 +28,19 @@ If no value is found in the defined sources, it returns an empty string ('')
28
28
  default = ( args.size > 1 ? args[1] : '' )
29
29
  options = ( args.size > 2 ? args[2] : {} )
30
30
 
31
- module_name = self.source.module_name
32
- module_var_name = "#{module_name}::#{var_name}"
33
- default_var_name = "#{module_name}::default::#{var_name}"
31
+ module_name = self.source.module_name
32
+ module_var_name = "#{module_name}::#{var_name}"
34
33
 
35
34
  config = CORL::Config.init(options, [ :param, :module_param ], module_name, {
35
+ :provisioner => :puppetnode,
36
36
  :hiera_scope => self,
37
37
  :puppet_scope => self,
38
38
  :search => 'core::default',
39
39
  :search_name => false,
40
- :init_fact => 'hiera_ready',
41
40
  :force => true,
42
41
  :merge => true
43
42
  })
44
- value = CORL::Config.lookup([ module_var_name, default_var_name ], default, config)
43
+ value = CORL::Config.lookup(module_var_name, default, config)
45
44
  end
46
45
  return value
47
46
  end
@@ -14,7 +14,7 @@ This function returns a standardized form of a given resource name.
14
14
  raise(Puppet::ParseError, "name(): Must have a resource name specified; " +
15
15
  "given (#{args.size} for 1)") if args.size < 1
16
16
 
17
- name = CORL.provisioner(:puppet).to_name(args[0])
17
+ name = CORL::Util::Puppet.to_name(args[0])
18
18
  end
19
19
  return name
20
20
  end
@@ -14,19 +14,19 @@ This function returns the string-ified form of a given value.
14
14
  raise(Puppet::ParseError, "render(): Must have a template class name and an optional source value specified; " +
15
15
  "given (#{args.size} for 2)") if args.size < 1
16
16
 
17
- class_name = args[0]
18
- data = ( args.size > 1 ? args[1] : {} )
19
- options = ( args.size > 2 ? args[2] : {} )
17
+ provider = args[0]
18
+ data = ( args.size > 1 ? args[1] : {} )
19
+ options = ( args.size > 2 ? args[2] : {} )
20
20
 
21
21
  config = CORL::Config.init_flat(options, [ :data, :render ], {
22
+ :provisioner => :puppetnode,
22
23
  :hiera_scope => self,
23
24
  :puppet_scope => self,
24
25
  :search => 'core::default',
25
- :init_fact => 'hiera_ready',
26
26
  :force => true,
27
27
  :merge => true
28
28
  })
29
- value = CORL.template(class_name, config).render(data)
29
+ value = CORL.template(config, provider).render(data)
30
30
  end
31
31
  return value
32
32
  end