Sha256: 0a87eae844ff71f98b886ebac764a2ee5d8e78d126ac524ad5aaed0eb6031856

Contents?: true

Size: 1.71 KB

Versions: 36

Compression:

Stored size: 1.71 KB

Contents

require "cf/cli/app/base"

module CF::App
  class Scale < Base
    desc "Update the instances/memory limit for an application"
    group :apps, :info
    input :app, :desc => "Application to update", :argument => true,
          :from_given => by_name(:app)
    input :instances, :desc => "Number of instances to run",
          :type => :numeric
    input :memory, :desc => "Memory limit"
    input :disk, :desc => "Disk quota"
    input :restart, :desc => "Restart app after updating?", :default => true

    def scale
      app = input[:app]

      if input.has?(:instances)
        instances = input[:instances, app.total_instances]
      end

      if input.has?(:memory)
        memory = input[:memory, app.memory]
      end

      if input.has?(:disk)
        disk = input[:disk, human_mb(app.disk_quota)]
      end

      unless instances || memory || disk
        instances = input[:instances, app.total_instances]
        memory = input[:memory, app.memory]
      end

      app.total_instances = instances if input.has?(:instances)
      app.memory = megabytes(memory) if input.has?(:memory)
      app.disk_quota = megabytes(disk) if input.has?(:disk)

      fail "No changes!" unless app.changed?

      with_progress("Scaling #{c(app.name, :name)}") do
        app.update!
      end

      needs_restart = app.changes.key?(:memory) || app.changes.key?(:disk_quota)

      if needs_restart && app.started? && input[:restart]
        invoke :restart, :app => app
      end
    end

    private

    def ask_instances(default)
      ask("Instances", :default => default)
    end

    def ask_memory(default)
      ask("Memory Limit", :choices => memory_choices,
          :default => human_mb(default), :allow_other => true)
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
cf-5.4.7 lib/cf/cli/app/scale.rb
cf-5.4.7.rc1 lib/cf/cli/app/scale.rb
cf-5.4.5 lib/cf/cli/app/scale.rb
cf-5.4.4 lib/cf/cli/app/scale.rb
trucker-cli-0.0.3 lib/cf/cli/app/scale.rb
cf-5.4.3 lib/cf/cli/app/scale.rb
cf-5.4.2 lib/cf/cli/app/scale.rb
trucker-cli-0.0.2 lib/cf/cli/app/scale.rb
trucker-cli-0.0.1 lib/cf/cli/app/scale.rb
cf-5.4.1 lib/cf/cli/app/scale.rb
cf-5.4.1.rc1 lib/cf/cli/app/scale.rb
cf-5.4.0 lib/cf/cli/app/scale.rb
cf-5.3.1 lib/cf/cli/app/scale.rb
cf-5.3.0 lib/cf/cli/app/scale.rb
cf-5.2.2 lib/cf/cli/app/scale.rb
cf-5.2.1.rc15 lib/cf/cli/app/scale.rb
cf-5.2.1.rc14 lib/cf/cli/app/scale.rb
cf-5.2.1.rc13 lib/cf/cli/app/scale.rb
cf-5.2.1.rc12 lib/cf/cli/app/scale.rb
cf-5.2.1.rc11 lib/cf/cli/app/scale.rb