Class: Pvectl::Commands::Get::Handlers::Snapshots
- Inherits:
-
Object
- Object
- Pvectl::Commands::Get::Handlers::Snapshots
- 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.
Instance Method Summary collapse
- #build_service ⇒ Object
-
#describe(name:, node: nil, args: [], vmid: nil, **_options) ⇒ Models::SnapshotDescription
Describes a snapshot by name.
-
#initialize(service: nil) ⇒ Snapshots
constructor
A new instance of Snapshots.
-
#list(node: nil, name: nil, args: [], storage: nil, vmid: nil, **_options) ⇒ Array<Models::Snapshot>
Lists snapshots, optionally filtered by VMIDs and/or node.
-
#parse_vmids(vmid) ⇒ Array<Integer>
Parses --vmid flag values to integer array.
-
#presenter ⇒ Presenters::Snapshot
Returns presenter for snapshots.
- #service ⇒ Object
Methods included from ResourceHandler
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_service ⇒ Object
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, **) 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, **) 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 |
#presenter ⇒ Presenters::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 |
#service ⇒ Object
67 68 69 |
# File 'lib/pvectl/commands/get/handlers/snapshots.rb', line 67 def service @service ||= build_service end |