Class: Puppet::Provider::F5
- Inherits:
 - 
      Puppet::Provider
      
        
- Object
 - Puppet::Provider
 - Puppet::Provider::F5
 
 
- Defined in:
 - lib/puppet/provider/f5.rb
 
Direct Known Subclasses
Class Method Summary collapse
- .call(url, args = {}) ⇒ Object
 - .call_items(url, args = {'expandSubcollections'=>'true'}) ⇒ Object
 - 
  
    
      .clear_profile_type_cache  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
This function is to invalidate the cache, it is called once per provider previously, we were refreshing the cache many times per resource.
 - .connection ⇒ Object
 - .delete(url) ⇒ Object
 - .device(url) ⇒ Object
 - .find_availability(string) ⇒ Object
 - .find_default_route_domain(partition) ⇒ Object
 - .find_monitors(string) ⇒ Object
 - 
  
    
      .find_profile_type(profile)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Find the type of a given profile in the profile cache, or if it is not found try reloading the cache and looking again.
 - .get_partitions ⇒ Object
 - .integer?(str) ⇒ Boolean
 - .partition(path) ⇒ Object
 - .post(url, message) ⇒ Object
 - .put(url, message) ⇒ Object
 - 
  
    
      .sort_profiles  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Find all profiles on the F5 and associate them as <profile name> => <profile type> (profile names are unique for all profile types).
 - .transport ⇒ Object
 
Instance Method Summary collapse
- #api_name ⇒ Object
 - #basename ⇒ Object
 - #convert_underscores(hash) ⇒ Object
 - #create_message(basename, partition, hash) ⇒ Object
 - #destination_conversion(message) ⇒ Object
 - 
  
    
      #filters_conversion(message)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
We need to convert our puppet array into a space seperated string.
 - 
  
    
      #headers_conversion(message)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
We need to convert our puppet array into a n seperated string.
 - #monitor_conversion(hash) ⇒ Object
 - #partition ⇒ Object
 - 
  
    
      #rename_keys(keys_to_rename, rename_hash)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
This allows us to simply rename keys from the puppet representation to the F5 representation.
 - #string_to_integer(hash) ⇒ Object
 - #strip_elements(hash, elements_to_strip) ⇒ Object
 - 
  
    
      #strip_nil_values(hash)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
For some reason the object we pass in has undefined parameters in the object with nil values.
 
Class Method Details
.call(url, args = {}) ⇒ Object
      24 25 26  | 
    
      # File 'lib/puppet/provider/f5.rb', line 24 def self.call(url,args={}) transport.call(url,args) end  | 
  
.call_items(url, args = {'expandSubcollections'=>'true'}) ⇒ Object
      28 29 30 31 32 33 34  | 
    
      # File 'lib/puppet/provider/f5.rb', line 28 def self.call_items(url,args={'expandSubcollections'=>'true'}) if call = transport.call(url,args) call['items'] else nil end end  | 
  
.clear_profile_type_cache ⇒ Object
This function is to invalidate the cache, it is called once per provider previously, we were refreshing the cache many times per resource. If the profile didnt exist
      191 192 193  | 
    
      # File 'lib/puppet/provider/f5.rb', line 191 def self.clear_profile_type_cache @@profile_cache = nil end  | 
  
.connection ⇒ Object
      20 21 22  | 
    
      # File 'lib/puppet/provider/f5.rb', line 20 def self.connection transport.connection end  | 
  
.delete(url) ⇒ Object
      44 45 46  | 
    
      # File 'lib/puppet/provider/f5.rb', line 44 def self.delete(url) transport.delete(url) end  | 
  
.device(url) ⇒ Object
      6 7 8  | 
    
      # File 'lib/puppet/provider/f5.rb', line 6 def self.device(url) Puppet::Util::NetworkDevice::F5::Device.new(url) end  | 
  
.find_availability(string) ⇒ Object
      48 49 50  | 
    
      # File 'lib/puppet/provider/f5.rb', line 48 def self.find_availability(string) transport.find_availability(string) end  | 
  
.find_default_route_domain(partition) ⇒ Object
      211 212 213 214 215 216 217 218 219  | 
    
      # File 'lib/puppet/provider/f5.rb', line 211 def self.find_default_route_domain(partition) partitions = @@partition_cache ||= get_partitions if partitions[partition] partitions[partition]["defaultRouteDomain"] else @@partition_cache = get_partitions @@partition_cache[partition]["defaultRouteDomain"] end end  | 
  
.find_monitors(string) ⇒ Object
      52 53 54  | 
    
      # File 'lib/puppet/provider/f5.rb', line 52 def self.find_monitors(string) transport.find_monitors(string) end  | 
  
.find_profile_type(profile) ⇒ Object
Find the type of a given profile in the profile cache, or if it is not found try reloading the cache and looking again.
      181 182 183 184 185 186  | 
    
      # File 'lib/puppet/provider/f5.rb', line 181 def self.find_profile_type(profile) profiles = @@profile_cache ||= sort_profiles if profiles[profile] profiles[profile] end end  | 
  
.get_partitions ⇒ Object
      221 222 223 224 225 226  | 
    
      # File 'lib/puppet/provider/f5.rb', line 221 def self.get_partitions Puppet::Provider::F5.call_items("/mgmt/tm/auth/partition").inject({}) do |memo,partition| memo[partition["name"]] = partition memo end end  | 
  
.integer?(str) ⇒ Boolean
      56 57 58 59 60  | 
    
      # File 'lib/puppet/provider/f5.rb', line 56 def self.integer?(str) !!Integer(str) rescue ArgumentError, TypeError false end  | 
  
.partition(path) ⇒ Object
      78 79 80  | 
    
      # File 'lib/puppet/provider/f5.rb', line 78 def self.partition(path) File.dirname(path).split('/')[1] end  | 
  
.post(url, message) ⇒ Object
      36 37 38  | 
    
      # File 'lib/puppet/provider/f5.rb', line 36 def self.post(url, ) transport.post(url, ) end  | 
  
.put(url, message) ⇒ Object
      40 41 42  | 
    
      # File 'lib/puppet/provider/f5.rb', line 40 def self.put(url, ) transport.put(url, ) end  | 
  
.sort_profiles ⇒ Object
Find all profiles on the F5 and associate them as <profile name> => <profile type> (profile names are unique for all profile types)
      198 199 200 201 202 203 204 205 206 207 208 209  | 
    
      # File 'lib/puppet/provider/f5.rb', line 198 def self.sort_profiles profile_types = Puppet::Provider::F5.call_items("/mgmt/tm/ltm/profile").collect do |hash| hash["reference"]["link"].match(%r{([^/]+)\?})[1] end profile_types.inject({}) do |memo,profile_type| profile_array = Puppet::Provider::F5.call_items("/mgmt/tm/ltm/profile/#{profile_type}") || [] profile_hash = profile_array.inject({}) do |m,profile| m.merge!(profile["fullPath"] => profile_type) end memo.merge! profile_hash end end  | 
  
.transport ⇒ Object
      10 11 12 13 14 15 16 17 18  | 
    
      # File 'lib/puppet/provider/f5.rb', line 10 def self.transport if Puppet::Util::NetworkDevice.current #we are in `puppet device` Puppet::Util::NetworkDevice.current.transport else #we are in `puppet resource` Puppet::Util::NetworkDevice::Transport::F5.new(Facter.value(:url)) end end  | 
  
Instance Method Details
#api_name ⇒ Object
      86 87 88  | 
    
      # File 'lib/puppet/provider/f5.rb', line 86 def api_name "~#{partition}~#{basename}" end  | 
  
#basename ⇒ Object
      82 83 84  | 
    
      # File 'lib/puppet/provider/f5.rb', line 82 def basename File.basename(resource[:name]) end  | 
  
#convert_underscores(hash) ⇒ Object
      155 156 157 158 159 160 161 162 163 164 165  | 
    
      # File 'lib/puppet/provider/f5.rb', line 155 def convert_underscores(hash) # Here lies some evil magic. We want to replace all _'s with -'s in the # key names of the hash we create from the object we've passed into message. # # We do this by passing in an object along with .each, giving us an empty # hash to then build up with the fixed names. hash.each_with_object({}) do |(k ,v), obj| key = k.to_s.gsub(/_/, '-').to_sym obj[key] = v end end  | 
  
