Class: Pvectl::Repositories::Snapshot
- Defined in:
- lib/pvectl/repositories/snapshot.rb
Overview
Repository for VM/container snapshots.
Handles listing snapshots for both QEMU VMs and LXC containers. Filters out the “current” snapshot which represents the live state.
Instance Method Summary collapse
-
#create(vmid, node, resource_type, name:, description: nil, vmstate: false) ⇒ String
Creates a snapshot for a VM or container.
-
#delete(vmid, node, resource_type, snapname, force: false) ⇒ String
Deletes a snapshot.
-
#list(vmid, node, resource_type) ⇒ Array<Models::Snapshot>
Lists all snapshots for a VM or container.
-
#rollback(vmid, node, resource_type, snapname, start: false) ⇒ String
Rolls back to a snapshot.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Pvectl::Repositories::Base
Instance Method Details
#create(vmid, node, resource_type, name:, description: nil, vmstate: false) ⇒ String
Creates a snapshot for a VM or container.
Uses ‘POST /nodes/node/qemu|lxc/vmid/snapshot` with parameters:
-
snapname: Name of the snapshot
-
description: Optional description
-
vmstate: Include VM RAM state (QEMU only, ignored for LXC)
57 58 59 60 61 62 63 64 |
# File 'lib/pvectl/repositories/snapshot.rb', line 57 def create(vmid, node, resource_type, name:, description: nil, vmstate: false) endpoint = resource_endpoint(resource_type) params = { snapname: name } params[:description] = description if description params[:vmstate] = vmstate if vmstate && resource_type == :qemu connection.client["nodes/#{node}/#{endpoint}/#{vmid}/snapshot"].post(params) end |
#delete(vmid, node, resource_type, snapname, force: false) ⇒ String
Deletes a snapshot.
Uses ‘DELETE /nodes/node/qemu|lxc/vmid/snapshot/snapname`.
76 77 78 79 80 81 82 |
# File 'lib/pvectl/repositories/snapshot.rb', line 76 def delete(vmid, node, resource_type, snapname, force: false) endpoint = resource_endpoint(resource_type) params = {} params[:force] = true if force connection.client["nodes/#{node}/#{endpoint}/#{vmid}/snapshot/#{snapname}"].delete(params) end |
#list(vmid, node, resource_type) ⇒ Array<Models::Snapshot>
Lists all snapshots for a VM or container.
Uses ‘/nodes/node/qemu/vmid/snapshot` for VMs or `/nodes/node/lxc/vmid/snapshot` for containers. Filters out the “current” snapshot which represents live state.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pvectl/repositories/snapshot.rb', line 32 def list(vmid, node, resource_type) endpoint = resource_endpoint(resource_type) response = connection.client["nodes/#{node}/#{endpoint}/#{vmid}/snapshot"].get response .reject { |s| s[:name] == "current" } .map { |data| build_model(data, vmid, node, resource_type) } rescue StandardError [] end |
#rollback(vmid, node, resource_type, snapname, start: false) ⇒ String
Rolls back to a snapshot.
Uses ‘POST /nodes/node/qemu|lxc/vmid/snapshot/snapname/rollback`.
94 95 96 97 98 99 100 |
# File 'lib/pvectl/repositories/snapshot.rb', line 94 def rollback(vmid, node, resource_type, snapname, start: false) endpoint = resource_endpoint(resource_type) params = {} params[:start] = true if start connection.client["nodes/#{node}/#{endpoint}/#{vmid}/snapshot/#{snapname}/rollback"].post(params) end |