Class: Vagrant::Smartos::Zones::Models::Snapshot
- Inherits:
-
Object
- Object
- Vagrant::Smartos::Zones::Models::Snapshot
show all
- Includes:
- Util::GlobalZone::Helper
- Defined in:
- lib/vagrant/smartos/zones/models/snapshot.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included, #sudo, #with_gz
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
11
12
13
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 11
def created_at
@created_at
end
|
#machine ⇒ Object
Returns the value of attribute machine.
11
12
13
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 11
def machine
@machine
end
|
#name ⇒ Object
Returns the value of attribute name.
11
12
13
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 11
def name
@name
end
|
#space_used ⇒ Object
Returns the value of attribute space_used.
11
12
13
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 11
def space_used
@space_used
end
|
#zone ⇒ Object
Returns the value of attribute zone.
11
12
13
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 11
def zone
@zone
end
|
Class Method Details
.all(zone) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 25
def self.all(zone)
snapshots = []
cmd = "pfexec zfs list -t snapshot -H -r -o name,creation,used zones/#{zone.uuid}"
with_gz(zone.machine, cmd) do |output|
break if output.include?('no datasets available')
snapshots += output.split("\n").map { |l| from_line(l, zone) }
end
snapshots
end
|
.around(zone, &block) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 13
def self.around(zone, &block)
snapshot_name = "before_#{Time.now.to_i}"
snapshot = create(snapshot_name, zone)
if block.arity.eql?(1)
block.call snapshot
else
block.call
end
snapshot.rollback
snapshot.destroy
end
|
.create(name, zone) ⇒ Object
35
36
37
38
39
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 35
def self.create(name, zone)
cmd = "pfexec zfs snapshot zones/#{zone.uuid}@#{name}"
with_gz(zone.machine, cmd)
find(name, zone)
end
|
.find(name, zone) ⇒ Object
41
42
43
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 41
def self.find(name, zone)
all(zone).find { |snapshot| snapshot.name == name } || raise(SnapshotNotFound)
end
|
.from_line(l, zone) ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 45
def self.from_line(l, zone)
name, created_at, used = l.split("\t")
new.tap do |s|
s.machine = zone.machine
s.zone = zone
s.name = name.split('@').last
s.created_at = created_at
s.space_used = used
end
end
|
Instance Method Details
#destroy ⇒ Object
60
61
62
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 60
def destroy
with_gz("pfexec zfs destroy #{path}")
end
|
#path ⇒ Object
56
57
58
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 56
def path
"zones/#{zone.uuid}@#{name}"
end
|
#rollback ⇒ Object
64
65
66
|
# File 'lib/vagrant/smartos/zones/models/snapshot.rb', line 64
def rollback
with_gz("pfexec zfs rollback -r #{path}")
end
|