Module: Backends::Opennebula::Helpers::ComputeActionHelper

Included in:
Compute
Defined in:
lib/backends/opennebula/helpers/compute_action_helper.rb

Instance Method Summary collapse

Instance Method Details

#trigger_action_prolog(compute_id) ⇒ Object


58
59
60
61
62
63
64
# File 'lib/backends/opennebula/helpers/compute_action_helper.rb', line 58

def trigger_action_prolog(compute_id)
  virtual_machine = ::OpenNebula::VirtualMachine.new(::OpenNebula::VirtualMachine.build_xml(compute_id), @client)
  rc = virtual_machine.info
  check_retval(rc, Backends::Errors::ResourceRetrievalError)

  virtual_machine
end

#trigger_action_restart(compute_id, attributes = ::Occi::Core::Attributes.new) ⇒ Object


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

def trigger_action_restart(compute_id, attributes = ::Occi::Core::Attributes.new)
  backend_object = trigger_action_prolog(compute_id)
  trigger_action_state_check(backend_object, 'http://schemas.ogf.org/occi/infrastructure/compute/action#restart')

  case backend_object.state_str
  when 'ACTIVE'
    if backend_object.lcm_state_str == 'RUNNING'
      rc = backend_object.reboot
    else
      fail ::Backends::Errors::ResourceActionError,
         "Given action is not allowed in this state! [#{backend_object.lcm_state_str.inspect}]"
    end
  when 'FAILED'
    rc = backend_object.delete(recreate = true)
  else
    fail ::Backends::Errors::ResourceActionError,
         "Given action is not allowed in this state! [#{backend_object.state_str.inspect}]"
  end
  check_retval(rc, Backends::Errors::ResourceActionError)

  true
end

#trigger_action_start(compute_id, attributes = ::Occi::Core::Attributes.new) ⇒ Object


5
6
7
8
9
10
11
12
13
# File 'lib/backends/opennebula/helpers/compute_action_helper.rb', line 5

def trigger_action_start(compute_id, attributes = ::Occi::Core::Attributes.new)
  backend_object = trigger_action_prolog(compute_id)
  trigger_action_state_check(backend_object, 'http://schemas.ogf.org/occi/infrastructure/compute/action#start')

  rc = backend_object.resume
  check_retval(rc, Backends::Errors::ResourceActionError)

  true
end

#trigger_action_state_check(backend_object, action_type_identifier) ⇒ Object


66
67
68
69
70
71
72
73
74
75
# File 'lib/backends/opennebula/helpers/compute_action_helper.rb', line 66

def trigger_action_state_check(backend_object, action_type_identifier)
  result = parse_state(backend_object)

  unless result.actions.include? action_type_identifier
    fail ::Backends::Errors::ResourceStateError,
         "Given action is not allowed in state #{result.state.inspect}!"
  end

  true
end

#trigger_action_stop(compute_id, attributes = ::Occi::Core::Attributes.new) ⇒ Object


38
39
40
41
42
43
44
45
46
# File 'lib/backends/opennebula/helpers/compute_action_helper.rb', line 38

def trigger_action_stop(compute_id, attributes = ::Occi::Core::Attributes.new)
  backend_object = trigger_action_prolog(compute_id)
  trigger_action_state_check(backend_object, 'http://schemas.ogf.org/occi/infrastructure/compute/action#stop')

  rc = backend_object.poweroff
  check_retval(rc, Backends::Errors::ResourceActionError)

  true
end

#trigger_action_suspend(compute_id, attributes = ::Occi::Core::Attributes.new) ⇒ Object


48
49
50
51
52
53
54
55
56
# File 'lib/backends/opennebula/helpers/compute_action_helper.rb', line 48

def trigger_action_suspend(compute_id, attributes = ::Occi::Core::Attributes.new)
  backend_object = trigger_action_prolog(compute_id)
  trigger_action_state_check(backend_object, 'http://schemas.ogf.org/occi/infrastructure/compute/action#suspend')

  rc = backend_object.suspend
  check_retval(rc, Backends::Errors::ResourceActionError)

  true
end