-
Notifications
You must be signed in to change notification settings - Fork 12
/
compute_action_helper.rb
79 lines (63 loc) · 2.95 KB
/
compute_action_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module Backends
module Opennebula
module Helpers
module ComputeActionHelper
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
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(true)
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(true) # 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
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(true)
check_retval(rc, Backends::Errors::ResourceActionError)
true
end
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
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
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
end
end
end
end