Class: OsCtl::Cli::Group

Inherits:
Command show all
Includes:
Assets, Attributes, CGroupParams, Devices
Defined in:
lib/osctl/cli/group.rb

Constant Summary collapse

FIELDS =
%i(
  pool
  name
  path
  full_path
) + CGroupParams::CGPARAM_STATS
FILTERS =
%i(
  pool
)
DEFAULT_FIELDS =
%i(
  pool
  name
  memory
  cpu_time
)

Constants included from Devices

Devices::DEVICES_FIELDS

Constants included from CGroupParams

CGroupParams::CGPARAM_DEFAULT_FIELDS, CGroupParams::CGPARAM_FIELDS, CGroupParams::CGPARAM_FILTERS, CGroupParams::CGPARAM_STATS

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods included from Attributes

#do_set_attr, #do_unset_attr

Methods included from Assets

#print_assets

Methods included from Devices

#do_device_add, #do_device_chmod, #do_device_delete, #do_device_inherit, #do_device_list, #do_device_promote, #do_device_replace, #do_device_set_inherit, #do_device_unset_inherit

Methods included from CGroupParams

#cg_add_stats, #cg_blkio_stats, #cg_read_stats, #do_cgparam_apply, #do_cgparam_list, #do_cgparam_replace, #do_cgparam_set, #do_cgparam_unset, #do_set_cpu_limit, #do_set_memory, #do_unset_cpu_limit, #do_unset_memory, #parse_cgparams, #parse_memory_stat, #parse_subsystem, #read_cgparam, #read_memory_usage

Methods inherited from Command

#cli_opt, #format_output, #initialize, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, #require_args!, run

Methods included from Utils::Humanize

#break_interval, #format_long_duration, #format_percent, #format_short_duration, #humanize_data, #humanize_time_ns, #parse_data

Constructor Details

This class inherits a constructor from OsCtl::Cli::Command

Instance Method Details

#assetsObject



172
173
174
175
# File 'lib/osctl/cli/group.rb', line 172

def assets
  require_args!('name')
  print_assets(:group_assets, name: args[0], pool: gopts[:pool])
end

#cgparam_applyObject



192
193
194
195
# File 'lib/osctl/cli/group.rb', line 192

def cgparam_apply
  require_args!('name')
  do_cgparam_apply(:group_cgparam_apply, name: args[0], pool: gopts[:pool])
end

#cgparam_listObject



177
178
179
180
# File 'lib/osctl/cli/group.rb', line 177

def cgparam_list
  require_args!('name')
  do_cgparam_list(:group_cgparam_list, name: args[0], pool: gopts[:pool])
end

#cgparam_replaceObject



197
198
199
200
# File 'lib/osctl/cli/group.rb', line 197

def cgparam_replace
  require_args!('name')
  do_cgparam_replace(:group_cgparam_replace, name: args[0], pool: gopts[:pool])
end

#cgparam_setObject



182
183
184
185
# File 'lib/osctl/cli/group.rb', line 182

def cgparam_set
  require_args!('name', 'parameter', 'value')
  do_cgparam_set(:group_cgparam_set, name: args[0], pool: gopts[:pool])
end

#cgparam_unsetObject



187
188
189
190
# File 'lib/osctl/cli/group.rb', line 187

def cgparam_unset
  require_args!('name', 'parameter')
  do_cgparam_unset(:group_cgparam_unset, name: args[0], pool: gopts[:pool])
end

#createObject



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/osctl/cli/group.rb', line 100

def create
  require_args!('name')

  cmd_opts = {
    name: args[0],
    pool: opts[:pool] || gopts[:pool],
    parents: opts[:parents],
    cgparams: parse_cgparams,
  }

  osctld_fmt(:group_create, cmd_opts)
end

#deleteObject



113
114
115
116
# File 'lib/osctl/cli/group.rb', line 113

def delete
  require_args!('name')
  osctld_fmt(:group_delete, name: args[0], pool: gopts[:pool])
end

#device_addObject



207
208
209
210
# File 'lib/osctl/cli/group.rb', line 207

def device_add
  require_args!('name', 'type', 'major', 'minor', 'mode')
  do_device_add(:group_device_add, name: args[0], pool: gopts[:pool])
end

#device_chmodObject



217
218
219
220
# File 'lib/osctl/cli/group.rb', line 217

def device_chmod
  require_args!('name', 'type', 'major', 'minor', 'mode')
  do_device_chmod(:group_device_chmod, name: args[0], pool: gopts[:pool])
end

#device_deleteObject



212
213
214
215
# File 'lib/osctl/cli/group.rb', line 212

def device_delete
  require_args!('name', 'type', 'major', 'minor')
  do_device_delete(:group_device_delete, name: args[0], pool: gopts[:pool])
end

#device_inheritObject



227
228
229
230
# File 'lib/osctl/cli/group.rb', line 227

def device_inherit
  require_args!('name', 'type', 'major', 'minor')
  do_device_inherit(:group_device_inherit, name: args[0], pool: gopts[:pool])
