lib/puppet/resource/catalog.rb
def alias(resource, key)
    ref = resource.ref
    ref =~ /^(.+)\[/
    class_name = $1 || resource.class.name

    newref = [class_name, key].flatten

    if key.is_a? String
      ref_string = "#{class_name}[#{key}]"
      return if ref_string == ref
    end

    # LAK:NOTE It's important that we directly compare the references,
    # because sometimes an alias is created before the resource is
    # added to the catalog, so comparing inside the below if block
    # isn't sufficient.
    if existing = @resource_table[newref]
      return if existing == resource
      resource_declaration = Puppet::Util::Errors.error_location(resource.file, resource.line)
      msg = if resource_declaration.empty?
              #TRANSLATORS 'alias' should not be translated
              _("Cannot alias %{resource} to %{key}; resource %{newref} already declared") %
                  { resource: ref, key: key.inspect, newref: newref.inspect }
            else
              #TRANSLATORS 'alias' should not be translated
              _("Cannot alias %{resource} to %{key} at %{resource_declaration}; resource %{newref} already declared") %
                  { resource: ref, key: key.inspect, resource_declaration: resource_declaration, newref: newref.inspect }
            end
      msg += Puppet::Util::Errors.error_location_with_space(existing.file, existing.line)
      raise ArgumentError, msg
    end
    @resource_table[newref] = resource
    @aliases[ref] ||= []
    @aliases[ref] << newref
  end
# Create an alias for a resource.
Create an alias for a resource.
Create an alias for a resource .
def alias(resource, key)
    ref = resource.ref
    ref =~ /^(.+)\[/
    class_name = $1 || resource.class.name
    newref = [class_name, key].flatten
    if key.is_a? String
      ref_string = "#{class_name}[#{key}]"
      return if ref_string == ref
    end
    if existing = @resource_table[newref]
      return if existing == resource
      resource_declaration = Puppet::Util::Errors.error_location(resource.file, resource.line)
      msg = if resource_declaration.empty?
              _("Cannot alias %{resource} to %{key}; resource %{newref} already declared") %
                  { resource: ref, key: key.inspect, newref: newref.inspect }
            else
              _("Cannot alias %{resource} to %{key} at %{resource_declaration}; resource %{newref} already declared") %
                  { resource: ref, key: key.inspect, resource_declaration: resource_declaration, newref: newref.inspect }
            end
      msg += Puppet::Util::Errors.error_location_with_space(existing.file, existing.line)
      raise ArgumentError, msg
    end
    @resource_table[newref] = resource
    @aliases[ref] ||= []
    @aliases[ref] << newref
  end
def alias ( resource , key ) ref = resource . ref ref =~ / ^(.+) \[ / class_name = $1 || resource . class . name newref = [ class_name , key ] . flatten if key . is_a? String ref_string = "#{class_name}[#{key}]" return if ref_string == ref end if existing = @resource_table [ newref ] return if existing == resource resource_declaration = Puppet :: Util :: Errors . error_location ( resource . file , resource . line ) msg = if resource_declaration . empty? _ ( "Cannot alias %{resource} to %{key}; resource %{newref} already declared" ) % { resource : ref , key : key . inspect , newref : newref . inspect } else _ ( "Cannot alias %{resource} to %{key} at %{resource_declaration}; resource %{newref} already declared" ) % { resource : ref , key : key . inspect , resource_declaration : resource_declaration , newref : newref . inspect } end msg += Puppet :: Util :: Errors . error_location_with_space ( existing . file , existing . line ) raise ArgumentError , msg end @resource_table [ newref ] = resource @aliases [ ref ] ||= [ ] @aliases [ ref ] << newref end
Create an alias for a resource.
Create an alias for a resource .
# LAK:NOTE It's important that we directly compare the references, # because sometimes an alias is created before the resource is # added to the catalog, so comparing inside the below if block # isn't sufficient. #TRANSLATORS 'alias' should not be translated #TRANSLATORS 'alias' should not be translated
resource
key