8. Presented by
#run_command
#
lib/puppet/application/agent.rb
def
run_command
if
options[:fingerprint]
fingerprint
else
#
It'd
be
nice
to
daemonize
later,
but
we
have
to
daemonize
before
#
waiting
for
certificates
so
that
we
don't
block
daemon
=
daemonize_process_when(Puppet[:daemonize])
!
wait_for_certificates
!
if
Puppet[:onetime]
onetime(daemon)
else
main(daemon)
end
9. Presented by
onetime() and main()
#
lib/puppet/application/agent.rb
begin
exitstatus
=
daemon.agent.run
rescue
=>
detail
Puppet.log_exception(detail)
end
!
daemon.stop(:exit
=>
false)
!
if
not
exitstatus
exit(1)
elsif
options[:detailed_exitcodes]
then
exit(exitstatus)
else
exit(0)
end
#
lib/puppet/application/agent.rb
def
main(daemon)
if
Puppet[:listen]
setup_listen(daemon)
end
Puppet.notice
"Starting
Puppet
client
version
#{Puppet.version}"
!
daemon.start
end
10. Presented by
Obtaining the daemon
#
lib/puppet/application/agent.rb
def
daemonize_process_when(should_daemonize)
daemon
=
Puppet::Daemon.new(Puppet::Util::Pidlock.new(Puppet[:pidfile]))
daemon.argv
=
@argv
daemon.agent
=
@agent
!
daemon.daemonize
if
should_daemonize
!
daemon
end
18. Puppet::Configurer#run_internal
Presented by
#
lib/puppet/configurer.rb
def
run_internal(options)
#
We
create
the
report
pre-‐populated
with
default
settings
for
#
environment
and
transaction_uuid
very
early,
this
is
to
ensure
#
they
are
sent
regardless
of
any
catalog
compilation
failures
or
#
exceptions.
options[:report]
||=
Puppet::Transaction::Report.new("apply",
nil,
@environment,
@transaction_uuid)
report
=
options[:report]
init_storage
!
Puppet::Util::Log.newdestination(report)
…
…
…
29. Presented by
RAL Catalog
#
lib/puppet/resource/catalog.rb
def
to_catalog(convert)
result
=
self.class.new(self.name,
self.environment_instance)
result.version
=
self.version
map
=
{}
resources.each
do
|resource|
next
if
virtual_not_exported?(resource)
next
if
block_given?
and
yield
resource
newres
=
resource.copy_as_resource
newres.catalog
=
result
if
convert
!=
:to_resource
newres
=
newres.to_ral
end
#
We
can't
guarantee
that
resources
don't
munge
their
names
#
(like
files
do
with
trailing
slashes),
so
we
have
to
keep
track
#
of
what
a
resource
got
converted
to.
map[resource.ref]
=
newres
result.add_resource
newres
end
63. lib/puppet/network/http/api/v1.rb
• GET => indirection.find()
• POST => indirection.find() (for catalogs)
• (There was an issue with some servers rejecting GET
parameters that were too long. Funny story about that.)
• DELETE => indirection.destroy()
• PUT => indirection.save()
• GET to magical plural name => indirection.search()
Presented by
64. Presented by
BIG PICTURE
Configurer calls catalog.indirection.find()
↓
HTTP POST request to master
↓
Request handler calls catalog.indirection.find()
↓
Compiler terminus handles it
↓