Class: OsCtld::PrLimits::Manager
- Inherits:
-
Object
- Object
- OsCtld::PrLimits::Manager
- Includes:
- Lockable
- Defined in:
- lib/osctld/prlimits/manager.rb
Instance Attribute Summary collapse
-
#ct ⇒ Object
readonly
protected
Returns the value of attribute ct.
-
#prlimits ⇒ Object
readonly
protected
Returns the value of attribute prlimits.
Class Method Summary collapse
-
.default(ct) ⇒ Object
Create new resource limits with default values.
-
.load(ct, cfg) ⇒ Object
Load prlimits from config.
Instance Method Summary collapse
- #[](name) ⇒ PrLimits::PrLimit?
- #contains?(name) ⇒ Boolean
-
#dump ⇒ Object
Dump to config.
-
#dup(new_ct) ⇒ Object
rubocop:enable Style/HashTransformValues.
- #each {|name, prlimit| ... } ⇒ Object
-
#export ⇒ Object
Export to client.
-
#initialize(ct, entries: {}) ⇒ Manager
constructor
A new instance of Manager.
- #set(name, soft, hard) ⇒ Object
- #unset(name) ⇒ Object
Methods included from Lockable
#exclusively, included, #inclusively, #init_lock, #lock, #unlock
Constructor Details
#initialize(ct, entries: {}) ⇒ Manager
Returns a new instance of Manager.
31 32 33 34 35 36 |
# File 'lib/osctld/prlimits/manager.rb', line 31 def initialize(ct, entries: {}) init_lock @ct = ct @prlimits = entries end |
Instance Attribute Details
#ct ⇒ Object (readonly, protected)
Returns the value of attribute ct.
106 107 108 |
# File 'lib/osctld/prlimits/manager.rb', line 106 def ct @ct end |
#prlimits ⇒ Object (readonly, protected)
Returns the value of attribute prlimits.
106 107 108 |
# File 'lib/osctld/prlimits/manager.rb', line 106 def prlimits @prlimits end |
Class Method Details
.default(ct) ⇒ Object
Create new resource limits with default values
24 25 26 27 28 |
# File 'lib/osctld/prlimits/manager.rb', line 24 def self.default(ct) new(ct, entries: { 'nofile' => PrLimits::PrLimit.new('nofile', 1024, SystemLimits::FILE_MAX_DEFAULT) }) end |
.load(ct, cfg) ⇒ Object
Load prlimits from config
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/osctld/prlimits/manager.rb', line 10 def self.load(ct, cfg) entries = if cfg.is_a?(Array) cfg.map do |v| [v['name'], PrLimits::PrLimit.load(v['name'], v)] end else cfg.map { |k, v| [k, PrLimits::PrLimit.load(k, v)] } end new(ct, entries: entries.to_h) end |
Instance Method Details
#[](name) ⇒ PrLimits::PrLimit?
64 65 66 |
# File 'lib/osctld/prlimits/manager.rb', line 64 def [](name) inclusively { prlimits[name] } end |
#contains?(name) ⇒ Boolean
69 70 71 |
# File 'lib/osctld/prlimits/manager.rb', line 69 def contains?(name) inclusively { prlimits.has_key?(name) } end |
#dump ⇒ Object
Dump to config
84 85 86 |
# File 'lib/osctld/prlimits/manager.rb', line 84 def dump inclusively { prlimits.to_h { |k, v| [k, v.dump] } } end |
#dup(new_ct) ⇒ Object
rubocop:enable Style/HashTransformValues
97 98 99 100 101 102 |
# File 'lib/osctld/prlimits/manager.rb', line 97 def dup(new_ct) ret = super() ret.instance_variable_set('@ct', new_ct) ret.instance_variable_set('@prlimits', prlimits.map(&:clone)) ret end |
#each {|name, prlimit| ... } ⇒ Object
75 76 77 |
# File 'lib/osctld/prlimits/manager.rb', line 75 def each(&block) inclusively { prlimits.each(&block) } end |
#export ⇒ Object
Export to client
89 90 91 92 93 |
# File 'lib/osctld/prlimits/manager.rb', line 89 def export inclusively do prlimits.to_h { |k, v| [k, v.export] } end end |
#set(name, soft, hard) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/osctld/prlimits/manager.rb', line 41 def set(name, soft, hard) exclusively do if prlimits.has_key?(name) prlimits[name].set(soft, hard) else prlimits[name] = PrLimits::PrLimit.new(name, soft, hard) end end ct.save_config ct.lxc_config.configure_prlimits SystemLimits.ensure_nofile(hard) if name == 'nofile' end |
#unset(name) ⇒ Object
56 57 58 59 60 |
# File 'lib/osctld/prlimits/manager.rb', line 56 def unset(name) exclusively { prlimits.delete(name) } ct.save_config ct.lxc_config.configure_prlimits end |