Class: Pvectl::Models::Snapshot

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/models/snapshot.rb

Overview

Represents a VM/container snapshot in Proxmox.

A snapshot captures the state of a VM or container at a specific point in time, including optionally the VM memory state (vmstate).

Examples:

Creating a snapshot model

snapshot = Snapshot.new(
  name: "before-upgrade",
  snaptime: 1706800000,
  description: "Snapshot before upgrade",
  vmstate: 1
)
snapshot.has_vmstate?  # => true
snapshot.created_at    # => 2024-02-01 12:26:40 +0000

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Snapshot

Creates a new Snapshot instance.

Parameters:

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

    snapshot attributes

Options Hash (attrs):

  • :name (String)

    snapshot name

  • :snaptime (Integer)

    Unix timestamp of creation

  • :description (String)

    snapshot description

  • :vmstate (Integer)

    1 if VM state saved, 0 otherwise

  • :parent (String)

    parent snapshot name

  • :vmid (Integer)

    VM/container ID

  • :node (String)

    node name

  • :resource_type (Symbol)

    :qemu or :lxc



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pvectl/models/snapshot.rb', line 58

def initialize(attrs = {})
  super
  @name = attributes[:name]
  @snaptime = attributes[:snaptime]
  @description = attributes[:description]
  @vmstate = attributes[:vmstate]
  @parent = attributes[:parent]
  @vmid = attributes[:vmid]
  @node = attributes[:node]
  @resource_type = attributes[:resource_type]
end

Instance Attribute Details

#descriptionString? (readonly)

Returns optional description of the snapshot.

Returns:

  • (String, nil)

    optional description of the snapshot



30
31
32
# File 'lib/pvectl/models/snapshot.rb', line 30

def description
  @description
end

#nameString (readonly)

Returns snapshot name/identifier.

Returns:

  • (String)

    snapshot name/identifier



24
25
26
# File 'lib/pvectl/models/snapshot.rb', line 24

def name
  @name
end

#nodeString? (readonly)

Returns node name where the VM/container resides.

Returns:

  • (String, nil)

    node name where the VM/container resides



42
43
44
# File 'lib/pvectl/models/snapshot.rb', line 42

def node
  @node
end

#parentString? (readonly)

Returns parent snapshot name for snapshot trees.

Returns:

  • (String, nil)

    parent snapshot name for snapshot trees



36
37
38
# File 'lib/pvectl/models/snapshot.rb', line 36

def parent
  @parent
end

#resource_typeSymbol? (readonly)

Returns resource type (:qemu for VM, :lxc for container).

Returns:

  • (Symbol, nil)

    resource type (:qemu for VM, :lxc for container)



45
46
47
# File 'lib/pvectl/models/snapshot.rb', line 45

def resource_type
  @resource_type
end

#snaptimeInteger? (readonly)

Returns Unix timestamp when snapshot was created.

Returns:

  • (Integer, nil)

    Unix timestamp when snapshot was created



27
28
29
# File 'lib/pvectl/models/snapshot.rb', line 27

def snaptime
  @snaptime
end

#vmidInteger? (readonly)

Returns VM/container ID this snapshot belongs to.

Returns:

  • (Integer, nil)

    VM/container ID this snapshot belongs to



39
40
41
# File 'lib/pvectl/models/snapshot.rb', line 39

def vmid
  @vmid
end

#vmstateInteger? (readonly)

Returns 1 if VM memory state was saved, 0 or nil otherwise.

Returns:

  • (Integer, nil)

    1 if VM memory state was saved, 0 or nil otherwise



33
34
35
# File 'lib/pvectl/models/snapshot.rb', line 33

def vmstate
  @vmstate
end

Instance Method Details

#container?Boolean

Checks if the snapshot belongs to a container (LXC).

Returns:

  • (Boolean)

    true if resource_type is :lxc



96
97
98
# File 'lib/pvectl/models/snapshot.rb', line 96

def container?
  resource_type == :lxc
end

#created_atTime?

Returns the snapshot creation time as a Time object.

Returns:

  • (Time, nil)

    creation time or nil if snaptime is not set



80
81
82
83
84
# File 'lib/pvectl/models/snapshot.rb', line 80

def created_at
  return nil if snaptime.nil?

  Time.at(snaptime)
end

#has_vmstate?Boolean

Checks if the snapshot includes VM memory state.

Returns:

  • (Boolean)

    true if vmstate equals 1



73
74
75
# File 'lib/pvectl/models/snapshot.rb', line 73

def has_vmstate?
  vmstate == 1
end

#vm?Boolean

Checks if the snapshot belongs to a VM (QEMU).

Returns:

  • (Boolean)

    true if resource_type is :qemu



89
90
91
# File 'lib/pvectl/models/snapshot.rb', line 89

def vm?
  resource_type == :qemu
end