Sha256: 018fe75700327874fb3e621a7a7bf9babdaa7b4944aadcdccb8e97c25b490858

Contents?: true

Size: 1.17 KB

Versions: 44

Compression:

Stored size: 1.17 KB

Contents

require 'puppet/rails/host'
require 'puppet/indirector/active_record'
require 'puppet/resource/catalog'

class Puppet::Resource::Catalog::ActiveRecord < Puppet::Indirector::ActiveRecord
  use_ar_model Puppet::Rails::Host

  # If we can find the host, then return a catalog with the host's resources
  # as the vertices.
  def find(request)
    return nil unless request.options[:cache_integration_hack]
    return nil unless host = ar_model.find_by_name(request.key)

    catalog = Puppet::Resource::Catalog.new(host.name)

    host.resources.each do |resource|
      catalog.add_resource resource.to_transportable
    end

    catalog
  end

  # Save the values from a Facts instance as the facts on a Rails Host instance.
  def save(request)
    catalog = request.instance

    host = ar_model.find_by_name(catalog.name) || ar_model.create(:name => catalog.name)

    host.railsmark "Saved catalog to database" do
      host.merge_resources(catalog.vertices)
      host.last_compile = Time.now

      if node = Puppet::Node.indirection.find(catalog.name)
        host.ip = node.parameters["ipaddress"]
        host.environment = node.environment.to_s
      end

      host.save
    end
  end
end

Version data entries

44 entries across 44 versions & 4 rubygems

Version Path
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.18 lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.17 lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.16 lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.14 lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.13 lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.12 lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.11 lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.9 lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.8 lib/puppet/indirector/catalog/active_record.rb
puppet-2.7.6 lib/puppet/indirector/catalog/active_record.rb