Module: VCloudSdk::Powerable

Included in:
VApp, VM
Defined in:
lib/ruby_vcloud_sdk/powerable.rb

Overview

Shared functions by classes VM and VApp

Instance Method Summary collapse

Instance Method Details

#power_offObject

Power off VApp or VM



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ruby_vcloud_sdk/powerable.rb', line 38

def power_off
  target = entity_xml
  class_name = self.class.name.split("::").last
  Config.logger.debug "#{class_name} status: #{target[:status]}"
  if is_status?(target, :SUSPENDED)
    error_msg = "#{class_name} #{target.name} suspended, discard state before powering off."
    fail class_name == "VApp" ? VappSuspendedError : VmSuspendedError,
         error_msg
  end
  if is_status?(target, :POWERED_OFF)
    Config.logger.info "#{class_name} #{target.name} is already powered off."
    return
  end

  power_off_link = target.power_off_link
  unless power_off_link
    fail CloudError, "#{class_name} #{target.name} is not in a state that could be powered off."
  end

  task = connection.post(power_off_link.href, nil)
  monitor_task task, @session.time_limit[:power_off]
  Config.logger.info "#{class_name} #{target.name} is powered off."

  undeploy(target, class_name)
  self
end

#power_onObject

Power on VApp or VM



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_vcloud_sdk/powerable.rb', line 15

def power_on
  target = entity_xml
  class_name = self.class.name.split("::").last
  Config.logger.debug "#{class_name} status: #{target[:status]}"
  if is_status?(target, :POWERED_ON)
    Config.logger.info "#{class_name} #{target.name} is already powered-on."
    return
  end

  power_on_link = target.power_on_link
  unless power_on_link
    fail CloudError,
         "#{class_name} #{target.name} not in a state able to power on."
  end

  Config.logger.info "Powering on #{class_name} #{target.name}."
  task = connection.post(power_on_link.href, nil)
  task = monitor_task task, @session.time_limit[:power_on]
  Config.logger.info "#{class_name} #{target.name} is powered on."
  self
end

#statusObject



4
5
6
7
8
9
10
11
12
# File 'lib/ruby_vcloud_sdk/powerable.rb', line 4

def status
  status_code = entity_xml[:status].to_i
  Xml::RESOURCE_ENTITY_STATUS.each_pair do |k, v|
    return k.to_s if v == status_code
  end

  fail CloudError,
       "Fail to find corresponding status for code '#{status_code}'"
end