Class: OsCtld::Assets::CgroupDeviceList

Inherits:
Base
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/assets/cgroup_device_list.rb

Overview

Check cgroupv1 devices.list

Instance Attribute Summary

Attributes inherited from Base

#errors, #opts, #path

Instance Method Summary collapse

Methods inherited from Base

#add_error, #prefetch_zfs, register, #run_validation, #state, #type, #valid?, #validate?, #validate_block

Constructor Details

#initialize(cgroup_path, opts) ⇒ CgroupDeviceList

Returns a new instance of CgroupDeviceList.

Parameters:

  • opts (Hash)

    options

Options Hash (opts):



13
14
15
# File 'lib/osctld/assets/cgroup_device_list.rb', line 13

def initialize(cgroup_path, opts) # rubocop:disable all
  super
end

Instance Method Details

#validate(_run) ⇒ Object (protected)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/osctld/assets/cgroup_device_list.rb', line 19

def validate(_run)
  begin
    devices_list = File.read(File.join(path, 'devices.list'))
  rescue Errno::ENOENT
    add_error("devices.list not found in cgroup #{path.inspect}")
  end

  cgroup_devices = devices_list.strip.split("\n")
  allowed_devices = opts[:devices].map(&:to_s)

  allowed_devices.delete_if do |dev|
    if cgroup_devices.delete(dev)
      true
    else
      add_error("device #{dev.inspect} not allowed")
      false
    end
  end

  cgroup_devices.each do |dev|
    add_error("device #{dev.inspect} allowed, but not configured")
  end
end