Class: ZFS::Filesystem

Inherits:
ZFS
  • Object
show all
Defined in:
lib/zfs.rb

Instance Attribute Summary

Attributes inherited from ZFS

#name, #path, #pool

Instance Method Summary collapse

Methods inherited from ZFS

#==, #[], #[]=, #children, #create, #destroy!, #exist?, #initialize, mounts, #parent, pools, property, #to_s

Constructor Details

This class inherits a constructor from ZFS

Instance Method Details

#+(path) ⇒ Object

Return sub-filesystem.



436
437
438
439
440
441
442
443
# File 'lib/zfs.rb', line 436

def +(path)
	if path.match(/^@/)
		ZFS("#{name.to_s}#{path}")
	else
		path = Pathname(name) + path
		ZFS(path.cleanpath.to_s)
	end
end

#promote!Object

Promote this filesystem.

Raises:



501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/zfs.rb', line 501

def promote!
	raise NotFound, "filesystem is not a clone" if self.origin.nil?

	cmd = [ZFS.zfs_path].flatten + ['promote', name]

	out, status = Open3.capture2e(*cmd)

	if status.success? and out.empty?
		return self
	else
		raise Exception, "something went wrong"
	end
end

#rename!(newname, opts = {}) ⇒ Object

Rename filesystem.

Raises:



446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/zfs.rb', line 446

def rename!(newname, opts={})
	raise AlreadyExists if ZFS(newname).exist?

	cmd = [ZFS.zfs_path].flatten + ['rename']
	cmd << '-p' if opts[:parents]
	cmd << name
	cmd << newname

	out, status = Open3.capture2e(*cmd)

	if status.success? and out.empty?
		initialize(newname)
		return self
	else
		raise Exception, "something went wrong"
	end
end

#snapshot(snapname, opts = {}) ⇒ Object

Create a snapshot.

Raises:



465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/zfs.rb', line 465

def snapshot(snapname, opts={})
	raise NotFound, "no such filesystem" if !exist?
	raise AlreadyExists, "#{snapname} exists" if ZFS("#{name}@#{snapname}").exist?

	cmd = [ZFS.zfs_path].flatten + ['snapshot']
	cmd << '-r' if opts[:children]
	cmd << "#{name}@#{snapname}"

	out, status = Open3.capture2e(*cmd)

	if status.success? and out.empty?
		return ZFS("#{name}@#{snapname}")
	else
		raise Exception, "something went wrong"
	end
end

#snapshotsObject

Get an Array of all snapshots on this filesystem.

Raises:



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/zfs.rb', line 483

def snapshots
	raise NotFound, "no such filesystem" if !exist?

	stdout, stderr = [], []
	cmd = [ZFS.zfs_path].flatten + %w(list -H -d1 -r -oname -tsnapshot) + [name]

	stdout, stderr, status = Open3.capture3(*cmd)

	if status.success? and stderr.empty?
		stdout.lines.collect do |snap|
			ZFS(snap.chomp)
		end
	else
		raise Exception, "something went wrong"
	end
end