Module: VMC::Cli::ConsoleHelper
- Included in:
- VMC::Cli::Command::Apps
- Defined in:
- lib/cli/console_helper.rb
Instance Method Summary collapse
- #close_console ⇒ Object
- #console_connection_info(appname) ⇒ Object
- #console_credentials(appname) ⇒ Object
- #console_login(auth_info, port) ⇒ Object
- #console_tab_completion_data(cmd) ⇒ Object
- #send_console_command(cmd) ⇒ Object
- #start_local_console(port, appname) ⇒ Object
Instance Method Details
#close_console ⇒ Object
92 93 94 |
# File 'lib/cli/console_helper.rb', line 92 def close_console @telnet_client.close end |
#console_connection_info(appname) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cli/console_helper.rb', line 7 def console_connection_info(appname) app = client.app_info(appname) fw = VMC::Cli::Framework.lookup_by_framework(app[:staging][:model]) if !fw.console err "'#{appname}' is a #{fw.name} application. " + "Console access is not supported for #{fw.name} applications." end instances_info_envelope = client.app_instances(appname) instances_info_envelope = {} if instances_info_envelope.is_a?(Array) instances_info = instances_info_envelope[:instances] || [] err "No running instances for [#{appname}]" if instances_info.empty? entry = instances_info[0] if !entry[:console_port] begin client.app_files(appname, '/app/cf-rails-console') err "Console port not provided for [#{appname}]. Try restarting the app." rescue VMC::Client::TargetError, VMC::Client::NotFound err "Console access not supported for [#{appname}]. " + "Please redeploy your app to enable support." end end conn_info = { 'hostname' => entry[:console_ip], 'port' => entry[:console_port] } end |
#console_credentials(appname) ⇒ Object
87 88 89 90 |
# File 'lib/cli/console_helper.rb', line 87 def console_credentials(appname) content = client.app_files(appname, '/app/cf-rails-console/.consoleaccess', '0') YAML.load(content) end |
#console_login(auth_info, port) ⇒ 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 |
# File 'lib/cli/console_helper.rb', line 46 def console_login(auth_info, port) if !auth_info["username"] || !auth_info["password"] err "Unable to verify console credentials." end @telnet_client = telnet_client(port) prompt = nil err_msg = "Login attempt timed out." 5.times do begin results = @telnet_client.login("Name"=>auth_info["username"], "Password"=>auth_info["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 syster app starts close_console sleep 5 @telnet_client = telnet_client(port) end display ".", false end unless prompt close_console err err_msg end prompt end |
#console_tab_completion_data(cmd) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/cli/console_helper.rb', line 96 def console_tab_completion_data(cmd) begin results = @telnet_client.cmd("String"=> cmd + "\t", "Match"=>/\S*\n$/, "Timeout"=>10) results.chomp.split(",") rescue TimeoutError [] #Just return empty results if timeout occurred on tab completion end end |
#send_console_command(cmd) ⇒ Object
82 83 84 85 |
# File 'lib/cli/console_helper.rb', line 82 def send_console_command(cmd) results = @telnet_client.cmd(cmd) results.split("\n") end |
#start_local_console(port, appname) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/cli/console_helper.rb', line 36 def start_local_console(port, appname) auth_info = console_credentials(appname) display "Connecting to '#{appname}' console: ", false prompt = console_login(auth_info, port) display "OK".green display "\n" initialize_readline run_console prompt end |