Class: Lxc::OverlayMount

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/elecksee/storage/overlay_mount.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#command, #detect_home, #log, #run_command, #sudo

Constructor Details

#initialize(args = {}) ⇒ OverlayMount

Returns a new instance of OverlayMount.



13
14
15
16
17
18
19
# File 'lib/elecksee/storage/overlay_mount.rb', line 13

def initialize(args={})
  validate!(args)
  @base = args[:base]
  @overlay = args[:overlay]
  @target = args[:target]
  @overlay_type = args[:overlay_type] || 'overlayfs'
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



8
9
10
# File 'lib/elecksee/storage/overlay_mount.rb', line 8

def base
  @base
end

#overlayObject (readonly)

Returns the value of attribute overlay.



9
10
11
# File 'lib/elecksee/storage/overlay_mount.rb', line 9

def overlay
  @overlay
end

#overlay_typeObject (readonly)

Returns the value of attribute overlay_type.



11
12
13
# File 'lib/elecksee/storage/overlay_mount.rb', line 11

def overlay_type
  @overlay_type
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/elecksee/storage/overlay_mount.rb', line 10

def target
  @target
end

Instance Method Details

#mountObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elecksee/storage/overlay_mount.rb', line 21

def mount
  unless(mounted?)
    case overlay_type
    when 'aufs'
      cmd = "mount -t aufs -o br=#{overlay}=rw:#{base}=ro,noplink none #{target}"
    when 'overlayfs'
      cmd = "mount -t overlayfs -oupperdir=#{overlay},lowerdir=#{base} none #{target}"
    else
      raise "Invalid overlay type provided: #{overlay_type}"
    end
    command(cmd, :sudo => true)
    true
  end
end

#mounted?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/elecksee/storage/overlay_mount.rb', line 36

def mounted?
  command("mount").stdout.include?(target)
end

#unmountObject



40
41
42
43
44
45
# File 'lib/elecksee/storage/overlay_mount.rb', line 40

def unmount
  if(mounted?)
    command("umount #{target}", :sudo => true, :allow_failure => true)
    true
  end
end