# File lib/openshift-origin-node/utils/cgroups.rb, line 57 def initialize(uuid) # TODO: Make this configurable and move libcgroup impl to a stand-alone plugin gem. @impl = ::OpenShift::Runtime::Utils::Cgroups::Libcgroup.new(uuid) end
Public: List the templates available in the implementation
# File lib/openshift-origin-node/utils/cgroups.rb, line 166 def self.show_templates @@TEMPLATE_SET.keys end
Public: Apply a cgroups template to a gear. If called with
a block, the default will be restored after the block is completed and return the value of the block.
# File lib/openshift-origin-node/utils/cgroups.rb, line 116 def apply_profile(type, &blk) t = templates[type] if t == nil raise ArgumentError, "Unknown template: #{type}" end r = store(t) if blk begin r = blk.call(type) ensure store(templates[:default]) end end r end
Public: Distribute this user's processes into their cgroup
# File lib/openshift-origin-node/utils/cgroups.rb, line 156 def classify_processes @impl.classify_processes end
# File lib/openshift-origin-node/utils/cgroups.rb, line 62 def create @impl.create(templates[:default]) end
Get the current values for any keys specified in the default template
# File lib/openshift-origin-node/utils/cgroups.rb, line 89 def current_values keys = templates.map { |k,v| v.keys }.flatten.uniq fetch(*keys) end
# File lib/openshift-origin-node/utils/cgroups.rb, line 66 def delete @impl.delete end
Public: Fetch the values from the current cgroup
- If args is a single value, it will return the value - If args is an array, it will return a Template of values
# File lib/openshift-origin-node/utils/cgroups.rb, line 97 def fetch(*args) t = @impl.fetch(*args) if t.length > 1 t else t.values.first end end
Public: List the process ids which are a member of this gear's cgroup.
# File lib/openshift-origin-node/utils/cgroups.rb, line 151 def processes @impl.processes end
Public: Infer the current profile based on current values.
# File lib/openshift-origin-node/utils/cgroups.rb, line 135 def profile cur = current_values tmpls = templates.map { |k,v| [ k, v.length ] }.sort { |a,b| a[1] <=> b[1] }.map { |ent| ent[0] } # Return the most specific match to all the current values or unknown prof = :unknown tmpls.each do |tmpl| cmpvals = cur.select { |k,v| templates[tmpl].keys.include? k } if cmpvals == templates[tmpl] prof = tmpl end end prof end
# File lib/openshift-origin-node/utils/cgroups.rb, line 51 def restore(&blk) apply_profile(:default, &blk) end
Public: List the templates available to this gear
# File lib/openshift-origin-node/utils/cgroups.rb, line 161 def show_templates @@TEMPLATE_SET.keys end
Public: Store cgroups configuration in the gear
# File lib/openshift-origin-node/utils/cgroups.rb, line 107 def store(*args) if not args.empty? @impl.store(*args) end end
# File lib/openshift-origin-node/utils/cgroups.rb, line 70 def templates if not @@templates_cache res = Config.new('/etc/openshift/resource_limits.conf') @@templates_cache={ :default => {} } @@TEMPLATE_SET.each do |templ, calls| if templ != :default t = param_cfg(res.get_group("cg_template_#{templ}")) @@templates_cache[templ] = t @@templates_cache[:default].update(Hash[*(t.map { |k,v| [k, @impl.parameters[k]] }.flatten)]) end end @@templates_cache[:default].update(param_cfg(res)) @@templates_cache.freeze end @@templates_cache end
Private: Extract parameters from the configuration
# File lib/openshift-origin-node/utils/cgroups.rb, line 173 def param_cfg(res) Hash[ *(@impl.parameters.map { |k,v| [k, res.get(k)] }.select { |ent| ent[1] }.flatten) ] end