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) ⇒ CFConsole
constructor
A new instance of CFConsole.
- #login(auth = get_credentials) ⇒ Object
- #start_console ⇒ Object
Constructor Details
#initialize(client, app, port = 10000) ⇒ CFConsole
Returns a new instance of CFConsole.
8 9 10 11 12 |
# File 'lib/console-vmc-plugin/console.rb', line 8 def initialize(client, app, port = 10000) @client = client @app = app @port = port end |
Instance Method Details
#get_connection_info(auth) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/console-vmc-plugin/console.rb', line 14 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
29 30 31 |
# File 'lib/console-vmc-plugin/console.rb', line 29 def get_credentials YAML.load(@app.file("app", "cf-rails-console", ".consoleaccess")) end |
#login(auth = get_credentials) ⇒ Object
41 42 43 44 45 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 |
# File 'lib/console-vmc-plugin/console.rb', line 41 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
33 34 35 36 37 38 39 |
# File 'lib/console-vmc-plugin/console.rb', line 33 def start_console prompt = login init_readline run_console prompt end |