Class: OsCtld::DB::Groups

Inherits:
PooledList show all
Defined in:
lib/osctld/db/groups.rb

Instance Attribute Summary

Attributes inherited from List

#objects

Instance Method Summary collapse

Methods inherited from PooledList

#contains?, #find

Methods inherited from List

#contains?, #count, #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



100
101
102
103
104
105
106
# File 'lib/osctld/db/groups.rb', line 100

def add(grp)
  sync do
    super
    @index[grp.pool.name] ||= {}
    @index[grp.pool.name][grp.name] = grp
  end
end

#by_path(pool, name) ⇒ Object



117
118
119
120
121
122
# File 'lib/osctld/db/groups.rb', line 117

def by_path(pool, name)
  sync do
    next nil unless @index.has_key?(pool.name)
    @index[pool.name][name]
  end
end

#default(pool) ⇒ Object



96
97
98
# File 'lib/osctld/db/groups.rb', line 96

def default(pool)
  find('/default', pool)
end

#load_or_create(pool, name, path = nil) ⇒ Object (protected)



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/osctld/db/groups.rb', line 125

def load_or_create(pool, name, path = nil)
  grp = nil
  root = name == '/'
  created = false

  begin
    grp = Group.new(pool, name, root: root, devices: false)

  rescue Errno::ENOENT
    grp = Group.new(pool, name, load: false, root: root)
    grp.configure(path: path, devices: false)
    created = true
  end

  add(grp)
  [grp, created]
end

#remove(grp) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/osctld/db/groups.rb', line 108

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



92
93
94
# File 'lib/osctld/db/groups.rb', line 92

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
# File 'lib/osctld/db/groups.rb', line 19

def setup(pool)
  root, created = load_or_create(
    pool,
    '/',
    File.join('osctl', "pool.#{pool.name}")
  )

  if created
    root.devices.init

    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, 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.apply
    root.save_config

  else
    root.devices.init
  end

  load_or_create(pool, '/default')
end