Module: Kanrisuru::Core::Disk

Extended by:
OsPackage::Define
Defined in:
lib/kanrisuru/core/disk.rb,
lib/kanrisuru/core/disk/types.rb,
lib/kanrisuru/core/disk/constants.rb,
lib/kanrisuru/core/disk/parsers/df.rb,
lib/kanrisuru/core/disk/parsers/du.rb,
lib/kanrisuru/core/disk/commands/df.rb,
lib/kanrisuru/core/disk/commands/du.rb,
lib/kanrisuru/core/disk/parsers/blkid.rb,
lib/kanrisuru/core/disk/parsers/lsblk.rb,
lib/kanrisuru/core/disk/commands/blkid.rb,
lib/kanrisuru/core/disk/commands/lsblk.rb,
lib/kanrisuru/core/disk/parsers/lsblk_version.rb

Defined Under Namespace

Modules: Parser Classes: BlkidDevice, DiskFree, DiskUsage, LsblkDevice

Constant Summary collapse

LSBK_VERSION =
2.27

Instance Method Summary collapse

Methods included from OsPackage::Define

extended, os_define

Instance Method Details

#blkid(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kanrisuru/core/disk/commands/blkid.rb', line 6

def blkid(opts = {})
  label = opts[:label]
  uuid  = opts[:uuid]
  device = opts[:device]

  mode = ''
  command = Kanrisuru::Command.new('blkid')

  if Kanrisuru::Util.present?(label) || Kanrisuru::Util.present?(uuid)
    mode = 'search'
    command.append_arg('-L', opts[:label])
    command.append_arg('-U', opts[:uuid])
  elsif Kanrisuru::Util.present?(device)
    mode = 'device'
    command.append_arg('-pio', 'export')
    command << device
  else
    mode = 'list'
    command.append_arg('-o', 'export')
  end

  execute_shell(command)

  Kanrisuru::Result.new(command) do |cmd|
    Parser::Blkid.parse(cmd, mode)
  end
end

#df(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kanrisuru/core/disk/commands/df.rb', line 6

def df(opts = {})
  path   = opts[:path]
  inodes = opts[:inodes]

  command = Kanrisuru::Command.new('df')

  command.append_flag('-PT')
  command.append_flag('-i', inodes)

  command << path if Kanrisuru::Util.present?(path)
  command | "awk '{print $1, $2, $3, $5, $6, $7}'"

  execute(command)

  Kanrisuru::Result.new(command) do |cmd|
    Parser::Df.parse(cmd)
  end
end

#du(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kanrisuru/core/disk/commands/du.rb', line 6

def du(opts = {})
  path      = opts[:path]
  summarize = opts[:summarize]
  convert   = opts[:convert]

  command = Kanrisuru::Command.new('du')
  command.append_flag('-s', summarize)
  command << path if Kanrisuru::Util.present?(path)
  command | "awk '{print \\$1, \\$2}'"

  execute_shell(command)

  Kanrisuru::Result.new(command) do |cmd|
    Parser::Du.parse(cmd, convert)
  end
end

#lsblk(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kanrisuru/core/disk/commands/lsblk.rb', line 6

def lsblk(opts = {})
  all    = opts[:all]
  nodeps = opts[:nodeps]
  paths  = opts[:paths]

  command = Kanrisuru::Command.new('lsblk')

  version = lsblk_version.to_f

  ## lsblk after version 2.26 handles json parsing.
  ## TODO: parse nested children for earlier version of lsblk
  if version >= LSBK_VERSION
    command.append_flag('--json') if version >= LSBK_VERSION
  else
    command.append_flag('-i')
    command.append_flag('-P')
    command.append_flag('--noheadings')
  end

  command.append_flag('-a', all)
  command.append_flag('-p', paths)
  command.append_flag('-d', nodeps)

  command.append_arg('-o', 'NAME,FSTYPE,MAJ:MIN,MOUNTPOINT,SIZE,UUID,RO,RM,OWNER,GROUP,MODE,TYPE')
  execute(command)

  Kanrisuru::Result.new(command) do |cmd|
    Parser::Lsblk.parse(cmd, version)
  end
end