class RHC::Commands::Cartridge

Public Instance Methods

add(cart_type) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 42
def add(cart_type)
  cart = find_cartridge rest_client, cart_type

  say "Adding '#{cart.name}' to application '#{options.app}'"

  rest_domain = rest_client.find_domain(options.namespace)
  rest_app = rest_domain.find_application(options.app)
  rest_cartridge = rest_app.add_cartridge(cart.name)
  say "Success"

  display_cart(rest_cartridge,rest_cartridge.properties[:cart_data])

  0
end
list() click to toggle source
# File lib/rhc/commands/cartridge.rb, line 13
def list
  rest_client = RHC::Rest::Client.new(openshift_rest_node, nil, nil)
  list = rest_client.cartridges.
    map{ |c| [c.name, c.display_name || '', c.type == 'standalone' ? 'Y' : ''] }.
    sort do |a,b|
      if a[2] == 'Y' && b[2] == ''
        -1
      elsif a[2] == '' && b[2] == 'Y'
        1
      else
        a[1].downcase <=> b[1].downcase
      end
    end
  list.unshift ['==========', '=========', '=============']
  list.unshift ['Short Name', 'Full name', 'New apps only']

  paragraph{ say "Use the short name of a cartridge when interacting with your applications." }

  say table(list).join("\n")

  0
end
reload(cartridge) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 158
def reload(cartridge)
  cartridge_action cartridge, :reload

  results { say "#{cartridge} config reloaded!" }
  0
end
remove(cartridge) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 79
def remove(cartridge)
  unless options.confirm
    results { say "Removing a cartridge is a destructive operation that may result in loss of data associated with the cartridge.  You must pass the --confirm switch to this command in order to to remove the cartridge." }
    return 1
  end

  rest_domain = rest_client.find_domain(options.namespace)
  rest_app = rest_domain.find_application(options.app)
  rest_cartridge = rest_app.find_cartridge cartridge, :type => "embedded"
  rest_cartridge.destroy

  results { say "Success: Cartridge '#{rest_cartridge.name}' removed from application '#{rest_app.name}'." }
  0
end
restart(cartridge) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 126
def restart(cartridge)
  cartridge_action cartridge, :restart

  results { say "#{cartridge} restarted!" }
  0
end
scale(cartridge) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 172
def scale(cartridge)
  raise RHC::MissingScalingValueException unless options.min || options.max

  rest_domain = rest_client.find_domain(options.namespace)
  rest_app = rest_domain.find_application(options.app)
  rest_cartridge = find_cartridge rest_app, cartridge, nil

  raise RHC::CartridgeNotScalableException unless rest_cartridge.scalable?

  cart = rest_cartridge.set_scales({
    :scales_from => options.min,
    :scales_to   => options.max
  })

  results do
    say "Success: Scaling values updated"
    display_cart(cart)
  end

  0
end
show(cartridge) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 62
def show(cartridge)
  rest_domain = rest_client.find_domain(options.namespace)
  rest_app = rest_domain.find_application(options.app)
  rest_cartridge = find_cartridge rest_app, cartridge, nil

  display_cart(rest_cartridge,rest_cartridge.properties[:cart_data])

  0
end
start(cartridge) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 100
def start(cartridge)
  cartridge_action cartridge, :start

  results { say "#{cartridge} started!" }
  0
end
status(cartridge) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 139
def status(cartridge)
  rest_domain = rest_client.find_domain(options.namespace)
  rest_app = rest_domain.find_application(options.app)
  rest_cartridge = find_cartridge(rest_app, cartridge)
  msgs = rest_cartridge.status
  results {
    msgs.each do |msg|
      say msg['message']
    end
  }
  0
end
stop(cartridge) click to toggle source
# File lib/rhc/commands/cartridge.rb, line 113
def stop(cartridge)
  cartridge_action cartridge, :stop

  results { say "#{cartridge} stopped!" }
  0
end