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
)

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!, 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)



40
41
42
43
44
# File 'lib/osctld/commands/container/prlimit_set.rb', line 40

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

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



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

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

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

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