Class: OsCtld::Commands::Container::PrLimitSet
- Defined in:
- lib/osctld/commands/container/prlimit_set.rb
Constant Summary collapse
- LIMITS =
%w[ as core cpu data fsize memlock msgqueue nice nofile nproc rss rtprio rttime sigpending stack ].freeze
Instance Method Summary collapse
- #execute(ct) ⇒ Object
- #find ⇒ Object
- #parse(v) ⇒ Object protected
- #validate(name, soft, hard) ⇒ Object protected
Methods inherited from Logged
Instance Method Details
#execute(ct) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/osctld/commands/container/prlimit_set.rb', line 30 def execute(ct) soft = parse(opts[:soft]) hard = parse(opts[:hard]) validate(opts[:name], soft, hard) ct.prlimits.set(opts[:name], soft, hard) ok end |
#find ⇒ Object
25 26 27 28 |
# File 'lib/osctld/commands/container/prlimit_set.rb', line 25 def find ct = DB::Containers.find(opts[:id], opts[:pool]) ct || error!('container not found') end |
#parse(v) ⇒ Object (protected)
41 42 43 44 45 46 47 |
# File 'lib/osctld/commands/container/prlimit_set.rb', line 41 def parse(v) return v if v.is_a?(Integer) error!("a limit must be an integer or 'unlimited'") if v != 'unlimited' v end |
#validate(name, soft, hard) ⇒ Object (protected)
49 50 51 52 53 54 55 56 |
# File 'lib/osctld/commands/container/prlimit_set.rb', line 49 def validate(name, soft, hard) error!("'#{name}' is not supported") unless LIMITS.include?(name) return if hard == 'unlimited' error!('soft cannot be unlimited when hard is finite') if soft == 'unlimited' error!('soft has to be lower than or equal to hard') if soft > hard end |