Class: Puppet::Util::NetworkDevice::Transport::F5
- Inherits:
 - 
      Base
      
        
- Object
 - Base
 - Puppet::Util::NetworkDevice::Transport::F5
 
 
- Defined in:
 - lib/puppet/util/network_device/transport/f5.rb
 
Instance Attribute Summary collapse
- 
  
    
      #connection  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute connection.
 
Instance Method Summary collapse
- #call(url, args = {}) ⇒ Object
 - #delete(url) ⇒ Object
 - #failure?(result) ⇒ Boolean
 - 
  
    
      #find_availability(string)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Monitoring: Parse out the availability integer.
 - 
  
    
      #find_monitors(string)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Given a string containing objects matching /Partition/Object, return an array of all found objects.
 - 
  
    
      #initialize(url, _options = {})  ⇒ F5 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of F5.
 - #post(url, json) ⇒ Object
 - #put(url, json) ⇒ Object
 - #valid_json?(json) ⇒ Boolean
 
Constructor Details
#initialize(url, _options = {}) ⇒ F5
Returns a new instance of F5.
      8 9 10 11  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 8 def initialize(url, = {}) require 'faraday' @connection = Faraday.new(url: url, ssl: { verify: false }) end  | 
  
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
      6 7 8  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 6 def connection @connection end  | 
  
Instance Method Details
#call(url, args = {}) ⇒ Object
      13 14 15 16 17 18 19  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 13 def call(url, args={}) result = connection.get(url, args) JSON.parse(result.body) rescue JSON::ParserError # This should be better at handling errors return nil end  | 
  
#delete(url) ⇒ Object
      55 56 57 58 59  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 55 def delete(url) result = connection.delete(url) failure?(result) return result end  | 
  
#failure?(result) ⇒ Boolean
      21 22 23 24 25  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 21 def failure?(result) unless result.status == 200 fail("REST failure: HTTP status code #{result.status} detected. Body of failure is: #{result.body}") end end  | 
  
#find_availability(string) ⇒ Object
Monitoring: Parse out the availability integer.
      82 83 84 85 86 87 88 89 90 91 92 93 94  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 82 def find_availability(string) return nil if string.nil? if string == "default" or string == "none" return nil end # Look for integers within the string. matches = string.match(/min\s(\d+)/) if matches matches[1] else "all" end end  | 
  
#find_monitors(string) ⇒ Object
Given a string containing objects matching /Partition/Object, return an array of all found objects.
      70 71 72 73 74 75 76 77 78 79  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 70 def find_monitors(string) return nil if string.nil? if string == "default" ["default"] elsif string =~ %r{/none$} ["none"] else string.scan(/(\/\S+)/).flatten end end  | 
  
#post(url, json) ⇒ Object
      27 28 29 30 31 32 33 34 35 36 37 38 39  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 27 def post(url, json) if valid_json?(json) result = connection.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.body = json end failure?(result) return result else fail('Invalid JSON detected.') end end  | 
  
#put(url, json) ⇒ Object
      41 42 43 44 45 46 47 48 49 50 51 52 53  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 41 def put(url, json) if valid_json?(json) result = connection.put do |req| req.url url req.headers['Content-Type'] = 'application/json' req.body = json end failure?(result) return result else fail('Invalid JSON detected.') end end  | 
  
#valid_json?(json) ⇒ Boolean
      61 62 63 64 65 66  | 
    
      # File 'lib/puppet/util/network_device/transport/f5.rb', line 61 def valid_json?(json) JSON.parse(json) return true rescue return false end  |