Class: Saklient::Cloud::Resources::Resource
- Inherits:
-
Object
- Object
- Saklient::Cloud::Resources::Resource
show all
- Defined in:
- lib/saklient/cloud/resources/resource.rb
Direct Known Subclasses
Appliance, Archive, Bridge, CommonServiceItem, CommonServiceProvider, Disk, DiskPlan, Icon, Iface, Ipv4Net, Ipv6Net, IsoImage, License, LicenseInfo, Region, Router, RouterPlan, Script, Server, ServerInstance, ServerPlan, Swytch
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client) ⇒ Resource
Returns a new instance of Resource.
91
92
93
94
95
|
# File 'lib/saklient/cloud/resources/resource.rb', line 91
def initialize(client)
Saklient::Util::validate_type(client, 'Saklient::Cloud::Client')
@_client = client
@_query = {}
end
|
Instance Attribute Details
32
33
34
|
# File 'lib/saklient/cloud/resources/resource.rb', line 32
def client
@client
end
|
Class Method Details
.create_with(className, client, obj, wrapped = false) ⇒ Resource
296
297
298
299
300
301
302
303
304
305
306
|
# File 'lib/saklient/cloud/resources/resource.rb', line 296
def self.create_with(className, client, obj, wrapped = false)
Saklient::Util::validate_type(className, 'String')
Saklient::Util::validate_type(client, 'Saklient::Cloud::Client')
Saklient::Util::validate_type(wrapped, 'bool')
a = [
client,
obj,
wrapped
]
return Saklient::Util::create_class_instance('saklient.cloud.resources.' + className, a)
end
|
Instance Method Details
#_class_name ⇒ String
79
80
81
|
# File 'lib/saklient/cloud/resources/resource.rb', line 79
def _class_name
return nil
end
|
#_id ⇒ String
85
86
87
|
# File 'lib/saklient/cloud/resources/resource.rb', line 85
def _id
return nil
end
|
#api_deserialize(obj, wrapped = false) ⇒ void
This method returns an undefined value.
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/saklient/cloud/resources/resource.rb', line 154
def api_deserialize(obj, wrapped = false)
Saklient::Util::validate_type(wrapped, 'bool')
root = nil
record = nil
rkey = _root_key
if !(obj).nil?
if !wrapped
if !(rkey).nil?
root = {}
root[rkey.to_sym] = obj
end
record = obj
else
root = obj
record = obj[rkey.to_sym]
end
end
_on_before_api_deserialize(record, root)
api_deserialize_impl(record)
_on_after_api_deserialize(record, root)
end
|
#api_serialize(withClean = false) ⇒ any
191
192
193
194
195
196
197
|
# File 'lib/saklient/cloud/resources/resource.rb', line 191
def api_serialize(withClean = false)
Saklient::Util::validate_type(withClean, 'bool')
_on_before_api_serialize(withClean)
ret = api_serialize_impl(withClean)
_on_after_api_serialize(ret, withClean)
return ret
end
|
#destroy ⇒ void
This method returns an undefined value.
このローカルオブジェクトのIDと一致するリソースの削除リクエストをAPIに送信します.
249
250
251
252
253
|
# File 'lib/saklient/cloud/resources/resource.rb', line 249
def destroy
return nil if @is_new
path = _api_path + '/' + Saklient::Util::url_encode(_id)
request_retry('DELETE', path)
end
|
#dump ⇒ any
286
287
288
|
# File 'lib/saklient/cloud/resources/resource.rb', line 286
def dump
return api_serialize(true)
end
|
#exists ⇒ bool
275
276
277
278
279
280
281
282
|
# File 'lib/saklient/cloud/resources/resource.rb', line 275
def exists
query = {}
Saklient::Util::set_by_path(query, 'Filter.ID', [_id])
Saklient::Util::set_by_path(query, 'Include', ['ID'])
result = request_retry('GET', _api_path, query)
cnt = result[:Count]
return cnt == 1
end
|
#request_retry(method, path, query = nil, retryCount = 5, retrySleep = 5) ⇒ any
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
# File 'lib/saklient/cloud/resources/resource.rb', line 314
def request_retry(method, path, query = nil, retryCount = 5, retrySleep = 5)
Saklient::Util::validate_type(method, 'String')
Saklient::Util::validate_type(path, 'String')
Saklient::Util::validate_type(retryCount, 'Fixnum')
Saklient::Util::validate_type(retrySleep, 'Fixnum')
ret = nil
while 1 < retryCount do
isOk = false
begin
ret = @_client.request(method, path, query)
isOk = true
rescue Saklient::Errors::HttpException
isOk = false
end
if isOk
retryCount = -1
else
retryCount -= 1
sleep(retrySleep)
end
end
ret = @_client.request(method, path, query) if retryCount == 0
return ret
end
|
#set_param(key, value) ⇒ void
This method returns an undefined value.
50
51
52
53
|
# File 'lib/saklient/cloud/resources/resource.rb', line 50
def set_param(key, value)
Saklient::Util::validate_type(key, 'String')
@_query[key.to_sym] = value
end
|