Class: OpenShift::Node

Inherits:
Model
  • Object
show all
Defined in:
lib/openshift-origin-node/model/node.rb

Class Method Summary collapse

Class Method Details

.get_cartridge_info(cart_name, porcelain = false, oo_debug = false) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/openshift-origin-node/model/node.rb', line 68

def self.get_cartridge_info(cart_name, porcelain = false, oo_debug = false)
  output = ""
  cart_found = false

  cartridge_path = OpenShift::Config.new.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.2", "postgresql-8.4"].include? cart_dir
    path = File.join(cartridge_path, cart_dir, "info", "manifest.yml")
    begin
      cart = OpenShift::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 oo_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 = OpenShift::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 oo_debug
        print "#{e.message}\n#{e.backtrace.inspect}\n" unless porcelain
      end
    end
  end
  output
end

.get_cartridge_list(list_descriptors = false, porcelain = false, oo_debug = false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/openshift-origin-node/model/node.rb', line 25

def self.get_cartridge_list(list_descriptors = false, porcelain = false, oo_debug = false)
  carts = []

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

  print "\n\n\n" if oo_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) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/openshift-origin-node/model/node.rb', line 111

def self.get_quota(uuid)
  cmd = %&quota -w #{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) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/openshift-origin-node/model/node.rb', line 123

def self.set_quota(uuid, blocksmax, inodemax)
  cur_quota = get_quota(uuid)
  inodemax = cur_quota[6] if inodemax.to_s.empty?
  
  mountpoint = %x[quota -w #{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