Class: TrainPlugins::AWSSSM::Connection

Inherits:
Train::Plugins::Transport::BaseConnection
  • Object
show all
Defined in:
lib/train-awsssm/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



12
13
14
15
16
# File 'lib/train-awsssm/connection.rb', line 12

def initialize(options)
  super(options)

  check_options
end

Instance Attribute Details

#ec2=(value) ⇒ Object

Sets the attribute ec2

Parameters:

  • value

    the value to set the attribute ec2 to.



10
11
12
# File 'lib/train-awsssm/connection.rb', line 10

def ec2=(value)
  @ec2 = value
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



9
10
11
# File 'lib/train-awsssm/connection.rb', line 9

def instance_id
  @instance_id
end

#instances=(value) ⇒ Object

Sets the attribute instances

Parameters:

  • value

    the value to set the attribute instances to.



10
11
12
# File 'lib/train-awsssm/connection.rb', line 10

def instances=(value)
  @instances = value
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/train-awsssm/connection.rb', line 9

def options
  @options
end

#ssm=(value) ⇒ Object

Sets the attribute ssm

Parameters:

  • value

    the value to set the attribute ssm to.



10
11
12
# File 'lib/train-awsssm/connection.rb', line 10

def ssm=(value)
  @ssm = value
end

Instance Method Details

#closeObject



18
19
20
# File 'lib/train-awsssm/connection.rb', line 18

def close
  logger.info format("[AWS-SSM] Closed connection to %s", options[:host])
end

#execute_on_channel(cmd, &data_handler) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/train-awsssm/connection.rb', line 47

def execute_on_channel(cmd, &data_handler)
  logger.debug format("[AWS-SSM] Command: '%s'", cmd)

  result = execute_command(options[:host], cmd)

  stdout = result.standard_output_content || ""
  stderr = result.standard_error_content || ""
  exit_status = result.response_code

  [exit_status, stdout, stderr]
end

#file_via_connection(path, *args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/train-awsssm/connection.rb', line 33

def file_via_connection(path, *args)
  if os.aix?
    Train::File::Remote::Aix.new(self, path, *args)
  elsif os.solaris?
    Train::File::Remote::Unix.new(self, path, *args)
  elsif os[:name] == "qnx"
    Train::File::Remote::Qnx.new(self, path, *args)
  elsif os.windows?
    Train::File::Remote::Windows.new(self, path, *args)
  else
    Train::File::Remote::Linux.new(self, path, *args)
  end
end

#run_command_via_connection(cmd, &data_handler) ⇒ Object



26
27
28
29
30
31
# File 'lib/train-awsssm/connection.rb', line 26

def run_command_via_connection(cmd, &data_handler)
  logger.info format("[AWS-SSM] Sending command to %s", options[:host])
  exit_status, stdout, stderr = execute_on_channel(cmd, &data_handler)

  CommandResult.new(stdout, stderr, exit_status)
end

#uriObject



22
23
24
# File 'lib/train-awsssm/connection.rb', line 22

def uri
  "aws-ssm://#{options[:host]}/"
end