⚲
Project
General
Profile
Sign in
Home
Projects
Help
Search
:
Installer
All Projects
Foreman
»
Installer
Overview
Activity
Roadmap
Issues
Repository
Download (1.27 KB)
Feature #8518
» foreman.rb
foreman node indirection -
Michael Messmore
, 11/26/2014 11:18 AM
# /usr/lib/ruby/site_ruby/1.8/puppet/indirector/node/foreman.rb
require
'puppet/node'
require
'puppet/indirector/foreman'
class
Puppet::Node::Foreman
<
Puppet
::
Indirector
::
Foreman
desc
"Simple wrapper, since this only does nodes"
def
find
(
request
)
output
=
super
or
return
nil
result
=
translate
(
request
.
key
,
output
)
result
[
:environment
]
||=
request
.
environment
create_node
(
request
.
key
,
result
)
end
private
# Turn our outputted objects into a Puppet::Node instance.
def
create_node
(
name
,
result
)
node
=
Puppet
::
Node
.
new
(
name
)
set
=
false
[
:parameters
,
:classes
,
:environment
].
each
do
|
param
|
if
value
=
result
[
param
]
node
.
send
(
param
.
to_s
+
"="
,
value
)
set
=
true
end
end
node
.
fact_merge
node
end
# Translate the yaml string into Ruby objects.
def
translate
(
name
,
output
)
YAML
.
load
(
output
).
inject
({})
do
|
hash
,
data
|
case
data
[
0
]
when
String
hash
[
data
[
0
].
intern
]
=
data
[
1
]
when
Symbol
hash
[
data
[
0
]]
=
data
[
1
]
else
raise
Puppet
::
Error
,
"key is a
#{
data
[
0
].
class
}
, not a string or symbol"
end
hash
end
rescue
=>
detail
raise
Puppet
::
Error
,
"Could not load external node results for
#{
name
}
:
#{
detail
}
"
,
detail
.
backtrace
end
end
« Previous
1
2
Next »
(2-2/2)
Loading...