2018-04-25 16:49:07 +02:00
|
|
|
require 'to_lvm_xfs/exts'
|
|
|
|
|
|
|
|
class Image
|
|
|
|
attr_reader :base, :dir, :image, :root
|
|
|
|
def initialize base, dir, image: nil, root: nil
|
|
|
|
@base = base
|
|
|
|
@dir =
|
|
|
|
case dir
|
|
|
|
when Pathname then dir
|
2019-10-26 12:28:17 +02:00
|
|
|
when String then XPathname.new dir
|
2018-04-25 16:49:07 +02:00
|
|
|
else raise ArgumentError, "Pathname for dir expected"
|
|
|
|
end
|
|
|
|
@image =
|
|
|
|
case image
|
|
|
|
when Pathname then image
|
2019-10-26 12:28:17 +02:00
|
|
|
when String then XPathname.new image
|
2018-04-25 16:49:07 +02:00
|
|
|
when nil then @dir+'image'
|
|
|
|
else raise ArgumentError, "Pathname for image expected"
|
|
|
|
end
|
|
|
|
@image = @image.readlink.expand_path @image.expand_path.dirname while @image.symlink?
|
|
|
|
@root =
|
|
|
|
case root
|
|
|
|
when Pathname then root
|
2019-10-26 12:28:17 +02:00
|
|
|
when String then XPathname.new root
|
2018-04-25 16:49:07 +02:00
|
|
|
when nil then @dir+'root'
|
|
|
|
else raise ArgumentError, "Path for root must be Pathname, String or MP, if given"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def to_s() @dir.to_s end
|
|
|
|
|
|
|
|
def kpartx() @base.kpartx @image end
|
|
|
|
def departx() @base.departx @image end
|
|
|
|
def lpartx() @base.lpartx @image end
|
|
|
|
def kpartxed?() @base.kpartxed? @image end
|
|
|
|
end
|
|
|
|
|
|
|
|
class MP
|
|
|
|
attr_reader :base, :dev, :mp, :opts
|
|
|
|
def initialize base, dev, mp, *opts
|
|
|
|
@base, @dev, @mp, opts = base, dev, mp, opts
|
|
|
|
end
|
|
|
|
|
|
|
|
def mount() @base.mount dev, mp, *opts end
|
|
|
|
def umount() @base.umount mp end
|
|
|
|
def uuid() @uuid ||= @base.sh.fs_uuid @dev end
|
|
|
|
def fstype() @fstype ||= @base.sh.fs_type @dev end
|
|
|
|
def clear_cache() @uuid = @fstype = nil end
|
|
|
|
end
|
|
|
|
|