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)
}
return hosts_and_ports, hosts_and_ports_descriptions
end