Class: LxcSsh::Connection
- Inherits:
-
Object
- Object
- LxcSsh::Connection
- Defined in:
- lib/lxc_ssh/connection.rb
Instance Attribute Summary collapse
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
Instance Method Summary collapse
-
#connect(hostname, username, password, lxc_path = '/usr') ⇒ Object
Connects to the host system via ssh and authenticates by either public key or password authentication.
-
#init_manager ⇒ Object
Initializes the lxc manager object.
-
#initialize ⇒ Connection
constructor
Initializes the connection.
-
#obtain_version ⇒ Object
Obtains the version number of the lxc installation.
Constructor Details
#initialize ⇒ Connection
Initializes the connection
9 10 11 12 13 14 |
# File 'lib/lxc_ssh/connection.rb', line 9 def initialize @session = nil @manager = nil @lxc_version = nil @lxc_path = nil end |
Instance Attribute Details
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
6 7 8 |
# File 'lib/lxc_ssh/connection.rb', line 6 def manager @manager end |
Instance Method Details
#connect(hostname, username, password, lxc_path = '/usr') ⇒ Object
Connects to the host system via ssh and authenticates by either public key or password authentication
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lxc_ssh/connection.rb', line 23 def connect(hostname, username, password, lxc_path = '/usr') if @password.nil? # pubkey @session = Net::SSH.start(hostname, username) else @session = Net::SSH.start(hostname, username, password) end @lxc_path = lxc_path @lxc_version = obtain_version @manager = self.init_manager end |
#init_manager ⇒ Object
Initializes the lxc manager object
46 47 48 49 50 51 52 |
# File 'lib/lxc_ssh/connection.rb', line 46 def init_manager if @lxc_version.nil? raise 'no lxc version set, please detect and set the lxc version using detect_lxc_version' end @manager = LxcSsh::Manager.new(@session, @lxc_version, @lxc_path) end |
#obtain_version ⇒ Object
Obtains the version number of the lxc installation
39 40 41 42 43 |
# File 'lib/lxc_ssh/connection.rb', line 39 def obtain_version output = @session.exec! @lxc_path + "/bin/lxc-start --version" output.strip end |