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 |
# 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 Open3.popen3(command) do |stdin, stdout, stderr, th| if [:capture] == :interactive # return immediately if interactive so that stdin may be used return Helpers::ExecuteMixin::InteractiveResult.new(command, , -1, stdin, th).tap do |active| chunk_callback(stdout, stderr) do |stdout_chunk, stderr_chunk| active.send_output stdout_chunk if stdout_chunk active.send_output stderr_chunk if stderr_chunk end yield active active.exitstatus = th.value.exitstatus end else 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
44 45 46 47 |
# File 'lib/nexussw/lxd/transport/mixins/local.rb', line 44 def read_file(path) # return '' unless File.exist? path File.read path end |
#write_file(path, content) ⇒ Object
49 50 51 52 53 |
# File 'lib/nexussw/lxd/transport/mixins/local.rb', line 49 def write_file(path, content) File.open path, 'w' do |f| f.write content end end |