<commit_before>Puppet::Type.type(:quagga_system).provide :quagga do
  @doc = 'Manages quagga router settings'

  @resource_map = {
    :hostname => {
      :regexp => /\Ahostname\s(.*)\Z/,
      :template => 'hostname<% unless value.nil? %> <%= value %><% end %>',
      :type => :string,
      :default => :absent
    },
    :password => {
      :regexp => /\Apassword\s(?:\d\s)?(.*)\Z/,
      :template => 'password<% unless value.nil? %><% if encrypted %> 8<% end %> <%= value %><% end %>',
      :type => :string,
      :default => :absent
    },
    :enable_password => {
      :regexp => /\Aenable\spassword\s(?:\d\s)?(.*)\Z/,
      :template => 'enable password<% unless value.nil? %><% if encrypted %> 8<% end %> <%= value %><% end %>',
      :type => :string,
      :default => :absent
    },
    :line_vty => {
      :regexp => /\Aline\svty\Z/,
      :template => 'line vty',
      :type => :boolean,
      :default => :true
    },
    :service_password_encryption => {
      :regexp => /\Aservice\spassword-encryption\Z/,
      :template => 'service password-encryption',
      :type => :boolean,
      :default => :false
    }
  }

  commands :vtysh => 'vtysh'

  def initialize(value)
    super(value)
    @property_flush = {}
  end

  def self.instances
    debug '[instances]'

    hash = {}
    @resource_map.each do |property, options|
      hash[property] = options[:default]
    end

    hash[:name] = hash[:hostname] if hash[:hostname]

    config = vtysh('-c', 'show running-config')
    config.split(/\n/).collect do |line|
      # comment
      next if line =~ /\A!\Z/

      @resource_map.each do |property, options|
        if line =~ options[:regexp]
          value = $1

          if value.nil?
            hash[property] = :true
          else
            case options[:type]
              when :boolean
                hash[property] = :true

              when :fixnum
                hash[property] = value.to_i

              when :symbol
                hash[property] = value.to_sym

              else
                hash[property] = value

            end
          end

          break
        end
      end
    end

    [new(hash)]
  end

  def self.prefetch(resources)
    resources[resources.keys.first].provider = instances.first
  end

  def flush
    resource_map = self.class.instance_variable_get('@resource_map')
    name = @property_hash[:name].nil? ? @resource[:name] : @property_hash[:name]

    debug "[flush][#{name}]"
<commit_msg>Fixed a name of the resource `quagga_system`<commit_after>Puppet::Type.type(:quagga_system).provide :quagga do
  @doc = 'Manages quagga router settings'

  @resource_map = {
    :hostname => {
      :regexp => /\Ahostname\s(.*)\Z/,
      :template => 'hostname<% unless value.nil? %> <%= value %><% end %>',
      :type => :string,
      :default => :absent
    },
    :password => {
      :regexp => /\Apassword\s(?:\d\s)?(.*)\Z/,
      :template => 'password<% unless value.nil? %><% if encrypted %> 8<% end %> <%= value %><% end %>',
      :type => :string,
      :default => :absent
    },
    :enable_password => {
      :regexp => /\Aenable\spassword\s(?:\d\s)?(.*)\Z/,
      :template => 'enable password<% unless value.nil? %><% if encrypted %> 8<% end %> <%= value %><% end %>',
      :type => :string,
      :default => :absent
    },
    :line_vty => {
      :regexp => /\Aline\svty\Z/,
      :template => 'line vty',
      :type => :boolean,
      :default => :true
    },
    :service_password_encryption => {
      :regexp => /\Aservice\spassword-encryption\Z/,
      :template => 'service password-encryption',
      :type => :boolean,
      :default => :false
    }
  }

  commands :vtysh => 'vtysh'

  def initialize(value)
    super(value)
    @property_flush = {}
  end

  def self.instances
    debug '[instances]'

    hash = {}
    @resource_map.each do |property, options|
      hash[property] = options[:default]
    end

    config = vtysh('-c', 'show running-config')
    config.split(/\n/).collect do |line|
      # comment
      next if line =~ /\A!\Z/

      @resource_map.each do |property, options|
        if line =~ options[:regexp]
          value = $1

          if value.nil?
            hash[property] = :true
          else
            case options[:type]
              when :boolean
                hash[property] = :true

              when :fixnum
                hash[property] = value.to_i

              when :symbol
                hash[property] = value.to_sym

              else
                hash[property] = value

            end
          end

          break
        end
      end
    end

    hash[:name] = hash[:hostname]

    [new(hash)]
  end

  def self.prefetch(resources)
    resources[resources.keys.first].provider = instances.first
  end

  def flush
    resource_map = self.class.instance_variable_get('@resource_map')
    name = @property_hash[:name].nil? ? @resource[:name] : @property_hash[:name]

    debug "[flush][#{name}]"

{'fraction_non_alphanumeric': 0.16606425702811245, 'fraction_numerical': 0.0012048192771084338, 'mean_word_length': 2.0242865816636306, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4218817', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1568, 'n_words': 338}