class Train::Transports::Lxd::Connection
Attributes
lxd[R]
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/train/transports/lxd.rb, line 23 def initialize(options) super options @lxd = nx_driver.transport_for(options[:container_name]).tap do |transport| transport.user options[:username] if options[:username] end end
Private Instance Methods
can_rest?()
click to toggle source
# File lib/train/transports/lxd.rb, line 39 def can_rest? options[:config][:server] && !options[:config][:server].empty? end
file_via_connection(path)
click to toggle source
Interact with files on the target. Read, write, and get metadata from files via the transport.
@param [String] path which is being inspected @return [FileCommon] file object that allows for interaction
# File lib/train/transports/lxd.rb, line 63 def file_via_connection(path) # TODO: can I replace this with a class that will work more efficiently with lxd api calls? Train::File::Remote::Linux.new(self, path) end
host_address()
click to toggle source
# File lib/train/transports/lxd.rb, line 43 def host_address "https://#{options[:config][:server]}:#{options[:config][:port] || 8443}" end
login_command()
click to toggle source
Builds a LoginCommand which can be used to open an interactive session on the remote host.
@return [LoginCommand] array of command line tokens
# File lib/train/transports/lxd.rb, line 72 def login_command # TODO: implement raise NotImplementedError, "#{self.class} does not implement #login_command()" end
nx_driver()
click to toggle source
# File lib/train/transports/lxd.rb, line 34 def nx_driver return ::NexusSW::LXD::Driver::CLI.new(::NexusSW::LXD::Transport::Local.new) unless can_rest? ::NexusSW::LXD::Driver::Rest.new(host_address, options[:config][:rest_options]) end
run_command_via_connection(command)
click to toggle source
Execute a command using this connection.
@param command [String] command string to execute @return [CommandResult] contains the result of running the command
# File lib/train/transports/lxd.rb, line 51 def run_command_via_connection(command) command = command.shelljoin if command.is_a? Array command = ['sh', '-c', command] res = lxd.execute(command) CommandResult.new res.stdout, res.stderr, res.exitstatus end