corl 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/corl.gemspec +12 -7
- data/lib/CORL/action/build.rb +30 -0
- data/lib/CORL/action/provision.rb +34 -8
- data/lib/CORL/configuration/file.rb +50 -64
- data/lib/CORL/provisioner/puppetnode.rb +186 -314
- data/lib/core/mixin/lookup.rb +20 -15
- data/lib/core/mixin/macro/network_settings.rb +52 -0
- data/lib/core/plugin/action.rb +1 -1
- data/lib/core/plugin/configuration.rb +43 -4
- data/lib/core/plugin/network.rb +16 -3
- data/lib/core/plugin/node.rb +69 -2
- data/lib/core/plugin/provisioner.rb +286 -11
- data/lib/{CORL/provisioner/puppetnode → core/util/puppet}/resource.rb +36 -40
- data/lib/{CORL/provisioner/puppetnode → core/util/puppet}/resource_group.rb +33 -41
- data/lib/core/util/puppet.rb +303 -0
- data/lib/corl.rb +34 -11
- data/lib/facter/corl_build.rb +8 -0
- data/lib/facter/corl_exists.rb +3 -3
- data/lib/facter/corl_network.rb +1 -1
- data/lib/facter/custom_facts.rb +24 -0
- data/lib/facter/vagrant_exists.rb +15 -0
- data/lib/hiera/corl_logger.rb +1 -1
- data/lib/puppet/indirector/corl.rb +2 -2
- data/lib/puppet/parser/functions/corl_include.rb +10 -14
- data/lib/puppet/parser/functions/corl_initialize.rb +15 -0
- data/lib/puppet/parser/functions/{deep_merge.rb → corl_merge.rb} +4 -4
- data/lib/puppet/parser/functions/corl_resources.rb +9 -4
- data/lib/puppet/parser/functions/global_array.rb +1 -1
- data/lib/puppet/parser/functions/global_hash.rb +1 -1
- data/lib/puppet/parser/functions/global_param.rb +1 -1
- data/lib/puppet/parser/functions/interpolate.rb +1 -1
- data/lib/puppet/parser/functions/module_array.rb +8 -9
- data/lib/puppet/parser/functions/module_hash.rb +7 -8
- data/lib/puppet/parser/functions/module_param.rb +4 -5
- data/lib/puppet/parser/functions/name.rb +1 -1
- data/lib/puppet/parser/functions/render.rb +5 -5
- metadata +34 -29
- data/lib/CORL/extension/puppetloader.rb +0 -24
- 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
|
-
|
59
|
-
|
60
|
-
|
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
|
|
data/lib/facter/corl_exists.rb
CHANGED
@@ -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
|
data/lib/facter/corl_network.rb
CHANGED
@@ -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
|
data/lib/hiera/corl_logger.rb
CHANGED
@@ -13,12 +13,12 @@ class Puppet::Indirector::CORL < Puppet::Indirector::Terminus
|
|
13
13
|
#---
|
14
14
|
|
15
15
|
def find(request)
|
16
|
-
config = CORL::Config.
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
#
|
2
|
+
# corl_merge.rb
|
3
3
|
#
|
4
4
|
# Merges multiple hashes together recursively.
|
5
5
|
#
|
6
6
|
module Puppet::Parser::Functions
|
7
|
-
newfunction(:
|
8
|
-
This function
|
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, "
|
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.
|
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.
|
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
|
18
|
-
|
19
|
-
options
|
20
|
-
|
21
|
-
module_name
|
22
|
-
module_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(
|
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
|
18
|
-
|
19
|
-
options
|
17
|
+
var_name = args[0]
|
18
|
+
default = ( args.size > 1 ? args[1] : {} )
|
19
|
+
options = ( args.size > 2 ? args[2] : {} )
|
20
20
|
|
21
|
-
module_name
|
22
|
-
module_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(
|
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
|
32
|
-
module_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(
|
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.
|
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
|
-
|
18
|
-
data
|
19
|
-
options
|
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(
|
29
|
+
value = CORL.template(config, provider).render(data)
|
30
30
|
end
|
31
31
|
return value
|
32
32
|
end
|