Class: Vra::Resource
- Inherits:
-
Object
- Object
- Vra::Resource
- Defined in:
- lib/vra/resource.rb
Constant Summary collapse
- VM_TYPES =
%w[ Cloud.vSphere.Machine Cloud.Machine ].freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#deployment_id ⇒ Object
readonly
Returns the value of attribute deployment_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#resource_data ⇒ Object
readonly
Returns the value of attribute resource_data.
Instance Method Summary collapse
- #fetch_resource_data ⇒ Object (also: #refresh)
-
#initialize(client, deployment_id, opts = {}) ⇒ Resource
constructor
A new instance of Resource.
- #ip_address ⇒ Object
- #name ⇒ Object
- #network_interfaces ⇒ Object
- #owner_names ⇒ Object
- #project_id ⇒ Object
- #properties ⇒ Object
- #status ⇒ Object
- #vm? ⇒ Boolean
Constructor Details
#initialize(client, deployment_id, opts = {}) ⇒ Resource
Returns a new instance of Resource.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vra/resource.rb', line 31 def initialize(client, deployment_id, opts = {}) @client = client @deployment_id = deployment_id @id = opts[:id] @resource_data = opts[:data] @resource_actions = [] raise ArgumentError, 'must supply an id or a resource data hash' if @id.nil? && @resource_data.nil? raise ArgumentError, 'must supply an id OR a resource data hash, not both' if !@id.nil? && !@resource_data.nil? if @resource_data.nil? fetch_resource_data else @id = @resource_data['id'] end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
29 30 31 |
# File 'lib/vra/resource.rb', line 29 def client @client end |
#deployment_id ⇒ Object (readonly)
Returns the value of attribute deployment_id.
29 30 31 |
# File 'lib/vra/resource.rb', line 29 def deployment_id @deployment_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
29 30 31 |
# File 'lib/vra/resource.rb', line 29 def id @id end |
#resource_data ⇒ Object (readonly)
Returns the value of attribute resource_data.
29 30 31 |
# File 'lib/vra/resource.rb', line 29 def resource_data @resource_data end |
Instance Method Details
#fetch_resource_data ⇒ Object Also known as: refresh
48 49 50 51 52 |
# File 'lib/vra/resource.rb', line 48 def fetch_resource_data @resource_data = client.get_parsed("/deployment/api/deployments/#{deployment_id}/resources/#{id}") rescue Vra::Exception::HTTPNotFound raise Vra::Exception::NotFound, "resource ID #{@id} does not exist" end |
#ip_address ⇒ Object
95 96 97 98 99 |
# File 'lib/vra/resource.rb', line 95 def ip_address return if !vm? || network_interfaces.nil? properties['address'] end |
#name ⇒ Object
56 57 58 |
# File 'lib/vra/resource.rb', line 56 def name resource_data['name'] end |
#network_interfaces ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vra/resource.rb', line 80 def network_interfaces return unless vm? network_list = properties['networks'] return if network_list.nil? network_list.each_with_object([]) do |item, nics| nics << { 'NETWORK_NAME' => item['name'], 'NETWORK_ADDRESS' => item['address'], 'NETWORK_MAC_ADDRESS' => item['mac_address'] } end end |
#owner_names ⇒ Object
72 73 74 |
# File 'lib/vra/resource.rb', line 72 def owner_names properties['Owner'] end |
#project_id ⇒ Object
76 77 78 |
# File 'lib/vra/resource.rb', line 76 def project_id properties['project'] end |
#properties ⇒ Object
64 65 66 |
# File 'lib/vra/resource.rb', line 64 def properties resource_data['properties'] end |
#status ⇒ Object
60 61 62 |
# File 'lib/vra/resource.rb', line 60 def status resource_data['syncStatus'] end |
#vm? ⇒ Boolean
68 69 70 |
# File 'lib/vra/resource.rb', line 68 def vm? VM_TYPES.include?(resource_data['type']) end |