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



191
192
193
# File 'lib/puppet/provider/f5.rb', line 191

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



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_partitionsObject



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

Returns:

  • (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, 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 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

.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



86
87
88
# File 'lib/puppet/provider/f5.rb', line 86

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

#basenameObject



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



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/puppet/provider/f5.rb', line 122

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.



144
145
146
147
148
149
150
151
152
153
# File 'lib/puppet/provider/f5.rb', line 144

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.



135
136
137
138
139
140
141
# File 'lib/puppet/provider/f5.rb', line 135

def headers_conversion(message)
  if message[:headers]
    message[:headers] = message[:headers].join("\n")
  end

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



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)
  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.



175
176
177
# File 'lib/puppet/provider/f5.rb', line 175

def strip_nil_values(hash)
  hash.reject { |k, v| v.nil? }
end