Module: Backends::Ec2::Helpers::StorageActionHelper

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

Instance Method Summary collapse

Instance Method Details

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


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

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

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    @ec2_client.create_snapshot(
      volume_id: storage_id,
      description: "Snapshot of #{storage_id} from #{DateTime.now}"
    )
  end

  true
end

#trigger_action_state_check(storage_id, action_type_identifier) ⇒ Object


18
19
20
21
22
23
24
25
26
27
# File 'lib/backends/ec2/helpers/storage_action_helper.rb', line 18

def trigger_action_state_check(storage_id, action_type_identifier)
  result = get(storage_id)

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

  true
end