end

#device_listObject



202
203
204
205
# File 'lib/osctl/cli/group.rb', line 202

def device_list
  require_args!('name')
  do_device_list(:group_device_list, name: args[0], pool: gopts[:pool])
end

#device_promoteObject



222
223
224
225
# File 'lib/osctl/cli/group.rb', line 222

def device_promote
  require_args!('name', 'type', 'major', 'minor')
  do_device_chmod(:group_device_promote, name: args[0], pool: gopts[:pool])
end

#device_replaceObject



242
243
244
245
# File 'lib/osctl/cli/group.rb', line 242

def device_replace
  require_args!('name')
  do_device_replace(:group_device_replace, name: args[0], pool: gopts[:pool])
end

#device_set_inheritObject



232
233
234
235
# File 'lib/osctl/cli/group.rb', line 232

def device_set_inherit
  require_args!('name', 'type', 'major', 'minor')
  do_device_set_inherit(:group_device_set_inherit, name: args[0], pool: gopts[:pool])
end

#device_unset_inheritObject



237
238
239
240
# File 'lib/osctl/cli/group.rb', line 237

def device_unset_inherit
  require_args!('name', 'type', 'major', 'minor')
  do_device_unset_inherit(:group_device_unset_inherit, name: args[0], pool: gopts[:pool])
end

#listObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/osctl/cli/group.rb', line 31

def list
  if opts[:list]
    puts FIELDS.join("\n")
    return
  end

  cmd_opts = {}
  fmt_opts = {
    layout: :columns,
    sort: opts[:sort] && opts[:sort].split(',').map(&:to_sym),
  }

  cmd_opts[:names] = args if args.count > 0

  FILTERS.each do |v|
    [gopts, opts].each do |options|
      next unless options[v]
      cmd_opts[v] = options[v].split(',')
    end
  end

  fmt_opts[:header] = false if opts['hide-header']
  cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : DEFAULT_FIELDS

  c = osctld_open
  groups = cg_add_stats(
    c,
    c.cmd_data!(:group_list, cmd_opts),
    lambda { |g| g[:full_path] },
    cols,
    gopts[:parsable]
  )
  c.close

  format_output(groups, cols, fmt_opts)
end

#set_attrObject



153
154
155
156
157
158
159
160
161
# File 'lib/osctl/cli/group.rb', line 153

def set_attr
  require_args!('name', 'attribute', 'value')
  do_set_attr(
    :group_set,
    {name: args[0], pool: gopts[:pool]},
    args[1],
    args[2],
  )
end

#set_cpu_limitObject



118
119
120
121
# File 'lib/osctl/cli/group.rb', line 118

def set_cpu_limit
  require_args!('name', 'limit')
  do_set_cpu_limit(:group_cgparam_set, name: args[0], pool: gopts[:pool])
end

#set_memoryObject



133
134
135
136
137
138
139
140
141
# File 'lib/osctl/cli/group.rb', line 133

def set_memory
  require_args!('name', 'memory')
  do_set_memory(
    :group_cgparam_set,
    :group_cgparam_unset,
    name: args[0],
    pool: gopts[:pool]
  )
end

#showObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/osctl/cli/group.rb', line 73

def show
  if opts[:list]
    puts FIELDS.join("\n")
    return
  end

  require_args!('name')

  cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : FIELDS

  fmt_opts = {layout: :rows}
  fmt_opts[:header] = false if opts['hide-header']

  c = osctld_open
  group = c.cmd_data!(:group_show, name: args[0], pool: gopts[:pool])
  cg_add_stats(
    c,
    group,
    group[:full_path],
    cols,
    gopts[:parsable]
  )
  c.close

  format_output(group, cols, fmt_opts)
end

#treeObject



68
69
70
71
# File 'lib/osctl/cli/group.rb', line 68

def tree
  require_args!('pool')
  Tree.print(args[0], parsable: gopts[:parsable], color: gopts[:color])
end

#unset_attrObject



163
164
165
166
167
168
169
170
# File 'lib/osctl/cli/group.rb', line 163

def unset_attr
  require_args!('name', 'attribute')
  do_unset_attr(
    :group_unset,
    {name: args[0], pool: gopts[:pool]},
    args[1],
  )
end

#unset_cpu_limitObject



123
124
125
126
127
128
129
130
131
# File 'lib/osctl/cli/group.rb', line 123

def unset_cpu_limit
  require_args!('name')
  do_unset_cpu_limit(
    :group_cgparam_set,
    :group_cgparam_unset,
    name: args[0],
    pool: gopts[:pool]
  )
end

#unset_memoryObject



143
144
145
146
147
148
149
150
151
# File 'lib/osctl/cli/group.rb', line 143

def unset_memory
  require_args!('name')
  do_unset_memory(
    :group_cgparam_set,
    :group_cgparam_unset,
    name: args[0],
    pool: gopts[:pool]
  )
end