Class: Vra::Deployment
- Inherits:
-
Object
- Object
- Vra::Deployment
- 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
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #action_id_by_name(action_name) ⇒ Object
- #actions ⇒ Object
- #blueprint_id ⇒ Object
- #completed? ⇒ Boolean
- #description ⇒ Object
- #destroy(reason = "") ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(client, opts = {}) ⇒ Deployment
constructor
A new instance of Deployment.
- #name ⇒ Object
- #org_id ⇒ Object
- #owner ⇒ Object
- #power_off(reason = "") ⇒ Object
- #power_on(reason = nil) ⇒ Object
- #refresh ⇒ Object
- #requests ⇒ Object
- #resource_by_id(res_id) ⇒ Object
- #resources ⇒ Object
- #status ⇒ Object
- #successful? ⇒ Boolean
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
#id ⇒ Object (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 |
#actions ⇒ Object
78 79 80 |
# File 'lib/vra/deployment.rb', line 78 def actions @actions = client.get_parsed("/deployment/api/deployments/#{id}/actions") end |
#blueprint_id ⇒ Object
54 55 56 |
# File 'lib/vra/deployment.rb', line 54 def blueprint_id @data["blueprintId"] end |
#completed? ⇒ Boolean
74 75 76 |
# File 'lib/vra/deployment.rb', line 74 def completed? successful? || failed? end |
#description ⇒ Object
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
70 71 72 |
# File 'lib/vra/deployment.rb', line 70 def failed? status == "CREATE_FAILED" end |
#name ⇒ Object
42 43 44 |
# File 'lib/vra/deployment.rb', line 42 def name @data["name"] end |
#org_id ⇒ Object
50 51 52 |
# File 'lib/vra/deployment.rb', line 50 def org_id @data["orgId"] end |
#owner ⇒ Object
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 |
#refresh ⇒ Object
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 |
#requests ⇒ Object
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 |
#resources ⇒ Object
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 |
#status ⇒ Object
62 63 64 |
# File 'lib/vra/deployment.rb', line 62 def status @data["status"] end |
#successful? ⇒ Boolean
66 67 68 |
# File 'lib/vra/deployment.rb', line 66 def successful? status == "CREATE_SUCCESSFUL" end |