Class: Vcloud::Core::Vapp
- Inherits:
-
Object
- Object
- Vcloud::Core::Vapp
- Extended by:
- ComputeMetadata
- Defined in:
- lib/vcloud/core/vapp.rb
Defined Under Namespace
Modules: STATUS
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
- .get_by_name(name) ⇒ Object
- .get_by_name_and_vdc_name(name, vdc_name) ⇒ Object
- .instantiate(name, network_names, template_id, vdc_name) ⇒ Object
Instance Method Summary collapse
- #fog_vms ⇒ Object
- #href ⇒ Object
-
#initialize(id) ⇒ Vapp
constructor
A new instance of Vapp.
- #name ⇒ Object
- #networks ⇒ Object
- #power_on ⇒ Object
- #vcloud_attributes ⇒ Object
- #vdc_id ⇒ Object
Methods included from ComputeMetadata
Constructor Details
#initialize(id) ⇒ Vapp
8 9 10 11 12 13 |
# File 'lib/vcloud/core/vapp.rb', line 8 def initialize(id) unless id =~ /^#{self.class.id_prefix}-[-0-9a-f]+$/ raise "#{self.class.id_prefix} id : #{id} is not in correct format" end @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/vcloud/core/vapp.rb', line 6 def id @id end |
Class Method Details
.get_by_name(name) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vcloud/core/vapp.rb', line 15 def self.get_by_name(name) q = Vcloud::Core::QueryRunner.new query_results = q.run('vApp', :filter => "name==#{name}") raise "Error finding vApp by name #{name}" unless query_results case query_results.size when 0 raise "vApp #{name} not found" when 1 return self.new(query_results.first[:href].split('/').last) else raise "found multiple vApp entities with name #{name}!" end end |
.get_by_name_and_vdc_name(name, vdc_name) ⇒ Object
59 60 61 62 63 |
# File 'lib/vcloud/core/vapp.rb', line 59 def self.get_by_name_and_vdc_name(name, vdc_name) fog_interface = Vcloud::Fog::ServiceInterface.new attrs = fog_interface.get_vapp_by_name_and_vdc_name(name, vdc_name) self.new(attrs[:href].split('/').last) if attrs && attrs.key?(:href) end |
.instantiate(name, network_names, template_id, vdc_name) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vcloud/core/vapp.rb', line 65 def self.instantiate(name, network_names, template_id, vdc_name) Vcloud::Core.logger.info("Instantiating new vApp #{name} in vDC '#{vdc_name}'") fog_interface = Vcloud::Fog::ServiceInterface.new networks = get_networks(network_names, vdc_name) attrs = fog_interface.post_instantiate_vapp_template( fog_interface.vdc(vdc_name), template_id, name, InstantiationParams: build_network_config(networks) ) self.new(attrs[:href].split('/').last) if attrs and attrs.key?(:href) end |
Instance Method Details
#fog_vms ⇒ Object
51 52 53 |
# File 'lib/vcloud/core/vapp.rb', line 51 def fog_vms vcloud_attributes[:Children][:Vm] end |
#href ⇒ Object
42 43 44 |
# File 'lib/vcloud/core/vapp.rb', line 42 def href vcloud_attributes[:href] end |
#name ⇒ Object
38 39 40 |
# File 'lib/vcloud/core/vapp.rb', line 38 def name vcloud_attributes[:name] end |
#networks ⇒ Object
55 56 57 |
# File 'lib/vcloud/core/vapp.rb', line 55 def networks vcloud_attributes[:'ovf:NetworkSection'][:'ovf:Network'] end |
#power_on ⇒ Object
79 80 81 82 83 84 |
# File 'lib/vcloud/core/vapp.rb', line 79 def power_on raise "Cannot power on a missing vApp." unless id return true if running? Vcloud::Fog::ServiceInterface.new.power_on_vapp(id) running? end |
#vcloud_attributes ⇒ Object
29 30 31 |
# File 'lib/vcloud/core/vapp.rb', line 29 def vcloud_attributes Vcloud::Fog::ServiceInterface.new.get_vapp(id) end |