Class: Puppet::Provider::F5

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet/provider/f5.rb

Direct Known Subclasses

F5Virtualserver

Class Method Summary collapse

Instance Method Summary collapse

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_cacheObject

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

.connectionObject



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_partitionsObject



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

Returns:

  • (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, message)
  transport.patch(url, message)
end

.post(url, message) ⇒ Object



36
37
38
# File 'lib/puppet/provider/f5.rb', line 36

def self.post(url, message)
  transport.post(url, message)
end

.put(url, message) ⇒ Object



40
41
42
# File 'lib/puppet/provider/f5.rb', line 40

def self.put(url, message)
  transport.put(url, message)
end

.sort_profilesObject

Find all profiles on the F5 and associate them as => (profile names are unique for all profile types)



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

.transportObject



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_nameObject



90
91
92
# File 'lib/puppet/provider/f5.rb', line 90

def api_name
  "~#{partition}~#{basename}"
end

#basenameObject



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 create_message(basename, partition, hash)
  # Create the message by stripping :present.
  new_hash            = hash.reject { |k, _| [:ensure, :provider, Puppet::Type.metaparams].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(message)
  if message[:'alias-address'] and message[:'alias-service-port']
    message[:destination] = "#{message[:'alias-address']}:#{message[:'alias-service-port']}"
  elsif message[:'alias-address']
    message[:destination] = message[:'alias-address']
  end
  message.delete(:'alias-address')
  message.delete(:'alias-service-port')

  return message
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(message)
  if message[:filter]
    message[:filter] = message[:filter].join(' ')
  end
  if message[:filterNeg]
    message[:filterNeg] = message[:filterNeg].join(' ')
  end

  return message
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(message)
  if message[:headers]
    message[:headers] = message[:headers].join("\n")
  end

  return message
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)
  message = hash
  # If monitor is an array then we need to rebuild the message.
  if hash[:availability]
    if hash[:availability] == "all"
      message[:monitor] = Array(hash[:monitor]).join(' and ')
    elsif hash[:availability] > 0
      message[:monitor] = "min #{hash[:availability]} of #{Array(hash[:monitor]).join(' ')}"
    end
    hash.delete(:availability)
  else
    message[:monitor] = Array(hash[:monitor]).join(' and ')
  end
  message.merge(hash)
end

#partitionObject



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)
  message = hash.reject { |k, _| elements_to_strip.include?(k) }

  return message
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