Class: OsCtld::DB::Groups
- Inherits:
-
PooledList
- Object
- List
- PooledList
- OsCtld::DB::Groups
- Defined in:
- lib/osctld/db/groups.rb
Instance Attribute Summary
Attributes inherited from List
Instance Method Summary collapse
- #add(grp) ⇒ Object
- #by_path(pool, name) ⇒ Object
- #default(pool) ⇒ Object
-
#initialize(*_) ⇒ Groups
constructor
A new instance of Groups.
- #load_or_create(pool, name, path = nil) ⇒ Object protected
- #remove(grp) ⇒ Object
- #root(pool) ⇒ Object
-
#setup(pool) ⇒ Object
Ensures presence of root and default groups.
Methods inherited from PooledList
#contains?, #each_by_ids, #find, #select_by_ids
Methods inherited from List
#contains?, #count, #each, #find, #get, instance, #sync
Constructor Details
#initialize(*_) ⇒ Groups
Returns a new instance of Groups.
13 14 15 16 |
# File 'lib/osctld/db/groups.rb', line 13 def initialize(*_) super @index = {} end |
Instance Method Details
#add(grp) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/osctld/db/groups.rb', line 111 def add(grp) sync do super @index[grp.pool.name] ||= {} @index[grp.pool.name][grp.name] = grp end end |
#by_path(pool, name) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/osctld/db/groups.rb', line 128 def by_path(pool, name) sync do next nil unless @index.has_key?(pool.name) @index[pool.name][name] end end |
#default(pool) ⇒ Object
107 108 109 |
# File 'lib/osctld/db/groups.rb', line 107 def default(pool) find('/default', pool) end |
#load_or_create(pool, name, path = nil) ⇒ Object (protected)
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/osctld/db/groups.rb', line 138 def load_or_create(pool, name, path = nil) grp = nil root = name == '/' created = false begin grp = Group.new(pool, name, root:, devices: false) rescue Errno::ENOENT grp = Group.new(pool, name, load: false, root:) grp.configure(path:, devices: false) created = true end add(grp) [grp, created] end |
#remove(grp) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/osctld/db/groups.rb', line 119 def remove(grp) sync do super @index[grp.pool.name].delete(grp.name) @index.delete(grp.pool.name) if @index[grp.pool.name].empty? grp end end |
#root(pool) ⇒ Object
103 104 105 |
# File 'lib/osctld/db/groups.rb', line 103 def root(pool) find('/', pool) end |
#setup(pool) ⇒ Object
Ensures presence of root and default groups
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 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/osctld/db/groups.rb', line 19 def setup(pool) root, created = load_or_create( pool, '/', File.join(CGroup::ROOT_GROUP, "pool.#{pool.name}") ) if created Devices::Lock.sync(pool) do # cgroupv1 devices are configured on the fly, so the cgroup has to be # initialized first root.devices.init if CGroup.v1? root.devices.add_new( :char, 1, 3, 'rwm', name: '/dev/null', inherit: true ) root.devices.add_new( :char, 1, 5, 'rwm', name: '/dev/zero', inherit: true ) root.devices.add_new( :char, 1, 7, 'rwm', name: '/dev/full', inherit: true ) root.devices.add_new( :char, 1, 8, 'rwm', name: '/dev/random', inherit: true ) root.devices.add_new( :char, 1, 9, 'rwm', name: '/dev/urandom', inherit: true ) root.devices.add_new( :char, 1, 11, 'rwm', name: '/dev/kmsg', inherit: true ) root.devices.add_new( :char, 5, 0, 'rwm', name: '/dev/tty', inherit: true ) root.devices.add_new( :char, 5, 1, 'rwm', # name: '/dev/console', # setup by lxc inherit: true ) root.devices.add_new( :char, 5, 2, 'rwm', # name: '/dev/ptmx', # setup by lxc inherit: true ) root.devices.add_new( :char, 136, '*', 'rwm', # name: '/dev/tty*', # setup by lxc inherit: true ) root.devices.add_new( :block, '*', '*', 'm', inherit: true ) root.devices.add_new( :char, '*', '*', 'm', inherit: true ) root.devices.init if CGroup.v2? end root.save_config else root.devices.init end default, = load_or_create(pool, '/default') default.devices.init end |