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
# File 'lib/osctld/commands/container/prlimit_set.rb', line 41

def parse(v)
  return v if v.is_a?(Integer)
  raise "a limit must be an integer or 'unlimited'" if v != 'unlimited'

  v
end

#validate(name, soft, hard) ⇒ Object (protected)



48
49
50
51
52
53
54
55
56
57
# File 'lib/osctld/commands/container/prlimit_set.rb', line 48

def validate(name, soft, hard)
  raise "'#{name}' is not supported" unless LIMITS.include?(name)

  if soft.is_a?(Integer) && hard.is_a?(Integer) && soft > hard
    raise 'soft has to be lower than hard'

  elsif (soft == :unlimited || hard == :unlimited) && soft != hard
    raise 'either both soft and hard are unlimited, or neither is'
  end
end