Class: OsCtld::Devices::Device
- Inherits:
-
Object
- Object
- OsCtld::Devices::Device
- Defined in:
- lib/osctld/devices/device.rb
Instance Attribute Summary collapse
-
#inherit ⇒ Object
writeonly
Sets the attribute inherit.
-
#inherited ⇒ Object
writeonly
Sets the attribute inherited.
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.import(hash) ⇒ Object
Load from client.
-
.load(hash) ⇒ Object
Load from config.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#chmod(new_mode) ⇒ Hash<Symbol, String>
Change mode and return action for cgroup update.
-
#dump ⇒ Object
Dump to config.
-
#export ⇒ Object
Export to client.
- #inherit? ⇒ Boolean
- #inherited? ⇒ Boolean
-
#initialize(type, major, minor, mode, **opts) ⇒ Device
constructor
A new instance of Device.
- #promoted? ⇒ Boolean
- #to_s(opts = {}) ⇒ Object
- #type_s ⇒ Object
Constructor Details
#initialize(type, major, minor, mode, **opts) ⇒ Device
Returns a new instance of Device.
42 43 44 45 46 47 48 49 50 |
# File 'lib/osctld/devices/device.rb', line 42 def initialize(type, major, minor, mode, **opts) @type = type @major = major @minor = minor @mode = Devices::Mode.new(mode) @name = opts[:name] @inherit = opts.has_key?(:inherit) ? opts[:inherit] : true @inherited = opts.has_key?(:inherited) ? opts[:inherited] : false end |
Instance Attribute Details
#inherit=(value) ⇒ Object (writeonly)
Sets the attribute inherit
30 31 32 |
# File 'lib/osctld/devices/device.rb', line 30 def inherit=(value) @inherit = value end |
#inherited=(value) ⇒ Object (writeonly)
Sets the attribute inherited
30 31 32 |
# File 'lib/osctld/devices/device.rb', line 30 def inherited=(value) @inherited = value end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
29 30 31 |
# File 'lib/osctld/devices/device.rb', line 29 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
29 30 31 |
# File 'lib/osctld/devices/device.rb', line 29 def minor @minor end |
#mode ⇒ Object
Returns the value of attribute mode.
29 30 31 |
# File 'lib/osctld/devices/device.rb', line 29 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/osctld/devices/device.rb', line 29 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
29 30 31 |
# File 'lib/osctld/devices/device.rb', line 29 def type @type end |
Class Method Details
.import(hash) ⇒ Object
Load from client
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/osctld/devices/device.rb', line 18 def self.import(hash) new( hash[:type].to_sym, hash[:major].to_s, hash[:minor].to_s, hash[:mode], name: hash[:dev_name], inherit: hash[:inherit] ) end |
.load(hash) ⇒ Object
Load from config
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/osctld/devices/device.rb', line 4 def self.load(hash) major = hash['major'].to_s minor = hash['minor'].to_s new( hash['type'].to_sym, major == 'all' ? '*' : major, minor == 'all' ? '*' : minor, hash['mode'], name: hash['name'], inherit: hash['inherit'] ) end |
Instance Method Details
#==(other) ⇒ Object
123 124 125 |
# File 'lib/osctld/devices/device.rb', line 123 def ==(other) type == other.type && major == other.major && minor == other.minor end |
#chmod(new_mode) ⇒ Hash<Symbol, String>
Change mode and return action for cgroup update
The return value is a hash describing actions that need to be taken to update cgroups. The hash can have two keys: ‘:allow` and `:deny`, each pointing to a value that has to be written to `devices.allow` or `devices.deny`, depending on the action type.
For example, for transition from ‘rm` to `wm`, the return value would be:
{allow: 'c 1:5 w', deny: 'c 1:5 r'}
82 83 84 85 86 |
# File 'lib/osctld/devices/device.rb', line 82 def chmod(new_mode) diff = mode.diff(new_mode) self.mode = new_mode diff.reject { |_k, v| v.empty? }.transform_values { |v| to_s(mode: v) } end |
#dump ⇒ Object
Dump to config
89 90 91 |
# File 'lib/osctld/devices/device.rb', line 89 def dump export.transform_keys(&:to_s) end |
#export ⇒ Object
Export to client
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/osctld/devices/device.rb', line 94 def export { type: type.to_s, major:, minor:, mode: mode.to_s, name:, inherit: inherit?, inherited: inherited? } end |
#inherit? ⇒ Boolean
52 53 54 |
# File 'lib/osctld/devices/device.rb', line 52 def inherit? @inherit end |
#inherited? ⇒ Boolean
56 57 58 |
# File 'lib/osctld/devices/device.rb', line 56 def inherited? @inherited end |
#promoted? ⇒ Boolean
60 61 62 |
# File 'lib/osctld/devices/device.rb', line 60 def promoted? !@inherited end |
#to_s(opts = {}) ⇒ Object
119 120 121 |
# File 'lib/osctld/devices/device.rb', line 119 def to_s(opts = {}) "#{type_s} #{major}:#{minor} #{opts[:mode] || mode || 'rwm'}" end |
#type_s ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/osctld/devices/device.rb', line 106 def type_s case type when :char 'c' when :block 'b' else raise "invalid device type '#{type}'" end end |