Class: Lxc::Storage::OverlayMount

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

Overview

Overlay mount backed storage

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#child_process_command, #detect_home, #log, #mixlib_shellout_command, #run_command, #sudo

Constructor Details

#initialize(args = {}) ⇒ OverlayMount

Note:

:overlay_type defaults to overlayfs

Create new instance

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :base (String)

    base path to overlay

  • :overlay (String)

    path to overlay storage

  • :target (String)

    path to mount overlay

  • :overlay_type (String)

    type of overlay to implement



27
28
29
30
31
32
33
# File 'lib/elecksee/storage/overlay_mount.rb', line 27

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

Instance Attribute Details

#baseString (readonly)

Returns base path to overlay.

Returns:

  • (String)

    base path to overlay



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

def base
  @base
end

#overlayString (readonly)

Returns path to overlay storage.

Returns:

  • (String)

    path to overlay storage



13
14
15
# File 'lib/elecksee/storage/overlay_mount.rb', line 13

def overlay
  @overlay
end

#overlay_typeString (readonly)

Returns type of overlay to implement.

Returns:

  • (String)

    type of overlay to implement



17
18
19
# File 'lib/elecksee/storage/overlay_mount.rb', line 17

def overlay_type
  @overlay_type
end

#targetString (readonly)

Returns path to mount overlay.

Returns:

  • (String)

    path to mount overlay



15
16
17
# File 'lib/elecksee/storage/overlay_mount.rb', line 15

def target
  @target
end

Instance Method Details

#mountTrueClass, FalseClass

Mount the overlay

Returns:

  • (TrueClass, FalseClass)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elecksee/storage/overlay_mount.rb', line 38

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
  else
    false
  end
end

#mounted?TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


56
57
58
# File 'lib/elecksee/storage/overlay_mount.rb', line 56

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

#unmountTrueClass, FalseClass

Unmount the overlay

Returns:

  • (TrueClass, FalseClass)


63
64
65
66
67
68
69
70
# File 'lib/elecksee/storage/overlay_mount.rb', line 63

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