Class: Itamae::Backend::Base
- Inherits:
-
Object
- Object
- Itamae::Backend::Base
- Defined in:
- lib/itamae/backend.rb
Instance Method Summary collapse
- #finalize ⇒ Object
- #get_command(*args) ⇒ Object
- #host_inventory ⇒ Object
-
#initialize(options) ⇒ Base
constructor
A new instance of Base.
- #receive_file(src, dst = nil) ⇒ Object
- #run_command(commands, options = {}) ⇒ Object
- #send_directory(src, dst) ⇒ Object
- #send_file(src, dst) ⇒ Object
Constructor Details
#initialize(options) ⇒ Base
Returns a new instance of Base.
38 39 40 41 |
# File 'lib/itamae/backend.rb', line 38 def initialize() @options = @backend = create_specinfra_backend end |
Instance Method Details
#finalize ⇒ Object
122 123 124 |
# File 'lib/itamae/backend.rb', line 122 def finalize # pass end |
#get_command(*args) ⇒ Object
83 84 85 |
# File 'lib/itamae/backend.rb', line 83 def get_command(*args) @backend.command.get(*args) end |
#host_inventory ⇒ Object
118 119 120 |
# File 'lib/itamae/backend.rb', line 118 def host_inventory @backend.host_inventory end |
#receive_file(src, dst = nil) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/itamae/backend.rb', line 87 def receive_file(src, dst = nil) if dst Itamae.logger.debug "Receiving a file from '#{src}' to '#{dst}'..." else Itamae.logger.debug "Receiving a file from '#{src}'..." end @backend.receive_file(src, dst) end |
#run_command(commands, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/itamae/backend.rb', line 43 def run_command(commands, = {}) = {error: true}.merge() command = build_command(commands, ) Itamae.logger.debug "Executing `#{command}`..." result = nil Itamae.logger.with_indent do reset_output_handler result = @backend.run_command(command) flush_output_handler_buffer if result.exit_status == 0 || ![:error] method = :debug = "exited with #{result.exit_status}" else method = :error = "Command `#{command}` failed. (exit status: #{result.exit_status})" unless Itamae.logger.level == ::Logger::DEBUG result.stdout.each_line do |l| log_output_line("stdout", l, :error) end result.stderr.each_line do |l| log_output_line("stderr", l, :error) end end end Itamae.logger.public_send(method, ) end if [:error] && result.exit_status != 0 raise CommandExecutionError end result end |
#send_directory(src, dst) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/itamae/backend.rb', line 107 def send_directory(src, dst) Itamae.logger.debug "Sending a directory from '#{src}' to '#{dst}'..." unless ::File.exist?(src) raise SourceNotExistError, "The directory '#{src}' doesn't exist." end unless ::File.directory?(src) raise SourceNotExistError, "'#{src}' is not a directory." end @backend.send_directory(src, dst) end |
#send_file(src, dst) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/itamae/backend.rb', line 96 def send_file(src, dst) Itamae.logger.debug "Sending a file from '#{src}' to '#{dst}'..." unless ::File.exist?(src) raise SourceNotExistError, "The file '#{src}' doesn't exist." end unless ::File.file?(src) raise SourceNotExistError, "'#{src}' is not a file." end @backend.send_file(src, dst) end |