class StickShift::Node

Public Class Methods

get_cartridge_info(cart_name, porcelain = false, ss_debug = false) click to toggle source
# File lib/stickshift-node/model/node.rb, line 84
def self.get_cartridge_info(cart_name, porcelain = false, ss_debug = false)
  output = ""
  cart_found = false

  cartridge_path = StickShift::Config.instance.get("CARTRIDGE_BASE_PATH")
  Dir.foreach(cartridge_path) do |cart_dir|
    next if [".", "..", "embedded", "abstract", "abstract-httpd", "mysql-5.1"].include? cart_dir
    path = File.join(cartridge_path, cart_dir, "info", "manifest.yml")
    begin
      cart = StickShift::Cartridge.new.from_descriptor(YAML.load(File.open(path)))
      if cart.name == cart_name
        output << "CLIENT_RESULT: "
        output << cart.to_descriptor.to_json
        cart_found = true
        break
      end
    rescue Exception => e
      print "ERROR\n" if ss_debug
      print "#{e.message}\n#{e.backtrace.inspect}\n" unless porcelain
    end
  end

  embedded_cartridge_path = File.join(cartridge_path, "embedded")
  if (! cart_found) and File.directory?(embedded_cartridge_path)
    Dir.foreach(embedded_cartridge_path) do |cart_dir|
      next if [".",".."].include? cart_dir
      path = File.join(embedded_cartridge_path, cart_dir, "info", "manifest.yml")
      begin
        cart = StickShift::Cartridge.new.from_descriptor(YAML.load(File.open(path)))
        if cart.name == cart_name
          output << "CLIENT_RESULT: "
          output << cart.to_descriptor.to_json
          break
        end
      rescue Exception => e
        print "ERROR\n" if ss_debug
        print "#{e.message}\n#{e.backtrace.inspect}\n" unless porcelain
      end
    end
  end
  output
end
get_cartridge_list(list_descriptors = false, porcelain = false, ss_debug = false) click to toggle source
# File lib/stickshift-node/model/node.rb, line 25
def self.get_cartridge_list(list_descriptors = false, porcelain = false, ss_debug = false)
  carts = []

  cartridge_path = StickShift::Config.instance.get("CARTRIDGE_BASE_PATH")
  Dir.foreach(cartridge_path) do |cart_dir|
    next if [".", "..", "embedded", "abstract", "abstract-httpd", "haproxy-1.4", "mysql-5.1", "mongodb-2.0"].include? cart_dir
    path = File.join(cartridge_path, cart_dir, "info", "manifest.yml")
    begin
      print "Loading #{cart_dir}..." if ss_debug
      carts.push StickShift::Cartridge.new.from_descriptor(YAML.load(File.open(path)))
      print "OK\n" if ss_debug
    rescue Exception => e
      print "ERROR\n" if ss_debug
      print "#{e.message}\n#{e.backtrace.inspect}\n" unless porcelain
    end
  end

  embedded_cartridge_path = File.join(cartridge_path, "embedded")
  if File.directory?(embedded_cartridge_path)
    Dir.foreach(embedded_cartridge_path) do |cart_dir|
      next if [".",".."].include? cart_dir
      path = File.join(embedded_cartridge_path, cart_dir, "info", "manifest.yml")
      begin
        print "Loading #{cart_dir}..." if ss_debug
        carts.push StickShift::Cartridge.new.from_descriptor(YAML.load(File.open(path)))
        print "OK\n" if ss_debug
      rescue Exception => e
        print "ERROR\n" if ss_debug
        print "#{e.message}\n#{e.backtrace.inspect}\n" unless porcelain
      end
    end
  end

  print "\n\n\n" if ss_debug

  output = ""
  if porcelain
    if list_descriptors
      output << "CLIENT_RESULT: "
      output << carts.map{|c| c.to_descriptor.to_yaml}.to_json
    else
      output << "CLIENT_RESULT: "
      output << carts.map{|c| c.name}.to_json
    end
  else
    if list_descriptors
      carts.each do |c|
        output << "Cartridge name: #{c.name}\n\nDescriptor:\n #{c.to_descriptor.inspect}\n\n\n"
      end
    else
      output << "Cartridges:\n"
      carts.each do |c|
        output << "\t#{c.name}\n"
      end
    end
  end
  output
end
get_quota(uuid) click to toggle source
# File lib/stickshift-node/model/node.rb, line 127
def self.get_quota(uuid)
  cmd = %Qquota #{uuid} | awk '/^.*\\/dev/ {print $1":"$2":"$3":"$4":"$5":"$6":"$7}'; exit ${PIPESTATUS[0]}&
  st, out, errout = systemu cmd
  if st.exitstatus == 0 || st.exitstatus == 1
    arr = out.strip.split(":")
    raise NodeCommandException.new "Error: #{errout} executing command #{cmd}" unless arr.length == 7
    arr
  else
    raise NodeCommandException.new "Error: #{errout} executing command #{cmd}"
  end
end
set_quota(uuid, blocksmax, inodemax) click to toggle source
# File lib/stickshift-node/model/node.rb, line 139
def self.set_quota(uuid, blocksmax, inodemax)
  mountpoint = %x[quota #{uuid} | awk '/^.*\\/dev/ {print $1}']
  cmd = "setquota -u #{uuid} 0 #{blocksmax} 0 #{inodemax} -a #{mountpoint}"
  st, out, errout = systemu cmd
  raise NodeCommandException.new "Error: #{errout} executing command #{cmd}" unless st.exitstatus == 0
end