Class: VCloudCloud::Steps::Instantiate

Inherits:
VCloudCloud::Step show all
Defined in:
lib/cloud/vcloud/steps/instantiate.rb

Overview

Instance Attribute Summary

Attributes inherited from VCloudCloud::Step

#client, #state

Instance Method Summary collapse

Methods inherited from VCloudCloud::Step

#cleanup, #initialize

Constructor Details

This class inherits a constructor from VCloudCloud::Step

Instance Method Details

#perform(template_id, vapp_name, description, disk_locality, storage_profile, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cloud/vcloud/steps/instantiate.rb', line 6

def perform(template_id, vapp_name, description, disk_locality, storage_profile, &block)
  catalog_item = client.resolve_entity template_id
  raise ObjectNotFoundError, "Invalid vApp template Id: #{template_id}" unless catalog_item
  template = client.resolve_link catalog_item.entity

  params = VCloudSdk::Xml::WrapperFactory.create_instance 'InstantiateVAppTemplateParams'
  params.name = vapp_name
  params.description = description
  params.source = template
  params.all_eulas_accepted = true
  params.linked_clone = false
  params.set_locality = locality_spec template, disk_locality
  params.set_storage_profile = storage_profile_spec(template, storage_profile) if storage_profile

  state[:instantiate_vapp_name] = vapp_name

  vapp = client.invoke :post, client.vdc.instantiate_vapp_template_link, :payload => params

  state[:vapp] = client.wait_entity vapp
end

#rollbackObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cloud/vcloud/steps/instantiate.rb', line 27

def rollback
  vapp_name = state[:instantiate_vapp_name]
  if vapp_name
    @logger.debug "Requesting vApp: #{vapp_name}"

    # Note that when renaming vApp, the remove_link stays the same and points to
    # the original vApp. To avoid potential inconsistency, fetch vApp from the server.
    begin
      client.flush_cache  # flush cached vdc which contains vapp list
      vapp = client.vapp_by_name vapp_name
      link = vapp.remove_link true
      client.invoke_and_wait :delete, link if link
    rescue => ex
      @logger.debug(ex) if @logger
    end

    # remove the item from state
    state.delete :vapp
    state.delete :instantiate_vapp_name
  end
end