lib/puppet/resource/catalog.rb
# An abstracted method for converting one catalog into another type of catalog.
# This pretty much just converts all of the resources from one class to another, using
# a conversion method.
An abstracted method for converting one catalog into another type of catalog.
This pretty much just converts all of the resources from one class to another, using
a conversion method.
An abstracted method for converting one catalog into another type of catalog . This pretty much just converts all of the resources from one class to another using a conversion method .
def to_catalog(convert)
    result = self.class.new(self.name, self.environment_instance)
    result.version = self.version
    result.code_id = self.code_id
    result.catalog_uuid = self.catalog_uuid
    result.catalog_format = self.catalog_format
    result.metadata = self.metadata
    result.recursive_metadata = self.recursive_metadata
    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
      map[resource.ref] = newres
      result.add_resource newres
    end
    message = convert.to_s.gsub "_", " "
    edges.each do |edge|
      next if virtual_not_exported?(edge.source)
      next if block_given? and yield edge.source
      next if virtual_not_exported?(edge.target)
      next if block_given? and yield edge.target
      unless source = map[edge.source.ref]
        raise Puppet::DevError, _("Could not find resource %{resource} when converting %{message} resources") % { resource: edge.source.ref, message: message }
      end
      unless target = map[edge.target.ref]
        raise Puppet::DevError, _("Could not find resource %{resource} when converting %{message} resources") % { resource: edge.target.ref, message: message }
      end
      result.add_edge(source, target, edge.label)
    end
    map.clear
    result.add_class(*self.classes)
    result.merge_tags_from(self)
    result
  end
def to_catalog ( convert ) result = self . class . new ( self . name , self . environment_instance ) result . version = self . version result . code_id = self . code_id result . catalog_uuid = self . catalog_uuid result . catalog_format = self . catalog_format result . metadata = self . metadata result . recursive_metadata = self . recursive_metadata 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 map [ resource . ref ] = newres result . add_resource newres end message = convert . to_s . gsub "_" , " " edges . each do | edge | next if virtual_not_exported? ( edge . source ) next if block_given? and yield edge . source next if virtual_not_exported? ( edge . target ) next if block_given? and yield edge . target unless source = map [ edge . source . ref ] raise Puppet :: DevError , _ ( "Could not find resource %{resource} when converting %{message} resources" ) % { resource : edge . source . ref , message : message } end unless target = map [ edge . target . ref ] raise Puppet :: DevError , _ ( "Could not find resource %{resource} when converting %{message} resources" ) % { resource : edge . target . ref , message : message } end result . add_edge ( source , target , edge . label ) end map . clear result . add_class ( * self . classes ) result . merge_tags_from ( self ) result end
An abstracted method for converting one catalog into another type of catalog.
An abstracted method for converting one catalog into another type of catalog .
# 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. # Skip edges between virtual resources.
convert