class Kitchen::Transport::Lxd::Connection
Attributes
nx_transport[R]
state_filename[R]
Public Class Methods
new(transport, options, state_filename)
click to toggle source
Calls superclass method
# File lib/kitchen/transport/lxd.rb, line 33 def initialize(transport, options, state_filename) super options @nx_transport = transport @state_filename = state_filename end
Public Instance Methods
download(remotes, local)
click to toggle source
# File lib/kitchen/transport/lxd.rb, line 68 def download(remotes, local) FileUtils.mkdir_p local unless Dir.exist? local [remotes].flatten.each do |remote| nx_transport.download_folder remote.to_s, local, auto_detect: true end rescue NexusSW::LXD::RestAPI::Error => ex raise TransportFailed, ex end
execute(command)
click to toggle source
# File lib/kitchen/transport/lxd.rb, line 41 def execute(command) return unless command && !command.empty? # There are some bash-isms coming from chef_zero (in particular, multiple_converge) # so let's wrap it command = command.shelljoin if command.is_a? Array command = ["bash", "-c", command] res = nx_transport.execute(command, capture: true) do |stdout_chunk, stderr_chunk| logger << stdout_chunk if stdout_chunk logger << stderr_chunk if stderr_chunk end raise TransportFailed.new("The command #{res.command} failed with exit code: #{res.exitstatus}", res.exitstatus) if res.error? end
login_command()
click to toggle source
# File lib/kitchen/transport/lxd.rb, line 77 def login_command args = [File.expand_path("../../../../bin/lxc-shell", __FILE__), state_filename] LoginCommand.new "ruby", args end
upload(locals, remote)
click to toggle source
# File lib/kitchen/transport/lxd.rb, line 55 def upload(locals, remote) nx_transport.execute("mkdir -p #{remote}").error! [locals].flatten.each do |local| nx_transport.upload_file local, File.join(remote, File.basename(local)) if File.file? local if File.directory? local debug "Transferring folder (#{local}) to remote: #{remote}" nx_transport.upload_folder local, remote end end rescue NexusSW::LXD::RestAPI::Error => ex raise TransportFailed, ex end