Module: Backends::Ec2::Helpers::ComputeActionHelper

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

Instance Method Summary collapse

Instance Method Details

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


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

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

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    @ec2_client.reboot_instances(instance_ids: [compute_id])
  end

  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/ec2/helpers/compute_action_helper.rb', line 5

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

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    @ec2_client.start_instances(instance_ids: [compute_id])
  end

  true
end

#trigger_action_state_check(compute_id, action_type_identifier) ⇒ Object


35
36
37
38
39
40
41
42
43
44
# File 'lib/backends/ec2/helpers/compute_action_helper.rb', line 35

def trigger_action_state_check(compute_id, action_type_identifier)
  result = get(compute_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

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


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

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

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    @ec2_client.stop_instances(instance_ids: [compute_id])
  end

  true
end