Class: CemAcpt::Platform::CmdBase

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cem_acpt/platform/base/cmd.rb

Overview

Base class for command providers. Provides an API for subclasses to implement.

Direct Known Subclasses

Gcp::Cmd

Instance Method Summary collapse

Methods included from Logging

current_log_config, #current_log_config, current_log_format, current_log_level, #current_log_level, included, #logger, new_log_config, #new_log_config, new_log_formatter, new_log_level, #new_log_level

Constructor Details

#initialize(*args, **kwargs) ⇒ CmdBase

Returns a new instance of CmdBase.



10
# File 'lib/cem_acpt/platform/base/cmd.rb', line 10

def initialize(*args, **kwargs); end

Instance Method Details

#apply_manifest(_instance_name, _manifest, _opts: {}) ⇒ Object

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/cem_acpt/platform/base/cmd.rb', line 32

def apply_manifest(_instance_name, _manifest, _opts: {})
  raise NotImplementedError, '#create_manifest_on_node must be implemented by a subclass'
end

#local_exec(*_args, **_kwargs) ⇒ Object

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/cem_acpt/platform/base/cmd.rb', line 12

def local_exec(*_args, **_kwargs)
  raise NotImplementedError, '#local_exec must be implemented by a subclass'
end

#run_shell(_instance_name, _command, _opts: {}) ⇒ Object

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/cem_acpt/platform/base/cmd.rb', line 36

def run_shell(_instance_name, _command, _opts: {})
  raise NotImplementedError, '#run_shell must be implemented by a subclass'
end

#scp_download(_instance_name, _local, _remote, _scp_opts: {}, _opts: {}) ⇒ Object

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/cem_acpt/platform/base/cmd.rb', line 24

def scp_download(_instance_name, _local, _remote, _scp_opts: {}, _opts: {})
  raise NotImplementedError, '#scp_download must be implemented by a subclass'
end

#scp_upload(_instance_name, _local, _remote, _scp_opts: {}, _opts: {}) ⇒ Object

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/cem_acpt/platform/base/cmd.rb', line 20

def scp_upload(_instance_name, _local, _remote, _scp_opts: {}, _opts: {})
  raise NotImplementedError, '#scp_upload must be implemented by a subclass'
end

#ssh(_instance_name, _command, _ignore_command_errors: false, _opts: {}) ⇒ Object

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/cem_acpt/platform/base/cmd.rb', line 16

def ssh(_instance_name, _command, _ignore_command_errors: false, _opts: {})
  raise NotImplementedError, '#ssh must be implemented by a subclass'
end

#ssh_ready?(_instance_name, _timeout = 300, _opts: {}) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/cem_acpt/platform/base/cmd.rb', line 28

def ssh_ready?(_instance_name, _timeout = 300, _opts: {})
  raise NotImplementedError, '#ssh_ready? must be implemented by a subclass'
end

#trim_output(output) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/cem_acpt/platform/base/cmd.rb', line 40

def trim_output(output)
  if output.include?("\n")
    output.split("\n").map(&:strip).reject(&:empty?).join("\n")
  else
    output.strip
  end
end

#with_timed_retry(timeout = 300) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cem_acpt/platform/base/cmd.rb', line 48

def with_timed_retry(timeout = 300)
  return unless block_given?

  last_error = nil
  start_time = Time.now
  while Time.now - start_time < timeout
    begin
      output = yield
      return output
    rescue StandardError => e
      last_error = e
      sleep(5)
    end
  end
  raise last_error
end