def self.create_app(libra_server, net_http, user_info, app_name, app_type, rhlogin, password, repo_dir=nil, no_dns=false, no_git=false, no_git_message=nil)
puts "Attempting to create remote application space: #{app_name}"
data = {:cartridge => app_type,
:action => 'configure',
:app_name => app_name,
:rhlogin => rhlogin
}
if @mydebug
data[:debug] = true
end
json_data = generate_json(data)
url = URI.parse("https://#{libra_server}/broker/cartridge")
response = http_post(net_http, url, json_data, password)
if response.code == '200'
json_resp = JSON.parse(response.body)
print_response_success(json_resp)
json_data = JSON.parse(json_resp['data'])
health_check_path = json_data['health_check_path']
app_uuid = json_data['uuid']
result = json_resp['result']
puts "DEBUG: '#{app_name}' creation returned success." if @mydebug
else
print_response_err(response)
end
at_exit do
unless $!.nil? || $!.is_a?(SystemExit) && $!.success?
puts "Cleaning up application"
destroy_app(libra_server, net_http, app_name, rhlogin, password)
end
end
namespace = user_info['user_info']['namespace']
rhc_domain = user_info['user_info']['rhc_domain']
fqdn = "#{app_name}-#{namespace}.#{rhc_domain}"
loop = 0
unless no_dns
puts "Now your new domain name is being propagated worldwide (this might take a minute)..."
sleep 15
sleep_time = 2
while loop < MAX_RETRIES && !hostexist?(fqdn)
sleep sleep_time
loop+=1
puts " retry # #{loop} - Waiting for DNS: #{fqdn}"
sleep_time = delay(sleep_time)
end
end
if loop >= MAX_RETRIES
puts "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nWARNING: We weren't able to lookup your hostname (\#{fqdn}) \nin a reasonable amount of time. This can happen periodically and will just\ntake an extra minute or two to propagate depending on where you are in the\nworld. Once you are able to access your application in a browser, you can then\nclone your git repository.\n\n Application URL: http://\#{fqdn}\n\n Git Repository URL: \#{git_url}\n\n Git Clone command: \n git clone \#{git_url} \#{repo_dir}\n\nIf you can't get your application '\#{app_name}' running in the browser, you can\nalso try destroying and recreating the application as well using:\n\n rhc-ctl-app -c destroy -a \#{app_name} -l \#{rhlogin}\n\nIf this doesn't work for you, let us know in the forums or in IRC and we'll\nmake sure to get you up and running.\n\n Forums: https://www.redhat.com/openshift/forums/express\n\n IRC: #openshift (on Freenode)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"
exit 0
end
git_url = "ssh://#{app_uuid}@#{app_name}-#{namespace}.#{rhc_domain}/~/git/#{app_name}.git/"
unless no_git
puts "Pulling new repo down"
puts "git clone --quiet #{git_url} #{repo_dir}" if @mydebug
quiet = (@mydebug ? ' ' : '--quiet ')
git_clone = %x<git clone #{quiet} #{git_url} #{repo_dir}>
if $?.exitstatus != 0
puts "Error in git clone"
puts git_clone
exit 216
end
else
if no_git_message
puts no_git_message
else
puts "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nIMPORTANT: Since the -n flag was specified, no local repo has been created.\nThis means you can't make changes to your published application until after\nyou clone the repo yourself. See the git url below for more information.\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"
end
end
unless no_git
at_exit do
unless $!.nil? || $!.is_a?(SystemExit) && $!.success?
puts "Cleaning up git repo"
FileUtils.rm_rf repo_dir
end
end
end
return {:app_name => app_name,
:fqdn => fqdn,
:health_check_path => health_check_path,
:git_url => git_url,
:repo_dir => repo_dir,
:result => result
}
end