Class: OsCtld::Commands::Container::PrLimitSet

Inherits:
Logged
  • Object
show all
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 Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Logged

#base_execute

Methods inherited from Base

#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::Commands::Base

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

#findObject



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