Class: Moonshot::Tools::ASGRollout::HookExecEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/moonshot/tools/asg_rollout/hook_exec_environment.rb

Overview

This object is passed into hooks defined in the ASGRollout process, to give them access to instances and logging facilities.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, instance_id) ⇒ HookExecEnvironment

Returns a new instance of HookExecEnvironment.



12
13
14
15
16
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 12

def initialize(config, instance_id)
  @ilog = config.interactive_logger
  @command_builder = Moonshot::SSHCommandBuilder.new(config.ssh_config, instance_id)
  @instance_id = instance_id
end

Instance Attribute Details

#instance_idObject (readonly)

Returns the value of attribute instance_id.



10
11
12
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 10

def instance_id
  @instance_id
end

Instance Method Details

#debug(msg) ⇒ Object



33
34
35
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 33

def debug(msg)
  @ilog.debug(msg)
end

#ec2Object



24
25
26
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 24

def ec2
  Aws::EC2::Client.new
end

#ec2_instanceObject



28
29
30
31
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 28

def ec2_instance
  res = Aws::EC2::Resource.new(client: ec2)
  res.instance(@instance_id)
end

#exec(cmd) ⇒ Object



18
19
20
21
22
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 18

def exec(cmd)
  cb = @command_builder.build(cmd)
  fe = SSHForkExecutor.new
  fe.run(cb.cmd)
end

#info(msg) ⇒ Object



37
38
39
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 37

def info(msg)
  @ilog.info(msg)
end