class F5::Icontrol::RAPI

Public Class Methods

new(method_chain = nil, **args) click to toggle source
# File lib/f5/icontrol/rapi.rb, line 9
def initialize(method_chain = nil, **args)
  @method_chain = method_chain || ''
  @args = args
end

Public Instance Methods

create(options = {}) click to toggle source
# File lib/f5/icontrol/rapi.rb, line 43
def create(options = {})
  response = RestClient::Request.execute(method: :post,
                                         url: url,
                                         user: @args[:username],
                                         password: @args[:password],
                                         verify_ssl: OpenSSL::SSL::VERIFY_NONE,
                                         payload: options.to_json,
                                         headers: { "content-type" => "application/json" }
                                        )
  JSON.parse response.body
end
each(&block) click to toggle source
# File lib/f5/icontrol/rapi.rb, line 60
def each(&block)
  get_collection.each &block
end
get_collection() click to toggle source
# File lib/f5/icontrol/rapi.rb, line 31
def get_collection
  response = RestClient::Request.execute(method: :get,
                                         url: "#{url}/",
                                         user: @args[:username],
                                         password: @args[:password],
                                         verify_ssl: OpenSSL::SSL::VERIFY_NONE
                                     )
  objects = JSON.parse response.body

  objects['items'].map { |r| Resource.new r, @args }
end
load(resource = nil) click to toggle source
# File lib/f5/icontrol/rapi.rb, line 14
def load(resource = nil)
  tail = resource.nil? ? '' : "/#{resource}"
  response = RestClient::Request.execute(method: :get,
                                         url: "#{url}#{tail}",
                                         user: @args[:username],
                                         password: @args[:password],
                                         verify_ssl: OpenSSL::SSL::VERIFY_NONE
                                     )
  object = JSON.parse response.body

  if object.has_key? 'items'
    object['items'].map { |r| Resource.new r, @args }
  else
    Resource.new object, @args
  end
end
method_missing(method, *args, &block) click to toggle source
# File lib/f5/icontrol/rapi.rb, line 55
def method_missing(method, *args, &block)
  new_method_chain = @method_chain == '/' ? '': "#{@method_chain}/"
  F5::Icontrol::RAPI.new("#{new_method_chain}#{method}", @args)
end

Private Instance Methods

url() click to toggle source
# File lib/f5/icontrol/rapi.rb, line 65
def url
  pool_match = @method_chain.match %r{(/pool/[A-Za-z0-9\-_~]+)}
  method_chain = @method_chain.tr '_', '-'
  method_chain = method_chain.sub %r{/pool/[A-Za-z0-9\-_~]+}, pool_match[1] unless pool_match.nil?
  method_chain.gsub! %r{^/}, ''
  "https://#{@args[:host]}/#{method_chain}"
end