<commit_before>class Puppet::Provider::SwiftRingBuilder < Puppet::Provider

  def self.instances
    # TODO iterate through the databases
    # and add the database that we used a property
    ring.keys.collect do |name|
      new(:name => name)
    end
  end


  def self.lookup_ring
    object_hash = {}
    if File.exists?(builder_file_path)
      if rows = swift_ring_builder(builder_file_path).split("\n")[4..-1]
        rows.each do |row|
          if row =~ /^\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)?\s+\d?(-?\d+\.\d+)\s+(\S*)$/
            object_hash["#{$4}:#{$5}"] = {
              :id          => $1,
              :region      => $2,
              :zone        => $3,
              :partitions  => $8,
              :balance     => $9,
              :meta        => $10,
            }
          else
            Puppet.warning("Unexpected line: #{row}")
          end
        end
      end
    end
    object_hash
  end

  def ring
    self.class.ring
  end

  def builder_file_path
    self.class.builder_file_path
  end

  def exists?
    notice("node name: #{resource[:name]}")
    notice("available devs: #{available_devs.keys.sort.inspect}")
    available_devs.keys.each do |dev|
      raise(Puppet::Error, "Device name #{resource[:name]} should not contain underscore") if dev.include?('_')
    end
    raise(Puppet::Error, "Device not found check device on  #{resource[:name]} ") if available_devs.empty?
    return  available_devs.keys.sort == used_devs
  end

  def create
    raise(Puppet::Error, "#{param} is required") unless resource[:zone]

    # remove the missing devices
    destroy

    (available_devs.keys - used_devs).each do |mountpoint|
      notice("*** create device: #{mountpoint}")
      swift_ring_builder(builder_file_path,
        'add',
        "z#{resource[:zone]}-#{resource[:name]}/#{mountpoint}",
        available_devs[mountpoint]
      )
    end
  end

  def destroy
    (used_devs - available_devs.keys).each do |mountpoint|
      notice("*** remove device: #{mountpoint}")
      swift_ring_builder(builder_file_path,
        'remove',
        "#{resource[:name]}/#{mountpoint}"
      )
    end
  end

  def available_devs
    @available_devices = {}

    mountpoints = "#{resource[:mountpoints]}".split("\n")
    for i in mountpoints
      @available_devices[i.split[0]] = i.split[1]
    end

    @available_devices
  end

  def used_devs
    if devs = swift_ring_builder(builder_file_path).split("\n")[4..-1]
      @used_devices = devs.collect do |line|
        line.strip.split(/\s+/)[5] if line.match(/#{resource[:name].split(':')[0]}/)
      end.compact.sort
    else
      []
    end
  end

  def id
    ring[resource[:name]][:id]
  end

  def id=(id)
    raise(Puppet::Error, "Cannot assign id, it is immutable")
  end

  def zone
    ring[resource[:name]][:zone]
  end

  # TODO - is updating the zone supported?
  def zone=(zone)
    Puppet.warning('Setting zone is not yet supported, I am not even sure if it is supported')
  end

  def partitions
    ring[resource[:name]][:partitions]
  end

  def partitions=(part)
    raise(Puppet::Error, "Cannot set partitions, it is set by rebalancing")
  end

  def balance
    ring[resource[:name]][:balance]
  end

  def balance=(balance)
    raise(Puppet::Error, "Cannot set balance, it is set by rebalancing")
  end

  def meta
    ring[resource[:name]][:meta]
  end

  def meta=(meta)
    raise(Puppet::Error, "Cannot set meta, I am not sure if it makes sense or what it is for")
  end

end

<commit_msg>Fix swift output parse regexp<commit_after>class Puppet::Provider::SwiftRingBuilder < Puppet::Provider

  def self.instances
    # TODO iterate through the databases
    # and add the database that we used a property
    ring.keys.collect do |name|
      new(:name => name)
    end
  end


  def self.lookup_ring
    object_hash = {}
    if File.exists?(builder_file_path)
      if rows = swift_ring_builder(builder_file_path).split("\n")[4..-1]
        rows.each do |row|
          if row =~ /^\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)?\s+\d?(-?\d+\.\d+)\s*(\S*)$/
            object_hash["#{$4}:#{$5}"] = {
              :id          => $1,
              :region      => $2,
              :zone        => $3,
              :partitions  => $10,
              :balance     => $11,
              :meta        => $12,
            }
          else
            Puppet.warning("Unexpected line: #{row}")
          end
        end
      end
    end
    object_hash
  end

  def ring
    self.class.ring
  end

  def builder_file_path
    self.class.builder_file_path
  end

  def exists?
    notice("node name: #{resource[:name]}")
    notice("available devs: #{available_devs.keys.sort.inspect}")
    available_devs.keys.each do |dev|
      raise(Puppet::Error, "Device name #{resource[:name]} should not contain underscore") if dev.include?('_')
    end
    raise(Puppet::Error, "Device not found check device on  #{resource[:name]} ") if available_devs.empty?
    return  available_devs.keys.sort == used_devs
  end

  def create
    raise(Puppet::Error, "#{param} is required") unless resource[:zone]

    # remove the missing devices
    destroy

    (available_devs.keys - used_devs).each do |mountpoint|
      notice("*** create device: #{mountpoint}")
      swift_ring_builder(builder_file_path,
        'add',
        "z#{resource[:zone]}-#{resource[:name]}/#{mountpoint}",
        available_devs[mountpoint]
      )
    end
  end

  def destroy
    (used_devs - available_devs.keys).each do |mountpoint|
      notice("*** remove device: #{mountpoint}")
      swift_ring_builder(builder_file_path,
        'remove',
        "#{resource[:name]}/#{mountpoint}"
      )
    end
  end

  def available_devs
    @available_devices = {}

    mountpoints = "#{resource[:mountpoints]}".split("\n")
    for i in mountpoints
      @available_devices[i.split[0]] = i.split[1]
    end

    @available_devices
  end

  def used_devs
    if devs = swift_ring_builder(builder_file_path).split("\n")[4..-1]
      @used_devices = devs.collect do |line|
        line.strip.split(/\s+/)[7] if line.match(/#{resource[:name].split(':')[0]}/)
      end.compact.sort
    else
      []
    end
  end

  def id
    ring[resource[:name]][:id]
  end

  def id=(id)
    raise(Puppet::Error, "Cannot assign id, it is immutable")
  end

  def zone
    ring[resource[:name]][:zone]
  end

  # TODO - is updating the zone supported?
  def zone=(zone)
    Puppet.warning('Setting zone is not yet supported, I am not even sure if it is supported')
  end

  def partitions
    ring[resource[:name]][:partitions]
  end

  def partitions=(part)
    raise(Puppet::Error, "Cannot set partitions, it is set by rebalancing")
  end

  def balance
    ring[resource[:name]][:balance]
  end

  def balance=(balance)
    raise(Puppet::Error, "Cannot set balance, it is set by rebalancing")
  end

  def meta
    ring[resource[:name]][:meta]
  end

  def meta=(meta)
    raise(Puppet::Error, "Cannot set meta, I am not sure if it makes sense or what it is for")
  end

end


{'fraction_non_alphanumeric': 0.1489600899381675, 'fraction_numerical': 0.00505902192242833, 'mean_word_length': 2.5460886895864476, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '3435840', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2372, 'n_words': 568}