Class: Vra::Deployment

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

Overview

Class that represents the Deployment Object

Constant Summary collapse

INDEX_URL =
"/deployment/api/deployments"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, opts = {}) ⇒ Deployment

Returns a new instance of Deployment.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vra/deployment.rb', line 29

def initialize(client, opts = {})
  @client = client
  @id     = opts[:id]
  @data   = opts[:data]
  validate!

  if @data.nil?
    refresh
  elsif @id.nil?
    @id = @data["id"]
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



27
28
29
# File 'lib/vra/deployment.rb', line 27

def id
  @id
end

Instance Method Details

#action_id_by_name(action_name) ⇒ Object



82
83
84
85
86
87
# File 'lib/vra/deployment.rb', line 82

def action_id_by_name(action_name)
  action = actions.find { |x| x["name"] == action_name }
  return if action.nil?

  action["id"]
end

#actionsObject



78
79
80
# File 'lib/vra/deployment.rb', line 78

def actions
  @actions = client.get_parsed("/deployment/api/deployments/#{id}/actions")
end

#blueprint_idObject



54
55
56
# File 'lib/vra/deployment.rb', line 54

def blueprint_id
  @data["blueprintId"]
end

#completed?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/vra/deployment.rb', line 74

def completed?
  successful? || failed?
end

#descriptionObject



46
47
48
# File 'lib/vra/deployment.rb', line 46

def description
  @data["description"]
end

#destroy(reason = "") ⇒ Object



111
112
113
114
115
116
# File 'lib/vra/deployment.rb', line 111

def destroy(reason = "")
  action_id = action_id_by_name("Delete")
  raise Vra::Exception::NotFound, "No destroy action found for resource #{@id}" if action_id.nil?

  submit_action_request(action_id, reason)
end

#failed?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/vra/deployment.rb', line 70

def failed?
  status == "CREATE_FAILED"
end

#nameObject



42
43
44
# File 'lib/vra/deployment.rb', line 42

def name
  @data["name"]
end

#org_idObject



50
51
52
# File 'lib/vra/deployment.rb', line 50

def org_id
  @data["orgId"]
end

#ownerObject



58
59
60
# File 'lib/vra/deployment.rb', line 58

def owner
  @data["ownedBy"]
end

#power_off(reason = "") ⇒ Object



118
119
120
121
122
123
# File 'lib/vra/deployment.rb', line 118

def power_off(reason = "")
  action_id = action_id_by_name("PowerOff")
  raise Vra::Exception::NotFound, "No power-off action found for resource #{@id}" if action_id.nil?

  submit_action_request(action_id, reason)
end

#power_on(reason = nil) ⇒ Object



125
126
127
128
129
130
# File 'lib/vra/deployment.rb', line 125

def power_on(reason = nil)
  action_id = action_id_by_name("PowerOn")
  raise Vra::Exception::NotFound, "No power-on action found for resource #{@id}" if action_id.nil?

  submit_action_request(action_id, reason)
end

#refreshObject



105
106
107
108
109
# File 'lib/vra/deployment.rb', line 105

def refresh
  @data = client.get_parsed("/deployment/api/deployments/#{id}")
rescue Vra::Exception::HTTPNotFound
  raise Vra::Exception::NotFound, "deployment with ID #{id} does not exist"
end

#requestsObject



99
100
101
102
103
# File 'lib/vra/deployment.rb', line 99

def requests
  response = client.get_parsed("/deployment/api/deployments/#{id}/requests")

  response["content"].map! { |x| Vra::Request.new(client, id, id: x["id"], data: x) }
end

#resource_by_id(res_id) ⇒ Object



95
96
97
# File 'lib/vra/deployment.rb', line 95

def resource_by_id(res_id)
  Vra::Resource.new(client, id, id: res_id)
end

#resourcesObject



89
90
91
92
93
# File 'lib/vra/deployment.rb', line 89

def resources
  response = client.get_parsed("/deployment/api/deployments/#{id}/resources")

  response["content"].map! { |x| Vra::Resource.new(client, id, data: x) }
end

#statusObject



62
63
64
# File 'lib/vra/deployment.rb', line 62

def status
  @data["status"]
end

#successful?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/vra/deployment.rb', line 66

def successful?
  status == "CREATE_SUCCESSFUL"
end