mirror of
https://github.com/Corsinvest/cv4pve-pepper.git
synced 2025-03-09 15:39:57 +00:00
@victorioustr add start/resume for stopped/paused vm options and delay options feature
This commit is contained in:
parent
b2797a3ebe
commit
6eaa9a20af
1 changed files with 18 additions and 35 deletions
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
|
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
|
||||||
* SPDX-License-Identifier: GPL-3.0-only
|
* SPDX-License-Identifier: GPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
@ -36,15 +36,10 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
||||||
|
|
||||||
var optViewerOptions = app.AddOption("--viewer-options", "Send options directly SPICE Viewer (quote value).");
|
var optViewerOptions = app.AddOption("--viewer-options", "Send options directly SPICE Viewer (quote value).");
|
||||||
|
|
||||||
var optStartOrResume = app.AddOption("--start-or-resume", "Run stopped or paused VM");
|
var optStartOrResume = app.AddOption<bool>("--start-or-resume", "Run stopped or paused VM");
|
||||||
optStartOrResume.IsRequired = false;
|
|
||||||
optStartOrResume.SetDefaultValue("false");
|
|
||||||
|
|
||||||
var optWaitForStartup = app.AddOption("--wait-for-startup", "Wait for startup VM");
|
var optWaitForStartup = app.AddOption<int>("--wait-for-startup", "Wait sec. for startup VM");
|
||||||
optWaitForStartup.IsRequired = false;
|
|
||||||
optWaitForStartup.SetDefaultValue(5);
|
optWaitForStartup.SetDefaultValue(5);
|
||||||
|
|
||||||
var startOrResume = optStartOrResume.GetValue() == "true";
|
|
||||||
|
|
||||||
app.SetHandler(async (InvocationContext ctx) =>
|
app.SetHandler(async (InvocationContext ctx) =>
|
||||||
{
|
{
|
||||||
|
@ -56,36 +51,25 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
||||||
|
|
||||||
var vm = await client.GetVm(optVmId.GetValue());
|
var vm = await client.GetVm(optVmId.GetValue());
|
||||||
|
|
||||||
if (startOrResume && (vm.IsStopped || vm.IsPaused))
|
if (optStartOrResume.GetValue() && (vm.IsStopped || vm.IsPaused))
|
||||||
{
|
{
|
||||||
if (app.DebugIsActive())
|
var status = vm.IsStopped ? VmStatus.Start : VmStatus.Resume;
|
||||||
{
|
|
||||||
await Console.Out.WriteLineAsync(
|
|
||||||
$"VM is {(vm.IsStopped ? "stopped" : "paused")}. {(vm.IsStopped ? "Running" : "Resuming")} now!");
|
|
||||||
}
|
|
||||||
|
|
||||||
await VmHelper.ChangeStatusVm(client, vm.Node, vm.VmType, vm.VmId,
|
|
||||||
vm.IsStopped ? VmStatus.Start : VmStatus.Resume);
|
|
||||||
|
|
||||||
for (var i = 1; i < int.Parse(optWaitForStartup.GetValue()); i++)
|
|
||||||
{
|
|
||||||
if (app.DebugIsActive())
|
|
||||||
{
|
|
||||||
await Console.Out.WriteAsync($"\r{10 - i}");
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (app.DebugIsActive())
|
if (app.DebugIsActive())
|
||||||
{
|
{
|
||||||
await Console.Out.WriteLineAsync();
|
await Console.Out.WriteLineAsync($"VM is {(vm.IsStopped ? "stopped" : "paused")}. {status} now!");
|
||||||
await Console.Out.WriteLineAsync("VM is running.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//start VM
|
||||||
|
var result = await VmHelper.ChangeStatusVm(client, vm.Node, vm.VmType, vm.VmId, status);
|
||||||
|
await client.WaitForTaskToFinish(result, timeout: optWaitForStartup.GetValue() * 1000);
|
||||||
|
|
||||||
|
//check VM is running
|
||||||
|
vm = await client.GetVm(optVmId.GetValue());
|
||||||
|
if (app.DebugIsActive()) { await Console.Out.WriteLineAsync($"VM is {vm.Status}."); }
|
||||||
}
|
}
|
||||||
|
|
||||||
var (success, reasonPhrase, content) =
|
var (success, reasonPhrase, content) = await VmHelper.GetQemuSpiceFileVV(client, vm.Node, vm.VmId, proxy);
|
||||||
await VmHelper.GetQemuSpiceFileVV(client, vm.Node, vm.VmId, proxy);
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
//proxy force
|
//proxy force
|
||||||
|
@ -100,13 +84,12 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content = string.Join("\n", lines);
|
content = string.Join("\n", lines);
|
||||||
|
|
||||||
if (app.DebugIsActive())
|
if (app.DebugIsActive())
|
||||||
{
|
{
|
||||||
Console.Out.WriteLine($"Replace Proxy: {proxy}");
|
await Console.Out.WriteLineAsync($"Replace Proxy: {proxy}");
|
||||||
Console.Out.WriteLine(content);
|
await Console.Out.WriteLineAsync(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,4 +144,4 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
||||||
return await app.ExecuteApp(args);
|
return await app.ExecuteApp(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue