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.
8 9 10 11 12 |
# File 'lib/foreplay/engine/remote.rb', line 8 def initialize(s, st, i) @server = s @steps = st @instructions = i end |
Instance Attribute Details
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
6 7 8 |
# File 'lib/foreplay/engine/remote.rb', line 6 def instructions @instructions end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
6 7 8 |
# File 'lib/foreplay/engine/remote.rb', line 6 def server @server end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
6 7 8 |
# File 'lib/foreplay/engine/remote.rb', line 6 def steps @steps end |
Instance Method Details
#check ⇒ Object
Deployment check: just say what we would have done
33 34 35 |
# File 'lib/foreplay/engine/remote.rb', line 33 def check Foreplay::Engine::Remote::Check.new(host, steps, instructions).perform end |
#deploy ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/foreplay/engine/remote.rb', line 14 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
41 42 43 |
# File 'lib/foreplay/engine/remote.rb', line 41 def host @host ||= host_port[0] end |
#host_port ⇒ Object
49 50 51 |
# File 'lib/foreplay/engine/remote.rb', line 49 def host_port @host_port ||= server.split(':') # Parse host + port end |
#options ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/foreplay/engine/remote.rb', line 53 def return if = { verbose: :warn, port: port } password = instructions['password'] if password.blank? [:key_data] = [private_key] else [:password] = password end end |
#port ⇒ Object
45 46 47 |
# File 'lib/foreplay/engine/remote.rb', line 45 def port @port ||= (host_port[1] || 22) end |
#private_key ⇒ Object
68 69 70 71 |
# File 'lib/foreplay/engine/remote.rb', line 68 def private_key pk = instructions['private_key'] pk.blank? ? private_key_from_file : pk end |
#private_key_from_file ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/foreplay/engine/remote.rb', line 73 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
87 88 89 90 91 |
# File 'lib/foreplay/engine/remote.rb', line 87 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.message}" end |
#user ⇒ Object
37 38 39 |
# File 'lib/foreplay/engine/remote.rb', line 37 def user @user = instructions['user'] end |