Class: Vcloud::Core::VappTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/vcloud/core/vapp_template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Hash

Return the vCloud data associated with vApp



10
11
12
13
14
15
# File 'lib/vcloud/core/vapp_template.rb', line 10

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.



5
6
7
# File 'lib/vcloud/core/vapp_template.rb', line 5

def id
  @id
end

Class Method Details

.get(vapp_template_name, catalog_name) ⇒ String

Get a template by name and catalog

Parameters:

  • vapp_template_name (String)

    The name of the vAppTemplate

  • catalog_name (String)

    The name of the catalog containing vAppTemplate

Returns:

  • (String)

    the ID of the template



58
59
60
61
62
63
64
65
# File 'lib/vcloud/core/vapp_template.rb', line 58

def self.get vapp_template_name, catalog_name
  ids = self.get_ids_by_name_and_catalog(vapp_template_name, catalog_name)
  raise 'Could not find template vApp' if ids.size == 0
  if ids.size > 1
    raise "Template #{vapp_template_name} is not unique in catalog #{catalog_name}"
  end
  return self.new(ids.first)
end

.get_ids_by_name_and_catalog(name, catalog_name) ⇒ Array

Get a list of templates with a particular name in a catalog

Parameters:

  • name (String)

    The name of the vAppTemplate to find

  • catalog_name (String)

    The name of the catalog to search

Returns:

  • (Array)

    an array of IDs of matching templates



43
44
45
46
47
48
49
50
51
# File 'lib/vcloud/core/vapp_template.rb', line 43

def self.get_ids_by_name_and_catalog name, catalog_name
  raise "provide Catalog and vAppTemplate name" unless name && catalog_name
  q = Vcloud::Core::QueryRunner.new
  query_results = q.run('vAppTemplate', :filter => "name==#{name};catalogName==#{catalog_name}")
  raise "Error retreiving #{q.type} query '#{q.filter}'" unless query_results
  query_results.collect do |record|
    record[:href].split('/').last if record.key?(:href)
  end
end

.id_prefixString

Return the id_prefix to be used for vAppTemplates

Returns:

  • (String)

    returns ‘vappTemplate’ as an id_prefix



70
71
72
# File 'lib/vcloud/core/vapp_template.rb', line 70

def self.id_prefix
  'vappTemplate'
end

Instance Method Details

#hrefString

Return the name of vAppTemplate

Returns:

  • (String)

    the name of instance



27
28
29
# File 'lib/vcloud/core/vapp_template.rb', line 27

def href
  vcloud_attributes[:href]
end

#nameString

Return the name of vAppTemplate

Returns:

  • (String)

    the name of instance



34
35
36
# File 'lib/vcloud/core/vapp_template.rb', line 34

def name
  vcloud_attributes[:name]
end

#vcloud_attributesHash

Return the vCloud data associated with vAppTemplate

Returns:

  • (Hash)

    the complete vCloud data for vAppTemplate



20
21
22
# File 'lib/vcloud/core/vapp_template.rb', line 20

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