mirror of
https://github.com/Corsinvest/cv4pve-pepper.git
synced 2025-02-12 10:01:53 +00:00
Merge pull request #21 from victorioustr/master
add start/resume for stopped/paused vm options and delay options feature
This commit is contained in:
commit
6d5782b7b8
3 changed files with 50 additions and 21 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -351,4 +351,5 @@ MigrationBackup/
|
|||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
TestParm.parm
|
||||
TestParm.parm
|
||||
.idea/.idea.Corsinvest.ProxmoxVE.Pepper/.idea/
|
||||
|
|
27
README.md
27
README.md
|
@ -21,18 +21,20 @@ Usage:
|
|||
cv4pve-pepper [command] [options]
|
||||
|
||||
Options:
|
||||
--host <host> (REQUIRED) The host name host[:port],host1[:port],host2[:port]
|
||||
--api-token <api-token> Api token format 'USER@REALM!TOKENID=UUID'. Require Proxmox VE 6.2 or later
|
||||
--username <username> User name <username>@<realm>
|
||||
--password <password> The password. Specify 'file:path_file' to store password in file.
|
||||
--vmid <vmid> The id or name VM/CT
|
||||
--proxy <proxy> SPICE proxy server. This can be used by the client to specify the proxy server. All nodes in a cluster runs
|
||||
'spiceproxy', so it is up to the client to choose one. By default, we return the node to connect. If specify
|
||||
http(s)://[host]:[port] then replace proxy option in file .vv. E.g. for reverse proxy.
|
||||
--viewer <viewer> (REQUIRED) Executable SPICE client remote viewer.
|
||||
--viewer-options <viewer-options> Send options directly SPICE Viewer (quote value).
|
||||
--version Show version information
|
||||
-?, -h, --help Show help and usage information
|
||||
--host <host> (REQUIRED) The host name host[:port],host1[:port],host2[:port]
|
||||
--api-token <api-token> Api token format 'USER@REALM!TOKENID=UUID'. Require Proxmox VE 6.2 or later
|
||||
--username <username> User name <username>@<realm>
|
||||
--password <password> The password. Specify 'file:path_file' to store password in file.
|
||||
--vmid <vmid> The id or name VM/CT
|
||||
--proxy <proxy> SPICE proxy server. This can be used by the client to specify the proxy server. All nodes in a cluster runs
|
||||
'spiceproxy', so it is up to the client to choose one. By default, we return the node to connect. If specify
|
||||
http(s)://[host]:[port] then replace proxy option in file .vv. E.g. for reverse proxy.
|
||||
--viewer <viewer> (REQUIRED) Executable SPICE client remote viewer.
|
||||
--viewer-options <viewer-options> Send options directly SPICE Viewer (quote value).
|
||||
--start-or-resume Run stopped or paused VM
|
||||
--wait-for-startup <wait-for-startup> Wait sec. for startup VM [default: 5]
|
||||
--version Show version information
|
||||
-?, -h, --help Show help and usage information
|
||||
|
||||
Commands:
|
||||
app-check-update Check update application
|
||||
|
@ -69,6 +71,7 @@ this software aims to simplify run SPICE client from Proxmox VE using command li
|
|||
* Execute out side Proxmox VE
|
||||
* Not require Web login
|
||||
* Support multiple host for HA in --host parameter es. host[:port],host1[:port],host2[:port]
|
||||
* Start or Resume VM on connection
|
||||
* Check-Update and Upgrade application
|
||||
* Use Api token --api-token parameter
|
||||
* Send options directly to viewer
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
@ -13,6 +13,7 @@ using System.Text.RegularExpressions;
|
|||
using System.Threading.Tasks;
|
||||
using Corsinvest.ProxmoxVE.Api.Extension;
|
||||
using Corsinvest.ProxmoxVE.Api.Extension.Utils;
|
||||
using Corsinvest.ProxmoxVE.Api.Shared.Models.Vm;
|
||||
using Corsinvest.ProxmoxVE.Api.Shell.Helpers;
|
||||
|
||||
namespace Corsinvest.ProxmoxVE.Pepper
|
||||
|
@ -35,6 +36,11 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
|||
|
||||
var optViewerOptions = app.AddOption("--viewer-options", "Send options directly SPICE Viewer (quote value).");
|
||||
|
||||
var optStartOrResume = app.AddOption<bool>("--start-or-resume", "Run stopped or paused VM");
|
||||
|
||||
var optWaitForStartup = app.AddOption<int>("--wait-for-startup", "Wait sec. for startup VM");
|
||||
optWaitForStartup.SetDefaultValue(5);
|
||||
|
||||
app.SetHandler(async (InvocationContext ctx) =>
|
||||
{
|
||||
var loggerFactory = ConsoleHelper.CreateLoggerFactory<Program>(app.GetLogLevelFromDebug());
|
||||
|
@ -44,7 +50,26 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
|||
if (string.IsNullOrWhiteSpace(proxy)) { proxy = client.Host; }
|
||||
|
||||
var vm = await client.GetVm(optVmId.GetValue());
|
||||
var (success, reasonPhrase, content) = await VmHelper.GetQemuSpiceFileVV(client, vm.Node,vm.VmId, proxy);
|
||||
|
||||
if (optStartOrResume.GetValue() && (vm.IsStopped || vm.IsPaused))
|
||||
{
|
||||
var status = vm.IsStopped ? VmStatus.Start : VmStatus.Resume;
|
||||
|
||||
if (app.DebugIsActive())
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"VM is {(vm.IsStopped ? "stopped" : "paused")}. {status} now!");
|
||||
}
|
||||
|
||||
//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) = await VmHelper.GetQemuSpiceFileVV(client, vm.Node, vm.VmId, proxy);
|
||||
if (success)
|
||||
{
|
||||
//proxy force
|
||||
|
@ -63,8 +88,8 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
|||
|
||||
if (app.DebugIsActive())
|
||||
{
|
||||
Console.Out.WriteLine($"Replace Proxy: {proxy}");
|
||||
Console.Out.WriteLine(content);
|
||||
await Console.Out.WriteLineAsync($"Replace Proxy: {proxy}");
|
||||
await Console.Out.WriteLineAsync(content);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,8 +122,8 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
|||
|
||||
if (app.DebugIsActive())
|
||||
{
|
||||
Console.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}");
|
||||
Console.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}");
|
||||
await Console.Out.WriteLineAsync($"Run FileName: {process.StartInfo.FileName}");
|
||||
await Console.Out.WriteLineAsync($"Run Arguments: {process.StartInfo.Arguments}");
|
||||
}
|
||||
|
||||
if (!app.DryRunIsActive())
|
||||
|
@ -111,7 +136,7 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.Out.WriteLine($"Error: {reasonPhrase}");
|
||||
await Console.Out.WriteLineAsync($"Error: {reasonPhrase}");
|
||||
ctx.ExitCode = 1;
|
||||
}
|
||||
});
|
||||
|
@ -119,4 +144,4 @@ namespace Corsinvest.ProxmoxVE.Pepper
|
|||
return await app.ExecuteApp(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue