Class: Openstack::Client::Manager
- Inherits:
-
Object
- Object
- Openstack::Client::Manager
show all
- Defined in:
- lib/openstack-client/base.rb
Constant Summary
collapse
- RESOURCE_CLASS =
Openstack::Client::Resource
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#_create(url, body, response_key, return_raw = false) ⇒ Object
-
#_delete(url) ⇒ Object
-
#_get(url, response_key) ⇒ Object
-
#_list(url, response_key, body = nil) ⇒ Object
-
#_update(url, body, response_key = nil, method = :put) ⇒ Object
-
#get_id(obj) ⇒ Object
-
#initialize(api) ⇒ Manager
constructor
A new instance of Manager.
-
#url_with_params(url, options = {}) ⇒ Object
Constructor Details
#initialize(api) ⇒ Manager
Returns a new instance of Manager.
66
67
68
69
|
# File 'lib/openstack-client/base.rb', line 66
def initialize api
self.api = api
self.resource_class = self.class::RESOURCE_CLASS
end
|
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
64
65
66
|
# File 'lib/openstack-client/base.rb', line 64
def api
@api
end
|
#resource_class ⇒ Object
Returns the value of attribute resource_class.
63
64
65
|
# File 'lib/openstack-client/base.rb', line 63
def resource_class
@resource_class
end
|
Instance Method Details
#_create(url, body, response_key, return_raw = false) ⇒ Object
111
112
113
114
115
116
117
118
|
# File 'lib/openstack-client/base.rb', line 111
def _create url, body, response_key, return_raw=false
resp, body = self.api.post(url, body)
if return_raw
return body[response_key]
else
return self.resource_class.new(self, body[response_key])
end
end
|
#_delete(url) ⇒ Object
120
121
122
|
# File 'lib/openstack-client/base.rb', line 120
def _delete url
self.api.delete(url)
end
|
#_get(url, response_key) ⇒ Object
106
107
108
109
|
# File 'lib/openstack-client/base.rb', line 106
def _get url, response_key
resp, body = self.api.get(url)
return self.resource_class.new(self, body[response_key])
end
|
#_list(url, response_key, body = nil) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/openstack-client/base.rb', line 89
def _list url, response_key, body=nil
if body
resp, body = self.api.post(url, body)
else
resp, body = self.api.get(url)
end
data = body[response_key]
data = data['values'] if data.kind_of? Hash
return [].tap do |rtn|
data.each do |d|
rtn << self.resource_class.new(self, d, true)
end
end
end
|
#_update(url, body, response_key = nil, method = :put) ⇒ Object
124
125
126
127
128
|
# File 'lib/openstack-client/base.rb', line 124
def _update url, body, response_key=nil, method=:put
resp, body = self.api.send(method, url, body)
return self.resource_class.new(self, body[response_key]) if body
return resp
end
|
#get_id(obj) ⇒ Object
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/openstack-client/base.rb', line 71
def get_id obj
if obj.kind_of? String
return obj
elsif obj.respond_to?(:id)
return obj.id
elsif obj.respond_to?(:uuid)
return obj.uuid
end
raise "No ID of this object: #{obj}"
end
|
#url_with_params(url, options = {}) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/openstack-client/base.rb', line 82
def url_with_params url, options={}
unless options.nil? || options.empty?
url += ('?' + options.to_a.map{|a| "#{a.first}=#{a.last}"}.join('&'))
end
URI.escape(url)
end
|