Class: OsCtld::UserControl::Commands::CtAutodev

Inherits:
Base show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/user_control/commands/ct_autodev.rb

Instance Attribute Summary

Attributes inherited from Base

#user

Attributes inherited from Commands::Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Base

handle, #initialize, #owns_ct?, run

Methods inherited from Commands::Base

#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::UserControl::Commands::Base

Instance Method Details

#device_access_mode(dev_name) ⇒ Object (protected)

Return device access mode for the device on the host, if it exists



30
31
32
33
34
35
# File 'lib/osctld/user_control/commands/ct_autodev.rb', line 30

def device_access_mode(dev_name)
  st = File.stat(File.join('/', dev_name))
  st.mode & 0o7777
rescue Errno::ENOENT
  0o644
end

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/osctld/user_control/commands/ct_autodev.rb', line 11

def execute
  ct = DB::Containers.find(opts[:id], opts[:pool])
  return error('container not found') unless ct
  return error('access denied') unless owns_ct?(ct)

  # Filter out devices that have to be created
  devices = ct.devices.select { |dev| dev.can_create? && dev.name }.map do |dev|
    dev.export.merge(
      type_s: dev.type_s,
      permission: device_access_mode(dev.name)
    )
  end

  ok(devices:)
end