#create_message(basename, partition, hash) ⇒ Object
      90 91 92 93 94 95 96 97  | 
    
      # File 'lib/puppet/provider/f5.rb', line 90 def (basename, partition, hash) # Create the message by stripping :present. new_hash = hash.reject { |k, _| [:ensure, :provider, Puppet::Type.].flatten.include?(k) } new_hash[:name] = basename new_hash[:partition] = partition return new_hash end  | 
  
#destination_conversion(message) ⇒ Object
      122 123 124 125 126 127 128 129 130 131 132  | 
    
      # File 'lib/puppet/provider/f5.rb', line 122 def destination_conversion() if [:'alias-address'] and [:'alias-service-port'] [:destination] = "#{[:'alias-address']}:#{[:'alias-service-port']}" elsif [:'alias-address'] [:destination] = [:'alias-address'] end .delete(:'alias-address') .delete(:'alias-service-port') return end  | 
  
#filters_conversion(message) ⇒ Object
We need to convert our puppet array into a space seperated string.
      144 145 146 147 148 149 150 151 152 153  | 
    
      # File 'lib/puppet/provider/f5.rb', line 144 def filters_conversion() if [:filter] [:filter] = [:filter].join(' ') end if [:filterNeg] [:filterNeg] = [:filterNeg].join(' ') end return end  | 
  
#headers_conversion(message) ⇒ Object
We need to convert our puppet array into a n seperated string.
      135 136 137 138 139 140 141  | 
    
      # File 'lib/puppet/provider/f5.rb', line 135 def headers_conversion() if [:headers] [:headers] = [:headers].join("\n") end return end  | 
  
#monitor_conversion(hash) ⇒ Object
      106 107 108 109 110 111 112 113 114 115 116 117 118 119 120  | 
    
      # File 'lib/puppet/provider/f5.rb', line 106 def monitor_conversion(hash) = hash # If monitor is an array then we need to rebuild the message. if hash[:availability] if hash[:availability] == "all" [:monitor] = Array(hash[:monitor]).join(' and ') elsif hash[:availability] > 0 [:monitor] = "min #{hash[:availability]} of #{Array(hash[:monitor]).join(' ')}" end hash.delete(:availability) else [:monitor] = Array(hash[:monitor]).join(' and ') end .merge(hash) end  | 
  
#partition ⇒ Object
      74 75 76  | 
    
      # File 'lib/puppet/provider/f5.rb', line 74 def partition self.class.partition(resource[:name]) end  | 
  
#rename_keys(keys_to_rename, rename_hash) ⇒ Object
This allows us to simply rename keys from the puppet representation to the F5 representation.
      64 65 66 67 68 69 70 71 72  | 
    
      # File 'lib/puppet/provider/f5.rb', line 64 def rename_keys(keys_to_rename, rename_hash) keys_to_rename.each do |k, v| next unless rename_hash[k] value = rename_hash[k] rename_hash.delete(k) rename_hash[v] = value end return rename_hash end  | 
  
#string_to_integer(hash) ⇒ Object
      99 100 101 102 103 104  | 
    
      # File 'lib/puppet/provider/f5.rb', line 99 def string_to_integer(hash) # Apply transformations hash.each do |k, v| hash[k] = Integer(v) if self.class.integer?(v) end end  | 
  
#strip_elements(hash, elements_to_strip) ⇒ Object
      167 168 169 170 171  | 
    
      # File 'lib/puppet/provider/f5.rb', line 167 def strip_elements(hash, elements_to_strip) = hash.reject { |k, _| elements_to_strip.include?(k) } return end  | 
  
#strip_nil_values(hash) ⇒ Object
For some reason the object we pass in has undefined parameters in the object with nil values. Not at all helpful for us.
      175 176 177  | 
    
      # File 'lib/puppet/provider/f5.rb', line 175 def strip_nil_values(hash) hash.reject { |k, v| v.nil? } end  |