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
- .patch(url, message) ⇒ Object
- .post(url, message) ⇒ Object
- .put(url, message) ⇒ Object
-
.sort_profiles ⇒ Object
Find all profiles on the F5 and associate them as
=> (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
195 196 197 |
# File 'lib/puppet/provider/f5.rb', line 195 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
48 49 50 |
# File 'lib/puppet/provider/f5.rb', line 48 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
52 53 54 |
# File 'lib/puppet/provider/f5.rb', line 52 def self.find_availability(string) transport.find_availability(string) end |
.find_default_route_domain(partition) ⇒ Object
215 216 217 218 219 220 221 222 223 |
# File 'lib/puppet/provider/f5.rb', line 215 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
56 57 58 |
# File 'lib/puppet/provider/f5.rb', line 56 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.
185 186 187 188 189 190 |
# File 'lib/puppet/provider/f5.rb', line 185 def self.find_profile_type(profile) profiles = @@profile_cache ||= sort_profiles if profiles[profile] profiles[profile] end end |
.get_partitions ⇒ Object
225 226 227 228 229 230 |
# File 'lib/puppet/provider/f5.rb', line 225 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
60 61 62 63 64 |
# File 'lib/puppet/provider/f5.rb', line 60 def self.integer?(str) !!Integer(str) rescue ArgumentError, TypeError false end |
.partition(path) ⇒ Object
82 83 84 |
# File 'lib/puppet/provider/f5.rb', line 82 def self.partition(path) File.dirname(path).split('/')[1] end |
.patch(url, message) ⇒ Object
44 45 46 |
# File 'lib/puppet/provider/f5.rb', line 44 def self.patch(url, ) transport.patch(url, ) 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
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/puppet/provider/f5.rb', line 202 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
90 91 92 |
# File 'lib/puppet/provider/f5.rb', line 90 def api_name "~#{partition}~#{basename}" end |
#basename ⇒ Object
86 87 88 |
# File 'lib/puppet/provider/f5.rb', line 86 def basename File.basename(resource[:name]) end |
#convert_underscores(hash) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/puppet/provider/f5.rb', line 159 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
94 95 96 97 98 99 100 101 |
# File 'lib/puppet/provider/f5.rb', line 94 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
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/puppet/provider/f5.rb', line 126 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.
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/puppet/provider/f5.rb', line 148 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.
139 140 141 142 143 144 145 |
# File 'lib/puppet/provider/f5.rb', line 139 def headers_conversion() if [:headers] [:headers] = [:headers].join("\n") end return end |
#monitor_conversion(hash) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/puppet/provider/f5.rb', line 110 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
78 79 80 |
# File 'lib/puppet/provider/f5.rb', line 78 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.
68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/provider/f5.rb', line 68 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
103 104 105 106 107 108 |
# File 'lib/puppet/provider/f5.rb', line 103 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
171 172 173 174 175 |
# File 'lib/puppet/provider/f5.rb', line 171 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.
179 180 181 |
# File 'lib/puppet/provider/f5.rb', line 179 def strip_nil_values(hash) hash.reject { |k, v| v.nil? } end |