Class: Vcloud::Core::Vapp

Inherits:
Object
  • Object
show all
Extended by:
ComputeMetadata
Defined in:
lib/vcloud/core/vapp.rb

Defined Under Namespace

Modules: STATUS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ComputeMetadata

get_metadata

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

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



51
52
53
# File 'lib/vcloud/core/vapp.rb', line 51

def fog_vms
  vcloud_attributes[:Children][:Vm]
end

#hrefObject



42
43
44
# File 'lib/vcloud/core/vapp.rb', line 42

def href
  vcloud_attributes[:href]
end

#nameObject



38
39
40
# File 'lib/vcloud/core/vapp.rb', line 38

def name
  vcloud_attributes[:name]
end

#networksObject



55
56
57
# File 'lib/vcloud/core/vapp.rb', line 55

def networks
  vcloud_attributes[:'ovf:NetworkSection'][:'ovf:Network']
end

#power_onObject



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_attributesObject



29
30
31
# File 'lib/vcloud/core/vapp.rb', line 29

def vcloud_attributes
  Vcloud::Fog::ServiceInterface.new.get_vapp(id)
end

#vdc_idObject



46
47
48
49
# File 'lib/vcloud/core/vapp.rb', line 46

def vdc_id
  link = vcloud_attributes[:Link].detect { |l| l[:rel] == Fog::RELATION::PARENT && l[:type] == Fog::ContentTypes::VDC }
  link ? link[:href].split('/').last : raise('a vapp without parent vdc found')
end