Class: Foreplay::Engine::Remote
- Inherits:
-
Object
- Object
- Foreplay::Engine::Remote
- Includes:
- Foreplay
- Defined in:
- lib/foreplay/engine/remote.rb
Defined Under Namespace
Constant Summary
Constants included from Foreplay
Instance Attribute Summary collapse
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
-
#check ⇒ Object
Deployment check: just say what we would have done.
- #deploy ⇒ Object
- #host ⇒ Object
- #host_port ⇒ Object
-
#initialize(s, st, i) ⇒ Remote
constructor
A new instance of Remote.
- #options ⇒ Object
- #port ⇒ Object
- #private_key ⇒ Object
- #private_key_from_file ⇒ Object
- #start_session(host, user, options) ⇒ Object
- #user ⇒ Object
Methods included from Foreplay
Constructor Details
#initialize(s, st, i) ⇒ Remote
Returns a new instance of Remote.
7 8 9 10 11 |
# File 'lib/foreplay/engine/remote.rb', line 7 def initialize(s, st, i) @server = s @steps = st @instructions = i end |
Instance Attribute Details
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
5 6 7 |
# File 'lib/foreplay/engine/remote.rb', line 5 def instructions @instructions end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
5 6 7 |
# File 'lib/foreplay/engine/remote.rb', line 5 def server @server end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
5 6 7 |
# File 'lib/foreplay/engine/remote.rb', line 5 def steps @steps end |
Instance Method Details
#check ⇒ Object
Deployment check: just say what we would have done
32 33 34 |
# File 'lib/foreplay/engine/remote.rb', line 32 def check Foreplay::Engine::Remote::Check.new(host, steps, instructions).perform end |
#deploy ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/foreplay/engine/remote.rb', line 13 def deploy output = '' puts "#{host}#{INDENT}Connecting to #{host} on port #{port}" # SSH connection session = start_session(host, user, ) puts "#{host}#{INDENT}Successfully connected to #{host} on port #{port}" session.shell do |sh| steps.each { |step| output += Foreplay::Engine::Remote::Step.new(host, sh, step, instructions).deploy } end session.close output end |
#host ⇒ Object
40 41 42 |
# File 'lib/foreplay/engine/remote.rb', line 40 def host @host ||= host_port[0] end |
#host_port ⇒ Object
48 49 50 |
# File 'lib/foreplay/engine/remote.rb', line 48 def host_port @host_port ||= server.split(':') # Parse host + port end |
#options ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/foreplay/engine/remote.rb', line 52 def return @options if @options @options = { verbose: :warn, port: port } password = instructions['password'] if password.blank? @options[:key_data] = [private_key] else @options[:password] = password end @options end |
#port ⇒ Object
44 45 46 |
# File 'lib/foreplay/engine/remote.rb', line 44 def port @port ||= (host_port[1] || 22) end |
#private_key ⇒ Object
67 68 69 70 |
# File 'lib/foreplay/engine/remote.rb', line 67 def private_key pk = instructions['private_key'] pk.blank? ? private_key_from_file : pk end |
#private_key_from_file ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/foreplay/engine/remote.rb', line 72 def private_key_from_file keyfile = instructions['keyfile'] keyfile.sub! '~', ENV['HOME'] || '/' unless keyfile.blank? # Remote shell won't expand this for us terminate( 'No authentication methods supplied. '\ 'You must supply a private key, key file or password in the configuration file' ) if keyfile.blank? # Get the key from the key file puts "#{INDENT}Using private key from #{keyfile}" File.read keyfile end |
#start_session(host, user, options) ⇒ Object
86 87 88 89 90 |
# File 'lib/foreplay/engine/remote.rb', line 86 def start_session(host, user, ) Net::SSH.start(host, user, ) rescue SocketError => e terminate "#{host}#{INDENT}There was a problem starting an ssh session on #{host}:\n#{e.}" end |
#user ⇒ Object
36 37 38 |
# File 'lib/foreplay/engine/remote.rb', line 36 def user @user = instructions['user'] end |