File: priority_setting.rb

package info (click to toggle)
puppet-agent 8.10.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,404 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (44 lines) | stat: -rw-r--r-- 1,315 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require_relative '../../puppet/settings/base_setting'

# A setting that represents a scheduling priority, and evaluates to an
# OS-specific priority level.
class Puppet::Settings::PrioritySetting < Puppet::Settings::BaseSetting
  PRIORITY_MAP =
    if Puppet::Util::Platform.windows?
      require_relative '../../puppet/util/windows/process'
      require_relative '../../puppet/ffi/windows/constants'
      {
        :high => Puppet::FFI::Windows::Constants::HIGH_PRIORITY_CLASS,
        :normal => Puppet::FFI::Windows::Constants::NORMAL_PRIORITY_CLASS,
        :low => Puppet::FFI::Windows::Constants::BELOW_NORMAL_PRIORITY_CLASS,
        :idle => Puppet::FFI::Windows::Constants::IDLE_PRIORITY_CLASS
      }
    else
      {
        :high => -10,
        :normal => 0,
        :low => 10,
        :idle => 19
      }
    end

  def type
    :priority
  end

  def munge(value)
    return unless value

    if value.is_a?(Integer)
      value
    elsif value.is_a?(String) and value =~ /\d+/
      value.to_i
    elsif value.is_a?(String) and PRIORITY_MAP[value.to_sym]
      PRIORITY_MAP[value.to_sym]
    else
      raise Puppet::Settings::ValidationError, _("Invalid priority format '%{value}' for parameter: %{name}") % { value: value.inspect, name: @name }
    end
  end
end