Class: ERPC::CloudResourcesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/erpc_sdk/rest.rb

Constant Summary collapse

RESOURCE_KINDS =
CloudCatalogClient::RESOURCE_KINDS
RESOURCE_MODES =
CloudCatalogClient::RESOURCE_MODES
BILLING_STATUSES =
%w[active grace-period inactive suspended].freeze

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ CloudResourcesClient

Returns a new instance of CloudResourcesClient.



299
300
301
# File 'lib/erpc_sdk/rest.rb', line 299

def initialize(transport)
  @transport = transport
end

Instance Method Details

#get(resource_id) ⇒ Object



315
316
317
318
319
320
321
322
323
324
# File 'lib/erpc_sdk/rest.rb', line 315

def get(resource_id)
  value = @transport.get("/v4/cloud/resources/#{URLs.escape_path(normalize_id(resource_id))}")
  envelope = Validation.mapping(value)
  message = Validation.mapping(envelope["message"])
  raise InvalidResponseError unless envelope["success"] == true

  validate_resource(message["resource"])
rescue InvalidResponseError
  raise InvalidResponseError, "ERPC returned an invalid Cloud resource"
end

#get_status(resource_id) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/erpc_sdk/rest.rb', line 326

def get_status(resource_id)
  path = "/v4/cloud/resources/#{URLs.escape_path(normalize_id(resource_id))}/status"
  envelope = Validation.mapping(@transport.get(path))
  raise InvalidResponseError unless envelope["success"] == true

  status = Validation.mapping(envelope["message"])
  Validation.string(status["id"])
  Validation.string(status["status"])
  validate_billing(status["billing"]) if status.key?("billing")
  status
rescue InvalidResponseError
  raise InvalidResponseError, "ERPC returned an invalid Cloud resource status"
end

#listObject



303
304
305
306
307
308
309
310
311
312
313
# File 'lib/erpc_sdk/rest.rb', line 303

def list
  envelope = Validation.mapping(@transport.get("/v4/cloud/resources"))
  message = Validation.mapping(envelope["message"])
  resources = message["resources"]
  raise InvalidResponseError unless envelope["success"] == true && resources.is_a?(Array)

  resources.each { |resource| validate_resource(resource) }
  resources
rescue InvalidResponseError
  raise InvalidResponseError, "ERPC returned an invalid Cloud resource list"
end