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.



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

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.



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

def instance_id
  @instance_id
end

Instance Method Details

#debug(msg) ⇒ Object



35
36
37
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 35

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

#ec2Object



26
27
28
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 26

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

#ec2_instanceObject



30
31
32
33
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 30

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

#exec(cmd) ⇒ Object



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

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

#info(msg) ⇒ Object



39
40
41
# File 'lib/moonshot/tools/asg_rollout/hook_exec_environment.rb', line 39

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