Class: OsCtl::Cli::CpuScheduler

Inherits:
Command
  • Object
show all
Defined in:
lib/osctl/cli/cpu_scheduler.rb

Constant Summary collapse

PACKAGE_FIELDS =
%i[
  id
  cpus
  ncpus
  containers
  containers_per_cpu
  usage_score
  usage_score_per_cpu
  enabled
].freeze

Instance Method Summary collapse

Methods inherited from Command

#cli_opt, #format_output, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, run

Instance Method Details

#disableObject



27
28
29
30
# File 'lib/osctl/cli/cpu_scheduler.rb', line 27

def disable
  require_args!
  osctld_fmt(:cpu_scheduler_disable)
end

#enableObject



22
23
24
25
# File 'lib/osctl/cli/cpu_scheduler.rb', line 22

def enable
  require_args!
  osctld_fmt(:cpu_scheduler_enable)
end

#package_disableObject



82
83
84
85
# File 'lib/osctl/cli/cpu_scheduler.rb', line 82

def package_disable
  require_args!('package')
  osctld_fmt(:cpu_scheduler_package_disable, cmd_opts: { package: args[0].to_i })
end

#package_enableObject



77
78
79
80
# File 'lib/osctl/cli/cpu_scheduler.rb', line 77

def package_enable
  require_args!('package')
  osctld_fmt(:cpu_scheduler_package_enable, cmd_opts: { package: args[0].to_i })
end

#package_listObject



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
67
68
69
70
71
72
73
74
75
# File 'lib/osctl/cli/cpu_scheduler.rb', line 37

def package_list
  require_args!

  param_selector = OsCtl::Lib::Cli::ParameterSelector.new(
    all_params: PACKAGE_FIELDS
  )

  if opts[:list]
    puts param_selector
    return
  end

  fmt_opts = {
    layout: :columns,
    cols: param_selector.parse_option(opts[:output]),
    sort: opts[:sort] && opts[:sort].split(',').map(&:to_sym),
    opts: {
      cpus: {
        label: 'CPUS',
        display: proc { |v| OsCtl::Lib::CpuMask.format(v) }
      }
    }
  }

  fmt_opts[:header] = false if opts['hide-header']

  packages = osctld_call(:cpu_scheduler_package_list)

  packages.each do |pkg|
    ncpus = pkg[:cpus].size
    ncpus_f = ncpus.to_f

    pkg[:ncpus] = ncpus
    pkg[:containers_per_cpu] = (pkg[:containers] / ncpus_f).round(2)
    pkg[:usage_score_per_cpu] = (pkg[:usage_score] / ncpus_f).round(2)
  end

  format_output(packages, **fmt_opts)
end

#statusObject



17
18
19
20
# File 'lib/osctl/cli/cpu_scheduler.rb', line 17

def status
  require_args!
  osctld_fmt(:cpu_scheduler_status)
end

#upkeepObject



32
33
34
35
# File 'lib/osctl/cli/cpu_scheduler.rb', line 32

def upkeep
  require_args!
  osctld_fmt(:cpu_scheduler_upkeep)
end