Class: CFConsole
- Inherits:
-
CFTunnel
- Object
- CFTunnel
- CFConsole
- Defined in:
- lib/console-vmc-plugin/console.rb
Instance Method Summary collapse
- #get_connection_info(auth) ⇒ Object
- #get_credentials ⇒ Object
-
#initialize(client, app, port = 10000, v2 = false) ⇒ CFConsole
constructor
A new instance of CFConsole.
- #login(auth = get_credentials) ⇒ Object
- #start_console ⇒ Object
Constructor Details
#initialize(client, app, port = 10000, v2 = false) ⇒ CFConsole
Returns a new instance of CFConsole.
8 9 10 11 12 13 |
# File 'lib/console-vmc-plugin/console.rb', line 8 def initialize(client, app, port = 10000, v2 = false) @client = client @app = app @port = port @v2 = v2 end |
Instance Method Details
#get_connection_info(auth) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/console-vmc-plugin/console.rb', line 15 def get_connection_info(auth) instances = @app.instances if instances.empty? raise "App has no running instances; try starting it." end unless console = instances[0].console raise "App does not have console access; try restarting it." end { "hostname" => console[:ip], "port" => console[:port] } end |
#get_credentials ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/console-vmc-plugin/console.rb', line 30 def get_credentials if @v2 YAML.load(@app.file("cf-rails-console", ".consoleaccess")) else YAML.load(@app.file("app", "cf-rails-console", ".consoleaccess")) end end |
#login(auth = get_credentials) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/console-vmc-plugin/console.rb', line 46 def login(auth = get_credentials) if !auth["username"] || !auth["password"] raise "Unable to verify console credentials." end @telnet = telnet_client prompt = nil err_msg = "Login attempt timed out." 5.times do begin results = @telnet.login( "Name" => auth["username"], "Password" => auth["password"]) lines = results.sub("Login: Password: ", "").split("\n") last_line = lines.pop if last_line =~ /[$%#>] \z/n prompt = last_line elsif last_line =~ /Login failed/ err_msg = last_line end break rescue TimeoutError sleep 1 rescue EOFError # This may happen if we login right after app starts close_console sleep 5 @telnet = telnet_client end end unless prompt close_console raise err_msg end prompt end |
#start_console ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/console-vmc-plugin/console.rb', line 38 def start_console prompt = login init_readline run_console prompt end |