# File lib/rhc-common.rb, line 705
  def self.list_ports(rhc_domain, namespace, app_name, app_uuid, debug=true)

    ip_and_port_simple_regex = /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5}/

    ssh_host = "#{app_name}-#{namespace}.#{rhc_domain}"

    ssh_cmd = "ssh -t #{app_uuid}@#{ssh_host} 'rhc-list-ports'"

    hosts_and_ports = []
    hosts_and_ports_descriptions = []
    scaled_uuids = []

    puts ssh_cmd if debug

    Open3.popen3(ssh_cmd) { |stdin, stdout, stderr| 

      stdout.each { |line|
        line = line.chomp
        if line.downcase =~ /scale/
          scaled_uuid = line[5..-1]
          scaled_uuids << scaled_uuid
        else
          if ip_and_port_simple_regex.match(line)
            hosts_and_ports << line
          end
        end
      }

      stderr.each { |line|
        line = line.chomp
        if line.downcase =~ /permission denied/
          puts line
          exit 1
        end
        
        
        if line.index(ip_and_port_simple_regex)
          hosts_and_ports_descriptions << line
        end
      }

    }

    scaled_uuids.each { |uuid|
      list_scaled_ports(rhc_domain, namespace, app_name, uuid, hosts_and_ports, hosts_and_ports_descriptions, debug)
    }
    
    #hosts_and_ports_descriptions = stderr.gets.chomp.split(/\n/)
    #hosts_and_ports = stdout.gets.chomp.split(/\n/)

    # Net::SSH.start(ssh_host, app_uuid) do |ssh| 

    #   ssh.exec!("rhc-list-ports") do |channel, stream, data|

    #     array = data.split(/\n/)

    #     if stream == :stderr 
    #       hosts_and_ports_descriptions = array
    #     elsif stream == :stdout 
    #       hosts_and_ports = array
    #     end

    #   end

    # end

    return hosts_and_ports, hosts_and_ports_descriptions

  end