Class: CemAcpt::Platform::CmdBase
- Inherits:
-
Object
- Object
- CemAcpt::Platform::CmdBase
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.
Constant Summary
Constants included
from Logging
Logging::LEVEL_MAP
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#apply_manifest(_instance_name, _manifest, _opts: {}) ⇒ Object
-
#initialize(*_args, env: {}, **_kwargs) ⇒ CmdBase
constructor
A new instance of CmdBase.
-
#local_exec(*_args, **_kwargs) ⇒ Object
-
#run_shell(_instance_name, _command, _opts: {}) ⇒ Object
-
#scp_download(_instance_name, _local, _remote, _scp_opts: {}, _opts: {}) ⇒ Object
-
#scp_upload(_instance_name, _local, _remote, _scp_opts: {}, _opts: {}) ⇒ Object
-
#ssh(_instance_name, _command, _ignore_command_errors: false, _opts: {}) ⇒ Object
-
#ssh_ready?(_instance_name, _timeout = 300, _opts: {}) ⇒ Boolean
-
#trim_output(output) ⇒ Object
-
#with_timed_retry(timeout = 300) ⇒ Object
Methods included from Logging
current_log_config, #current_log_config, current_log_format, #current_log_format, current_log_level, #current_log_level, included, logger, #logger, new_log_config, #new_log_config, new_log_formatter, #new_log_formatter, new_log_level, #new_log_level, new_logger, #new_logger
Constructor Details
#initialize(*_args, env: {}, **_kwargs) ⇒ CmdBase
Returns a new instance of CmdBase.
14
15
16
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 14
def initialize(*_args, env: {}, **_kwargs)
@env = env
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
12
13
14
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 12
def env
@env
end
|
Instance Method Details
#apply_manifest(_instance_name, _manifest, _opts: {}) ⇒ Object
38
39
40
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 38
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
18
19
20
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 18
def local_exec(*_args, **_kwargs)
raise NotImplementedError, '#local_exec must be implemented by a subclass'
end
|
#run_shell(_instance_name, _command, _opts: {}) ⇒ Object
42
43
44
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 42
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
30
31
32
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 30
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
26
27
28
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 26
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
22
23
24
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 22
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
34
35
36
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 34
def ssh_ready?(_instance_name, _timeout = 300, _opts: {})
raise NotImplementedError, '#ssh_ready? must be implemented by a subclass'
end
|
#trim_output(output) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 46
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/cem_acpt/platform/base/cmd.rb', line 54
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(10)
end
end
raise last_error
end
|