Class: Pvectl::Services::UnlinkDisk

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/services/unlink_disk.rb

Overview

Orchestrates disk unlinking from a VM configuration.

Delegates to the VM repository to issue the unlink PUT request and wraps the outcome in a Models::VmOperationResult. The underlying Proxmox endpoint is synchronous and returns no UPID, so the result captures success/failure synchronously.

Examples:

Soft unlink (keeps volume as unused)

service = UnlinkDisk.new(repository: vm_repo)
result = service.execute(vmid: 100, node: "pve1", disk_ids: "scsi1")

Hard delete via force

service = UnlinkDisk.new(repository: vm_repo)
result = service.execute(vmid: 100, node: "pve1", disk_ids: %w[scsi1 scsi2], force: true)

Instance Method Summary collapse

Constructor Details

#initialize(repository:) ⇒ UnlinkDisk

Creates a new UnlinkDisk service.

Parameters:



24
25
26
# File 'lib/pvectl/services/unlink_disk.rb', line 24

def initialize(repository:)
  @repository = repository
end

Instance Method Details

#execute(vmid:, node:, disk_ids:, force: false) ⇒ Models::VmOperationResult

Unlinks one or more disks from the VM configuration.

Parameters:

  • vmid (Integer)

    VM identifier

  • node (String)

    node name

  • disk_ids (Array<String>, String)

    disk identifiers

  • force (Boolean) (defaults to: false)

    physically remove the underlying volume(s)

Returns:



35
36
37
38
39
40
# File 'lib/pvectl/services/unlink_disk.rb', line 35

def execute(vmid:, node:, disk_ids:, force: false)
  @repository.unlink_disks(node, vmid, disk_ids, force: force)
  build_result(vmid, node, disk_ids, force, success: true)
rescue StandardError => e
  build_result(vmid, node, disk_ids, force, success: false, error: e.message)
end