Class: Vra::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/vra/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (readonly)

Returns the value of attribute client.



24
25
26
# File 'lib/vra/request.rb', line 24

def client
  @client
end

#idObject (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

Returns:

  • (Boolean)


56
57
58
# File 'lib/vra/request.rb', line 56

def completed?
  successful? || failed?
end

#completion_detailsObject



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_stateObject



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

Returns:

  • (Boolean)


64
65
66
# File 'lib/vra/request.rb', line 64

def failed?
  status == "FAILED"
end

#refreshObject



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_emptyObject



41
42
43
# File 'lib/vra/request.rb', line 41

def refresh_if_empty
  refresh if request_empty?
end

#request_empty?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/vra/request.rb', line 45

def request_empty?
  @request_data.nil?
end

#resourcesObject



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

#statusObject



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

Returns:

  • (Boolean)


60
61
62
# File 'lib/vra/request.rb', line 60

def successful?
  status == "SUCCESSFUL"
end