Class: VCloudCloud::Steps::Recompose

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

Overview

Recompose a vApp to add or remove VMs. Ref: pubs.vmware.com/vcd-51/index.jsp#operations/POST-RecomposeVApp.html

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(name, container_vapp, vm = nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cloud/vcloud/steps/recompose.rb', line 7

def perform(name, container_vapp, vm = nil, &block)
  params = VCloudSdk::Xml::WrapperFactory.create_instance 'RecomposeVAppParams'
  params.name = name
  params.all_eulas_accepted = true
  params.add_source_item vm.href if vm

  # HACK: Workaround. recomposeLink is not available when vapp is running (so force construct the link)
  recompose_vapp_link = container_vapp.recompose_vapp_link true
  state[:recompose_vapp_name] = name
  client.invoke_and_wait :post, recompose_vapp_link, :payload => params
end

#rollbackObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cloud/vcloud/steps/recompose.rb', line 19

def rollback
  # The recompose method is only used in create_vm step.
  # The rollback logic here is to delete the new-created VM.
  vm = state[:vm]
  vapp_name = state[:recompose_vapp_name]
  if !vm.nil? && !vapp_name.nil?
    @logger.debug "Requesting VM: #{vm.name}"

    begin
      client.flush_cache
      vapp = client.vapp_by_name vapp_name
      target_vm = vapp.vms.find { |v| v.name == vm.name }
      link = target_vm.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 :vm
    state.delete :recompose_vapp_name
  end
end