Module: Backends::Opennebula::Helpers::StorageActionHelper

Included in:
Storage
Defined in:
lib/backends/opennebula/helpers/storage_action_helper.rb

Instance Method Summary collapse

Instance Method Details

#trigger_action_backup(storage_id, attributes = ::Occi::Core::Attributes.new) ⇒ Object


25
26
27
28
29
30
31
32
33
# File 'lib/backends/opennebula/helpers/storage_action_helper.rb', line 25

def trigger_action_backup(storage_id, attributes = ::Occi::Core::Attributes.new)
  backend_object = trigger_action_prolog(storage_id)
  trigger_action_state_check(backend_object, 'http://schemas.ogf.org/occi/infrastructure/storage/action#backup')

  rc = backend_object.clone("#{backend_object['NAME']}-#{DateTime.now.to_s.gsub(':', '_')}")
  check_retval(rc, Backends::Errors::ResourceActionError)

  true
end

#trigger_action_offline(storage_id, attributes = ::Occi::Core::Attributes.new) ⇒ Object


15
16
17
18
19
20
21
22
23
# File 'lib/backends/opennebula/helpers/storage_action_helper.rb', line 15

def trigger_action_offline(storage_id, attributes = ::Occi::Core::Attributes.new)
  backend_object = trigger_action_prolog(storage_id)
  trigger_action_state_check(backend_object, 'http://schemas.ogf.org/occi/infrastructure/storage/action#offline')

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

  true
end

#trigger_action_online(storage_id, attributes = ::Occi::Core::Attributes.new) ⇒ Object


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

def trigger_action_online(storage_id, attributes = ::Occi::Core::Attributes.new)
  backend_object = trigger_action_prolog(storage_id)
  trigger_action_state_check(backend_object, 'http://schemas.ogf.org/occi/infrastructure/storage/action#online')

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

  true
end

#trigger_action_prolog(storage_id) ⇒ Object


35
36
37
38
39
40
41
# File 'lib/backends/opennebula/helpers/storage_action_helper.rb', line 35

def trigger_action_prolog(storage_id)
  image = ::OpenNebula::Image.new(::OpenNebula::Image.build_xml(storage_id), @client)
  rc = image.info
  check_retval(rc, Backends::Errors::ResourceRetrievalError)

  image
end

#trigger_action_state_check(backend_object, action_type_identifier) ⇒ Object


43
44
45
46
47
48
49
50
51
52
# File 'lib/backends/opennebula/helpers/storage_action_helper.rb', line 43

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