mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-09-05 11:45:28 +00:00
fix: plumb skiplock parameter for VMs, force for containers
VM removal: add skiplock=1 parameter when -Force is specified. PVE honors it for root@pam only; non-root callers receive 403 errors. Updated help text. Container removal: map -Force to force=1 (LXC-specific parameter for forcing removal of running containers). Containers do not support skiplock. Also: clarified class and parameter documentation to remove false claims about -Force suppressing confirmation (it does not). Fixes #136. Addresses correctness reviewer findings.
This commit is contained in:
committed by
GitHub
parent
c12bfe9183
commit
75f4bbfeed
@@ -330,15 +330,15 @@ namespace PSProxmoxVE.Core.Services
|
||||
string node,
|
||||
int vmid,
|
||||
bool purge = false,
|
||||
bool skipLock = false)
|
||||
bool force = false)
|
||||
{
|
||||
if (session == null) throw new ArgumentNullException(nameof(session));
|
||||
if (string.IsNullOrWhiteSpace(node)) throw new ArgumentNullException(nameof(node));
|
||||
|
||||
var queryParams = new List<string>();
|
||||
queryParams.Add(purge ? "purge=1" : "purge=0");
|
||||
if (skipLock)
|
||||
queryParams.Add("skiplock=1");
|
||||
if (force)
|
||||
queryParams.Add("force=1");
|
||||
var queryString = "?" + string.Join("&", queryParams);
|
||||
|
||||
IPveHttpClient client = _injectedClient ?? new PveHttpClient(session);
|
||||
|
||||
@@ -208,9 +208,9 @@ namespace PSProxmoxVE.Core.Services
|
||||
/// <param name="importFrom">
|
||||
/// The import source in PVE format. Examples:
|
||||
/// <list type="bullet">
|
||||
/// <item>"local:iso/image.img" — import from a file already on storage</item>
|
||||
/// <item>"local:import/myvm.ova/disk.vmdk" — import a disk from within an OVA</item>
|
||||
/// <item>"/var/lib/vz/images/disk.qcow2" — import from an absolute path on the node</item>
|
||||
/// <item>"local:iso/image.img" - import from a file already on storage</item>
|
||||
/// <item>"local:import/myvm.ova/disk.vmdk" - import a disk from within an OVA</item>
|
||||
/// <item>"/var/lib/vz/images/disk.qcow2" - import from an absolute path on the node</item>
|
||||
/// </list>
|
||||
/// </param>
|
||||
/// <param name="format">Optional target format (e.g. "qcow2", "raw"). Defaults to storage default.</param>
|
||||
@@ -334,7 +334,7 @@ namespace PSProxmoxVE.Core.Services
|
||||
/// its own post-stop cleanup, so nothing can interleave between the two halves. Composing
|
||||
/// a reboot client-side as shutdown + start instead races that cleanup: the start wins the
|
||||
/// lock, cleanup then holds it for 30 s waiting on the newly started process, and the next
|
||||
/// call fails with "can't lock file '/var/lock/qemu-server/lock-<vmid>.conf' - got timeout".
|
||||
/// call fails with "can't lock file '/var/lock/qemu-server/lock-<vmid>.conf' - got timeout".
|
||||
/// </remarks>
|
||||
/// <param name="session">The authenticated PVE session.</param>
|
||||
/// <param name="node">The cluster node name.</param>
|
||||
@@ -644,7 +644,7 @@ namespace PSProxmoxVE.Core.Services
|
||||
// PVE's agent/exec "command" is an array: element 0 is the executable and
|
||||
// each subsequent element is one argv entry. It is sent as repeated form
|
||||
// keys (command=<exe>&command=<arg1>&...). Do NOT use "input-data" for
|
||||
// arguments — that is the process's STDIN, not argv.
|
||||
// arguments - that is the process's STDIN, not argv.
|
||||
var data = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("command", command)
|
||||
@@ -757,7 +757,7 @@ namespace PSProxmoxVE.Core.Services
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Guest agent — extended operations
|
||||
// Guest agent - extended operations
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace PSProxmoxVE.Cmdlets.Containers
|
||||
/// <para type="synopsis">Removes an LXC container from a Proxmox VE node.</para>
|
||||
/// <para type="description">
|
||||
/// Deletes an LXC container and, optionally, all associated storage.
|
||||
/// This operation is destructive and requires confirmation unless -Force is specified.
|
||||
/// This operation is destructive and requires confirmation.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsCommon.Remove, "PveContainer",
|
||||
@@ -42,10 +42,10 @@ namespace PSProxmoxVE.Cmdlets.Containers
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">
|
||||
/// When specified, sends skiplock=1 to PVE, which bypasses locks. PVE honours this for root@pam only.
|
||||
/// When specified, sends force=1 to PVE, allowing removal of running containers.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, HelpMessage = "Bypass locks (root@pam only); sends skiplock=1 to PVE.")]
|
||||
[Parameter(Mandatory = false, HelpMessage = "Force destroy, even if running.")]
|
||||
public SwitchParameter Force { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace PSProxmoxVE.Cmdlets.Vms
|
||||
/// <para type="synopsis">Removes a QEMU/KVM virtual machine from a Proxmox VE node.</para>
|
||||
/// <para type="description">
|
||||
/// Deletes a virtual machine and, optionally, all associated disk images.
|
||||
/// This operation is destructive and requires confirmation unless -Force is specified.
|
||||
/// This operation is destructive and requires confirmation.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsCommon.Remove, "PveVm",
|
||||
@@ -42,10 +42,10 @@ namespace PSProxmoxVE.Cmdlets.Vms
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">
|
||||
/// When specified, sends skiplock=1 to PVE, which bypasses locks. PVE honours this for root@pam only.
|
||||
/// When specified, sends skiplock=1 to PVE to bypass locks. PVE honours this parameter for root@pam only; non-root callers will receive a 403 permission error.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, HelpMessage = "Bypass locks (root@pam only); sends skiplock=1 to PVE.")]
|
||||
[Parameter(Mandatory = false, HelpMessage = "Bypass locks via skiplock=1 (root@pam only).")]
|
||||
public SwitchParameter Force { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace PSProxmoxVE.Core.Tests.Services
|
||||
"powershell.exe", new[] { "-NoProfile", "-Command", "echo hi" });
|
||||
|
||||
Assert.NotNull(captured);
|
||||
// Args are argv, not STDIN — "input-data" must never be emitted.
|
||||
// Args are argv, not STDIN - "input-data" must never be emitted.
|
||||
Assert.DoesNotContain(captured!, kvp => kvp.Key == "input-data");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user