Module: OsCtld::Utils::CGroupParams

Instance Method Summary collapse

Instance Method Details

#apply(groupable, force: true) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/osctld/utils/cgroup_params.rb', line 62

def apply(groupable, force: true)
  manipulate(groupable) do
    groupable.cgparams.apply(keep_going: force) do |subsystem|
      if groupable.respond_to?(:abs_apply_cgroup_path)
        groupable.abs_apply_cgroup_path(subsystem)

      else
        groupable.abs_cgroup_path(subsystem)
      end
    end

    ok
  end
end

#info(groupable) ⇒ Object (protected)



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/osctld/utils/cgroup_params.rb', line 98

def info(groupable)
  ret = []

  groupable.cgparams.each do |p|
    next if opts[:version] && p.version != opts[:version]
    next if opts[:parameters] && !opts[:parameters].include?(p.name)
    next if opts[:subsystem] && !opts[:subsystem].include?(p.subsystem)

    info = p.export
    info[:abs_path] = File.join(groupable.abs_cgroup_path(p.subsystem), p.name)
    info[:group] = groupable.is_a?(Group) ? groupable.name : nil

    ret << info
  end

  ret
end

#list(groupable) ⇒ Object

Parameters:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/osctld/utils/cgroup_params.rb', line 4

def list(groupable)
  ret = []
  is_ct = groupable.is_a?(Container)

  if opts[:all]
    if is_ct
      groupable.group.groups_in_path.each do |g|
        ret.concat(info(g))
      end

    else
      groupable.groups_in_path.each do |g|
        ret.concat(info(g))
      end
    end
  end

  ret.concat(info(groupable)) if !opts[:all] || is_ct

  ok(ret)
end

#replace(groupable) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/osctld/utils/cgroup_params.rb', line 77

def replace(groupable)
  manipulate(groupable) do
    groupable.cgparams.replace(
      groupable.cgparams.import(opts[:parameters])
    ) do |subsystem|
      if groupable.respond_to?(:abs_apply_cgroup_path)
        groupable.abs_apply_cgroup_path(subsystem)

      else
        groupable.abs_cgroup_path(subsystem)
      end
    end

    apply(groupable)
  end
rescue CGroupSubsystemNotFound, CGroupParameterNotFound => e
  error(e.message)
end

#set(groupable, opts, apply: true) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/osctld/utils/cgroup_params.rb', line 26

def set(groupable, opts, apply: true)
  params = groupable.cgparams.import(opts[:parameters])

  manipulate(groupable) do
    groupable.cgparams.set(params, append: opts[:append])

    if apply
      ret = apply(groupable)
      return ret unless ret[:status]
    end

    ok
  end
rescue CGroupSubsystemNotFound, CGroupParameterNotFound => e
  error(e.message)
end

#unset(groupable, opts, reset: true, keep_going: false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/osctld/utils/cgroup_params.rb', line 43

def unset(groupable, opts, reset: true, keep_going: false)
  manipulate(groupable) do
    groupable.cgparams.unset(
      opts[:parameters],
      reset:,
      keep_going:
    ) do |subsystem|
      if groupable.respond_to?(:abs_apply_cgroup_path)
        groupable.abs_apply_cgroup_path(subsystem)

      else
        groupable.abs_cgroup_path(subsystem)
      end
    end

    ok
  end
end