Class: Vra::Request
- Inherits:
-
Object
- Object
- Vra::Request
- Defined in:
- lib/vra/request.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #completion_details ⇒ Object
- #completion_state ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(client, id) ⇒ Request
constructor
A new instance of Request.
- #refresh ⇒ Object
- #refresh_if_empty ⇒ Object
- #request_empty? ⇒ Boolean
- #resources ⇒ Object
- #status ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(client, id) ⇒ Request
Returns a new instance of Request.
25 26 27 28 29 30 31 32 33 |
# File 'lib/vra/request.rb', line 25 def initialize(client, id) @client = client @id = id @request_data = nil @status = nil @completion_state = nil @completion_details = nil end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
24 25 26 |
# File 'lib/vra/request.rb', line 24 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'lib/vra/request.rb', line 24 def id @id end |
Instance Method Details
#completed? ⇒ Boolean
56 57 58 |
# File 'lib/vra/request.rb', line 56 def completed? successful? || failed? end |
#completion_details ⇒ Object
75 76 77 78 79 80 |
# File 'lib/vra/request.rb', line 75 def completion_details refresh_if_empty return if request_empty? @request_data["requestCompletion"]["completionDetails"] end |
#completion_state ⇒ Object
68 69 70 71 72 73 |
# File 'lib/vra/request.rb', line 68 def completion_state refresh_if_empty return if request_empty? @request_data["requestCompletion"]["requestCompletionState"] end |
#failed? ⇒ Boolean
64 65 66 |
# File 'lib/vra/request.rb', line 64 def failed? status == "FAILED" end |
#refresh ⇒ Object
35 36 37 38 39 |
# File 'lib/vra/request.rb', line 35 def refresh @request_data = client.get_parsed("/catalog-service/api/consumer/requests/#{@id}") rescue Vra::Exception::HTTPNotFound raise Vra::Exception::NotFound, "request ID #{@id} is not found" end |
#refresh_if_empty ⇒ Object
41 42 43 |
# File 'lib/vra/request.rb', line 41 def refresh_if_empty refresh if request_empty? end |
#request_empty? ⇒ Boolean
45 46 47 |
# File 'lib/vra/request.rb', line 45 def request_empty? @request_data.nil? end |
#resources ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/vra/request.rb', line 82 def resources begin request_resources = client.http_get_paginated_array!("/catalog-service/api/consumer/requests/#{@id}/resources") rescue Vra::Exception::HTTPNotFound raise Vra::Exception::NotFound, "resources for request ID #{@id} are not found" end request_resources.map { |resource| Vra::Resource.new(client, data: resource) } end |
#status ⇒ Object
49 50 51 52 53 54 |
# File 'lib/vra/request.rb', line 49 def status refresh_if_empty return if request_empty? @request_data["phase"] end |
#successful? ⇒ Boolean
60 61 62 |
# File 'lib/vra/request.rb', line 60 def successful? status == "SUCCESSFUL" end |