Class: Occi::Resource

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/probe/occi/nocci/resource.rb

Overview

OCCI Resource class.

Direct Known Subclasses

Compute, Network, Storage

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Resource



24
25
26
27
28
29
30
31
# File 'lib/probe/occi/nocci/resource.rb', line 24

def initialize(connection)
  self.class.base_uri "#{connection[:endpoint]}"
  # nebula OCCI format
  self.class.basic_auth "#{connection[:auth][:username]}", Digest::SHA1.hexdigest(connection[:auth][:password])

  # Low-level debugging
  # self.class.debug_output
end

Class Method Details

.inherited(childclass) ⇒ Object

Callback invoked whenever a subclass is created. This method dynamically defines virtual @endpoint attribute located in child instance, which contains backslash + name of inheriting class. It is used for request building.



36
37
38
39
40
41
42
# File 'lib/probe/occi/nocci/resource.rb', line 36

def self.inherited(childclass)
  super(childclass)

  path = childclass.to_s.split('::').last.downcase

  childclass.send(:define_method, :endpoint) { "/#{path}" }
end

Instance Method Details

#allObject

Returns the contents of the pool. 200 OK: An XML representation of the pool in the http body. This means query the point /network, /storage etc.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/probe/occi/nocci/resource.rb', line 51

def all
  begin
    response = self.class.get(endpoint)
  rescue => e
    raise e.class, 'Could not initiate basic endpoint connectivity query, maybe HTTP/SSL server problem?'
  ensure
    if !response.nil?
      fail HTTPResponseError, "Basic pool availibility request failed! #{response.body}" unless response.code.between?(200, 300)
      response.body
    else
      fail HTTPResponseError, 'Basic pool availibility request failed!'
    end
  end
end

#entity(id) ⇒ Object



44
45
46
# File 'lib/probe/occi/nocci/resource.rb', line 44

def entity(id)
  "#{endpoint}/#{id}"
end

#find(id) ⇒ Object

Returns the representation of specific resource identified by id. 200 OK: An XML representation of the pool in the http body.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/probe/occi/nocci/resource.rb', line 68

def find(id)
  begin
    response = self.class.get(entity(id))
  rescue => e
    raise e.class, 'Could not initiate specific resource query, maybe HTTP/SSL server problem?'
  ensure
    if !response.nil?
      fail HTTPResponseError, "Specific resource request failed! #{response.body}" unless response.code.between?(200, 300)
      response.body
    else
      fail HTTPResponseError, 'Specific resource request failed!'
    end
  end
end