Module: NexusSW::LXD::Transport::Mixins::Local
- Includes:
- Helpers::ExecuteMixin
- Included in:
- Local
- Defined in:
- lib/nexussw/lxd/transport/mixins/local.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #execute_chunked(command, options, &block) ⇒ Object
- #initialize(config = {}) ⇒ Object
- #read_file(path) ⇒ Object
- #write_file(path, content) ⇒ Object
Methods included from Helpers::ExecuteMixin
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/nexussw/lxd/transport/mixins/local.rb', line 14 def config @config end |
Instance Method Details
#execute_chunked(command, options, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nexussw/lxd/transport/mixins/local.rb', line 18 def execute_chunked(command, , &block) NIO::WebSocket::Reactor.start LXD.with_timeout_and_retries do if [:capture] == :interactive if [:tty] == false Open3.popen2e(command) do |stdin, stdout, th| # return immediately if interactive so that stdin may be used return Helpers::ExecuteMixin::InteractiveResult.new(command, , stdin, th).tap do |active| chunk_callback(stdout) do |stdout_chunk| active.send_output stdout_chunk if stdout_chunk end yield active active.exitstatus = th.value.exitstatus end end else status = system command status = case status when nil then -1 when true then 0 when false then 1 end return Helpers::ExecuteMixin::ExecuteResult.new(command, , status) end else Open3.popen3(command) do |_stdin, stdout, stderr, th| chunk_callback(stdout, stderr, &block) if block_given? th.join loop do return Helpers::ExecuteMixin::ExecuteResult.new(command, , th.value.exitstatus) if th.value.exited? && mon_out && mon_err && mon_out.closed? && mon_err.closed? Thread.pass end end end end end |
#initialize(config = {}) ⇒ Object
10 11 12 |
# File 'lib/nexussw/lxd/transport/mixins/local.rb', line 10 def initialize(config = {}) @config = config end |
#read_file(path) ⇒ Object
55 56 57 58 |
# File 'lib/nexussw/lxd/transport/mixins/local.rb', line 55 def read_file(path) # return '' unless File.exist? path File.read path end |
#write_file(path, content) ⇒ Object
60 61 62 63 64 |
# File 'lib/nexussw/lxd/transport/mixins/local.rb', line 60 def write_file(path, content) File.open path, "w" do |f| f.write content end end |