Class: VagrantLXD::Capability

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-lxd/capability.rb

Class Method Summary collapse

Class Method Details

.debian_guest(machine) ⇒ Object

TODO Install the minimal set of packages to allow for Vagrant to connect to a Debian-based guest.



63
64
# File 'lib/vagrant-lxd/capability.rb', line 63

def Capability.debian_guest(machine)
end

.id_in_sub_id?(id, id_map) ⇒ Boolean

Determines whether the given numerical ‘id` is included in the subordinate map `id_map`, which should be an array of lines from the file /etc/subuid or /etc/subgid.

Invalid lines, and any lines for a user or group other than root, are ignored. See subuid(5) and subgid(5) for details about these files, and the expected format of their entries.

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
# File 'lib/vagrant-lxd/capability.rb', line 51

def Capability.id_in_sub_id?(id, id_map)
  id_map.any? do |line|
    if line.match(/^(root|0):(\d+):(\d+)/)
      range_min = $2.to_i
      range_max = range_min + $3.to_i
      id.between?(range_min, range_max)
    end
  end
end

.snapshot_list(machine) ⇒ Object



24
25
26
27
# File 'lib/vagrant-lxd/capability.rb', line 24

def Capability.snapshot_list(machine)
  env = machine.action(:snapshot_list)
  env[:machine_snapshot_list] || []
end

.synced_folders(env) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vagrant-lxd/capability.rb', line 29

def Capability.synced_folders(env)
  logger = Log4r::Logger.new('vagrant::lxd::capability')
  logger.debug "Checking synced folders support for effective UID/GID #{Process.uid}/#{Process.gid}..."
  %w(uid gid).all? do |type|
    begin
      id = Process.send(type)
      id_map = File.readlines("/etc/sub#{type}")
      id_in_sub_id?(id, id_map)
    rescue StandardError => e
      logger.warn "Cannot read subordinate permissions file: #{e.message}"
      false
    end
  end
end