Class: Infoblox::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/infoblox/resource.rb

Direct Known Subclasses

Host, Ipv4addr, Network

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Resource



60
61
62
63
64
# File 'lib/infoblox/resource.rb', line 60

def initialize(attrs={})
  attrs.each do |k,v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#_refObject

Returns the value of attribute _ref.



3
4
5
# File 'lib/infoblox/resource.rb', line 3

def _ref
  @_ref
end

Class Method Details

.allObject

Return an array of all records for this resource.



27
28
29
30
31
# File 'lib/infoblox/resource.rb', line 27

def self.all
  JSON.parse(connection.get(resource_uri).body).map do |item|
    new(item)
  end
end

.connectionObject



48
49
50
# File 'lib/infoblox/resource.rb', line 48

def self.connection
  @@connection
end

.connection=(con) ⇒ Object



52
53
54
# File 'lib/infoblox/resource.rb', line 52

def self.connection=(con)
  @@connection = con
end

.find(params) ⇒ Object

Find resources with query parameters.

Example: return extensible attributes for every resource.

{"_return_fields" => "extensible_attributes"}

Example: filter resources by name.

{"name~" => "foo.*bar"}


42
43
44
45
46
# File 'lib/infoblox/resource.rb', line 42

def self.find(params)
  JSON.parse(connection.get(resource_uri, params).body).map do |item|
    new(item)
  end
end

.remote_attr_accessor(*args) ⇒ Object

Define a writeable remote attribute, i.e. one that should show up in post / put operations.



13
14
15
16
17
18
# File 'lib/infoblox/resource.rb', line 13

def self.remote_attr_accessor(*args)
  args.each do |a|
    attr_accessor a
    remote_attrs << a
  end
end

.remote_attrsObject



20
21
22
# File 'lib/infoblox/resource.rb', line 20

def self.remote_attrs
  @remote_attrs ||= []
end

.resource_uriObject



56
57
58
# File 'lib/infoblox/resource.rb', line 56

def self.resource_uri
  BASE_PATH + self.wapi_object
end

.wapi_object(obj = nil) ⇒ Object



5
6
7
# File 'lib/infoblox/resource.rb', line 5

def self.wapi_object(obj=nil)
  obj.nil? ? @wapi_object : @wapi_object = obj
end

Instance Method Details

#createObject



66
67
68
69
# File 'lib/infoblox/resource.rb', line 66

def create
  self._ref = connection.post(resource_uri, remote_attribute_hash).body
  true
end

#deleteObject



71
72
73
# File 'lib/infoblox/resource.rb', line 71

def delete
  connection.delete(resource_uri).status == 200
end

#get(params = {}) ⇒ Object



75
76
77
# File 'lib/infoblox/resource.rb', line 75

def get(params={})
  connection.get(resource_uri, params)
end

#remote_attribute_hashObject



83
84
85
86
87
88
89
# File 'lib/infoblox/resource.rb', line 83

def remote_attribute_hash
  {}.tap do |hsh|
    self.class.remote_attrs.each do |k|
      hsh[k] = self.send(k)
    end
  end
end

#resource_uriObject



79
80
81
# File 'lib/infoblox/resource.rb', line 79

def resource_uri
  self._ref.nil? ? self.class.resource_uri : (BASE_PATH + self._ref)
end