Class: VCloudCloud::Steps::PowerOn

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

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(ref, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cloud/vcloud/steps/poweron.rb', line 4

def perform(ref, &block)
  entity = client.reload state[ref]
  if entity['status'] == VCloudSdk::Xml::RESOURCE_ENTITY_STATUS[:POWERED_ON].to_s
    @logger.debug "#{entity.name} already powered on"
    return
  end
  poweron_link = entity.power_on_link
  raise "#{entity.name} unable to power on" unless poweron_link
  state[:poweron_target] = state[ref]
  client.invoke_and_wait :post, poweron_link
  state[ref] = client.reload entity
end

#rollbackObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cloud/vcloud/steps/poweron.rb', line 17

def rollback
  target = state[:poweron_target]
  if target
    begin
      entity = client.reload target
      if entity['status'] == VCloudSdk::Xml::RESOURCE_ENTITY_STATUS[:POWERED_OFF].to_s
        @logger.debug "#{entity.name} already powered off"
        return
      end

      poweroff_link = entity.power_off_link
      client.invoke_and_wait :post, poweroff_link
    rescue => ex
      @logger.debug(ex) if @logger
    end
  end
end