lib/cli/commands/apps.rb in af-0.3.18.12 vs lib/cli/commands/apps.rb in af-0.3.19.beta.1
- old
+ new
@@ -21,22 +21,22 @@
apps.sort! {|a, b| a[:name] <=> b[:name] }
return display JSON.pretty_generate(apps || []) if @options[:json]
display "\n"
return display "No Applications" if apps.nil? || apps.empty?
-
+
infra_supported = !apps.detect { |a| a[:infra] }.nil?
apps_table = table do |t|
t.headings = 'Application', '# ', 'Health', 'URLS', 'Services'
t.headings << 'In' if infra_supported
apps.each do |app|
a = [app[:name], app[:instances], health(app), app[:uris].join(', '), app[:services].join(', ')]
if infra_supported
a << ( app[:infra] ? app[:infra][:provider] : " " )
end
- t << a
+ t << a
end
end
display apps_table
end
@@ -56,11 +56,11 @@
end
def console(appname, interactive=true)
app = client.app_info(appname)
- infra_name = app[:infra] ? app[:infra][:name] : 'aws' # FIXME
+ infra_name = app[:infra] ? app[:infra][:name] : 'aws' # FIXME
unless defined? Caldecott
display "To use `vmc rails-console', you must first install Caldecott:"
display ""
display "\tgem install caldecott"
@@ -211,32 +211,32 @@
end
def download(appname, path=nil)
path = File.expand_path(path || "#{appname}.zip" )
banner = "Downloading last pushed source code to #{path}: "
- display banner, false
+ display banner, false
client.app_download(appname, path)
display 'OK'.green
end
-
+
def pull(appname, path=nil)
path = File.expand_path(path || appname)
banner = "Pulling last pushed source code: "
- display banner, false
+ display banner, false
client.app_pull(appname, path)
display 'OK'.green
end
-
+
def clone(src_appname, dest_appname, dest_infra=nil)
-
+
# FIXME need to ask for dest_appname if nil
-
+
err "Application '#{dest_appname}' already exists" if app_exists?(dest_appname)
app = client.app_info(src_appname)
- if client.infra_supported?
+ if client.infra_supported?
dest_infra = @options[:infra] || client.infra_name_for_description(
ask("Select Infrastructure",:indexed => true, :choices => client.infra_descriptions))
client.infra = dest_infra
end
@@ -249,23 +249,23 @@
Dir.mktmpdir do |dir|
zip_path = File.join(dir,src_appname)
pull(src_appname,zip_path)
display "Cloning '#{src_appname}' to '#{dest_appname}': "
-
+
manifest = {
:name => "#{dest_appname}",
:staging => app[:staging],
:uris => [ url ],
:instances => app[:instances],
:resources => app[:resources]
}
manifest[:staging][:command] = app[:staging][:command] if app[:staging][:command]
manifest[:infra] = { :provider => dest_infra } if dest_infra
-
- client.create_app(dest_appname, manifest)
-
+
+ client.create_app(dest_appname, manifest)
+
# Stage and upload the app bits.
upload_app_bits(dest_appname, zip_path, dest_infra)
# Clone services
client.services.select { |s| app[:services].include?(s[:name])}.each do |service|
@@ -287,19 +287,19 @@
import_info = client.import_service(cloned_service_name,export_info[:uri])
if import_info
display 'OK'.green
else
err "Import data into '#{service}' failed"
- end
+ end
end
-
+
no_start = @options[:nostart]
- start(dest_appname, true) unless no_start
-
+ start(dest_appname, true) unless no_start
+
end
end
-
+
def logs(appname)
# Check if we have an app before progressing further
client.app_info(appname)
return grab_all_logs(appname) if @options[:all] && !@options[:instance]
instance = @options[:instance] || '0'
@@ -522,11 +522,11 @@
files = Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
check_unreachable_links(path,afi.included_files(files))
copy_files( path, ignore_sockets( afi.included_files(files)), explode_dir )
-
+
end
end
end
@@ -733,13 +733,21 @@
if d[:state] == "STARTED" && expected_instance > 0 && healthy_instances
health = format("%.3f", healthy_instances.to_f / expected_instance).to_f
end
- return 'RUNNING' if health && health == 1.0
- return "#{(health * 100).round}%" if health
- return 'N/A'
+ if health
+ if health == 1.0
+ return "RUNNING"
+ else
+ return "#{(health * 100).round}%"
+ end
+ elsif d[:state] == "STARTED"
+ return 'N/A' # unstarted instances
+ else
+ return d[:state]
+ end
end
def app_started_properly(appname, error_on_health)
app = client.app_info(appname)
case health(app)
@@ -1109,15 +1117,15 @@
:memory => mem_quota
}
}
manifest[:staging][:command] = command if command
manifest[:infra] = { :provider => infra } if infra
-
+
# Send the manifest to the cloud controller
client.create_app(appname, manifest)
display 'OK'.green
-
+
existing = Set.new(client.services.collect { |s| s[:name] })
if @app_info && services = @app_info["services"]
services.each do |name, info|
unless existing.include? name