Class: OsCtld::Devices::V2::ContainerManager

Inherits:
Manager
  • Object
show all
Defined in:
lib/osctld/devices/v2/container_manager.rb

Instance Attribute Summary

Attributes inherited from Manager

#configurator, #devices, #owner

Instance Method Summary collapse

Methods inherited from Manager

#add, #add_new, #add_to_changeset, #apply, #check_availability!, #check_descendant_mode!, #check_descendants!, #check_unset_inherit!, #chmod, class_for, #detect, #do_add, #dump, #dup, #each, #export, #find, #get, #include?, #inherit, #inherit_promoted, #inherit_recursive, #inherited?, #init, #initialize, load, new_for, #promote, #provide, #remove, #replace, #select, #set_inherit, #sync, #uninherit_recursive, #unset_inherit, #update_inherited_mode, #used?, #used_by_descendants?

Constructor Details

This class inherits a constructor from OsCtld::Devices::Manager

Instance Method Details

#assets(add) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/osctld/devices/v2/container_manager.rb', line 5

def assets(add)
  add.cgroup_program(
    ct.abs_apply_cgroup_path('devices'),
    desc: 'Controls access to devices',
    program_name: configurator.prog_name,
    attach_type: 'cgroup_device',
    attach_flags: 'multi',
    optional: true
  )
end

#changeset_sort_keyObject



61
62
63
# File 'lib/osctld/devices/v2/container_manager.rb', line 61

def changeset_sort_key
  File.join(ct.group.name, ct.id)
end

#check_all_available!(group: nil) ⇒ Object

Check that all devices are provided by parents, or raise an exception

Parameters:

  • group (Group, nil) (defaults to: nil)

    which group to use as the container’s parent, defaults to the container’s group



19
20
21
22
23
# File 'lib/osctld/devices/v2/container_manager.rb', line 19

def check_all_available!(group: nil)
  sync do
    devices.each { |dev| check_availability!(dev, parent: group || ct.group) }
  end
end

#childrenObject



53
54
55
# File 'lib/osctld/devices/v2/container_manager.rb', line 53

def children
  []
end

#configurator_classObject



57
58
59
# File 'lib/osctld/devices/v2/container_manager.rb', line 57

def configurator_class
  Devices::V2::ContainerConfigurator
end

#ensure_allObject

Ensure that all required devices are provided by parent groups



26
27
28
29
30
# File 'lib/osctld/devices/v2/container_manager.rb', line 26

def ensure_all
  sync do
    devices.each { |dev| parent.devices.provide(dev) }
  end
end

#parentObject



49
50
51
# File 'lib/osctld/devices/v2/container_manager.rb', line 49

def parent
  ct.group
end

#remove_missingObject

Remove devices that aren’t provided by the parent, or have insufficient access mode



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/osctld/devices/v2/container_manager.rb', line 34

def remove_missing
  sync do
    changed = false

    devices.delete_if do |dev|
      pdev = parent.devices.get(dev)
      delete = pdev.nil? || !pdev.mode.compatible?(dev.mode)
      changed = true if delete
      delete
    end

    add_to_changeset if changed
  end
end