Class: Pvectl::Commands::Get::Handlers::Snapshots

Inherits:
Object
  • Object
show all
Includes:
ResourceHandler
Defined in:
lib/pvectl/commands/get/handlers/snapshots.rb,
sig/pvectl/commands/get/handlers/snapshots.rbs

Overview

Handler for listing and describing snapshots.

Uses --vmid flag (repeatable) for VM/CT filtering and --node for node filtering. Without --vmid, operates cluster-wide.

Examples:

List snapshots for specific VMs

handler.list(args: [], vmid: ["100", "101"])

List all snapshots cluster-wide

handler.list(args: [])

Instance Method Summary collapse

Methods included from ResourceHandler

#selector_class

Constructor Details

#initialize(service: nil) ⇒ Snapshots



21
22
23
# File 'lib/pvectl/commands/get/handlers/snapshots.rb', line 21

def initialize(service: nil)
  @service = service
end

Instance Method Details

#build_serviceObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/pvectl/commands/get/handlers/snapshots.rb', line 71

def build_service
  config_service = Pvectl::Config::Service.new
  config_service.load
  connection = Pvectl::Connection.new(config_service.current_config)

  snapshot_repo = Pvectl::Repositories::Snapshot.new(connection)
  resolver = Pvectl::Utils::ResourceResolver.new(connection)
  task_repo = Pvectl::Repositories::Task.new(connection)

  Pvectl::Services::Snapshot.new(
    snapshot_repo: snapshot_repo,
    resource_resolver: resolver,
    task_repo: task_repo
  )
end

#describe(name:, node: nil, args: [], vmid: nil, **_options) ⇒ Models::SnapshotDescription

Describes a snapshot by name.



43
44
45
46
# File 'lib/pvectl/commands/get/handlers/snapshots.rb', line 43

def describe(name:, node: nil, args: [], vmid: nil, **_options)
  parsed_vmids = parse_vmids(vmid)
  service.describe(parsed_vmids, name, node: node)
end

#list(node: nil, name: nil, args: [], storage: nil, vmid: nil, **_options) ⇒ Array<Models::Snapshot>

Lists snapshots, optionally filtered by VMIDs and/or node.



31
32
33
34
# File 'lib/pvectl/commands/get/handlers/snapshots.rb', line 31

def list(node: nil, name: nil, args: [], storage: nil, vmid: nil, **_options)
  parsed_vmids = parse_vmids(vmid)
  service.list(parsed_vmids, node: node)
end

#parse_vmids(vmid) ⇒ Array<Integer>

Parses --vmid flag values to integer array.



61
62
63
64
65
# File 'lib/pvectl/commands/get/handlers/snapshots.rb', line 61

def parse_vmids(vmid)
  return [] if vmid.nil?

  Array(vmid).map(&:to_i)
end

#presenterPresenters::Snapshot

Returns presenter for snapshots.



51
52
53
# File 'lib/pvectl/commands/get/handlers/snapshots.rb', line 51

def presenter
  Pvectl::Presenters::Snapshot.new
end

#serviceObject



67
68
69
# File 'lib/pvectl/commands/get/handlers/snapshots.rb', line 67

def service
  @service ||= build_service
end