<commit_before>require File.join(File.dirname(__FILE__), '..', 'cloudstack_rest')

Puppet::Type.type(:cloudstack_network_offering).provide :rest, :parent => Puppet::Provider::Rest do
  desc "REST provider for Cloudstack Network Offering"
  
  mk_resource_methods
  
  def flush      
    if @property_flush[:ensure] == :absent
      deleteNetworkOffering
      return
    end 
        
    if @property_flush[:ensure] != :absent
      return if createNetworkOffering
    end
        
    if @property_flush[:ensure] == :enabled
      enableNetworkOffering
      return
    end 
    
#    if @property_flush[:ensure] == :inactive
#      # ???
#      return
#    end 
    
    if @property_flush[:ensure] == :disabled
      disableNetworkOffering
      return
    end 
    
    updateNetworkOffering
  end  

  def self.instances     
    list = get_objects(:listNetworkOfferings, "networkoffering")
    if list == nil
      return list
    end
    
    result = Array.new  
    list.each do |object|
      map = getNetworkOffering(object)
      if map != nil
        #Puppet.debug "NetworkOffering FOUND: "+map.inspect
        result.push(new(map))
      end
    end 

    result 
  end
  
  def self.getObject(name) 
    params = { :name => name }
    
    #Puppet.debug "LOOKUP NetworkOffering: "+params.inspect

    list = get_objects(:listNetworkOfferings, "networkoffering", params)    
    if list == nil
      raise "Could not find Network Offering with name "+name
    end
    
    list.each do |object|   
       if object["name"] == name
         #Puppet.debug "NetworkOffering FOUND (2): "+object.inspect
         return getNetworkOffering(object)         
       end      
    end
    
    # Found similar names, but no exact matches!
    return nil
  end
    
  def self.getNetworkOffering(object)   
    if object["name"] != nil        
      tags = convertCSVtoArray(object["tags"])
  
      params = { :id => object['serviceofferingid'] }
      serviceoffering = getServiceOffering(params)
      
      services = Array.new
      if object["service"] != nil
        object["service"].each do |serviceMap|
          newSet = Hash.new
          serviceMap.each do |k, v|
            newSet["name"] = v["name"]
            newSet["provider"] = v["provider"]
          end
          services.push newSet
        end
      end
                    
      {
        :id                   => object["id"],
        :name                 => object["name"],   
        :displaytext          => object["displaytext"],            
        :guestiptype          => object["guestiptype"].downcase,
        :ispersistent         => object["ispersistent"],
        :conservemode         => object["conservemode"],     
        :availability         => object["availability"],<commit_msg>Fix network offering (service map)<commit_after>require File.join(File.dirname(__FILE__), '..', 'cloudstack_rest')

Puppet::Type.type(:cloudstack_network_offering).provide :rest, :parent => Puppet::Provider::Rest do
  desc "REST provider for Cloudstack Network Offering"
  
  mk_resource_methods
  
  def flush      
    if @property_flush[:ensure] == :absent
      deleteNetworkOffering
      return
    end 
        
    if @property_flush[:ensure] != :absent
      return if createNetworkOffering
    end
        
    if @property_flush[:ensure] == :enabled
      enableNetworkOffering
      return
    end 
    
#    if @property_flush[:ensure] == :inactive
#      # ???
#      return
#    end 
    
    if @property_flush[:ensure] == :disabled
      disableNetworkOffering
      return
    end 
    
    updateNetworkOffering
  end  

  def self.instances     
    list = get_objects(:listNetworkOfferings, "networkoffering")
    if list == nil
      return list
    end
    
    result = Array.new  
    list.each do |object|
      map = getNetworkOffering(object)
      if map != nil
        #Puppet.debug "NetworkOffering FOUND: "+map.inspect
        result.push(new(map))
      end
    end 

    result 
  end
  
  def self.getObject(name) 
    params = { :name => name }
    
    #Puppet.debug "LOOKUP NetworkOffering: "+params.inspect

    list = get_objects(:listNetworkOfferings, "networkoffering", params)    
    if list == nil
      raise "Could not find Network Offering with name "+name
    end
    
    list.each do |object|   
       if object["name"] == name
         #Puppet.debug "NetworkOffering FOUND (2): "+object.inspect
         return getNetworkOffering(object)         
       end      
    end
    
    # Found similar names, but no exact matches!
    return nil
  end
    
  def self.getNetworkOffering(object)   
    if object["name"] != nil        
      tags = convertCSVtoArray(object["tags"])
  
      params = { :id => object['serviceofferingid'] }
      serviceoffering = getServiceOffering(params)
      
      services = Array.new
      if object["service"] != nil
        object["service"].each do |serviceMap|
          newSet = Hash.new
          newSet["name"] = serviceMap["name"]
          newSet["provider"] = serviceMap["provider"]
          services.push newSet
        end
      end
                    
      {
        :id                   => object["id"],
        :name                 => object["name"],   
        :displaytext          => object["displaytext"],            
        :guestiptype          => object["guestiptype"].downcase,
        :ispersistent         => object["ispersistent"],
        :conservemode         => object["conservemode"],     
        :availability         => object["availability"],
{'fraction_non_alphanumeric': 0.10369036903690369, 'fraction_numerical': 0.00036003600360036, 'mean_word_length': 1.998381003777658, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '1213578', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1568, 'n_words': 358}