mirror of
https://github.com/Corsinvest/cv4pve-pepper.git
synced 2025-02-12 10:01:53 +00:00
Proxmox VE 8.2
This commit is contained in:
parent
732d539ddc
commit
f3ebcd0e6a
5 changed files with 134 additions and 153 deletions
19
.vscode/launch.json
vendored
19
.vscode/launch.json
vendored
|
@ -1,29 +1,26 @@
|
|||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
// Usare IntelliSense per individuare gli attributi esistenti per il debug C#
|
||||
// Usa il passaggio del mouse per la descrizione degli attributi esistenti
|
||||
// Per ulteriori informazioni, visitare https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper/bin/Debug/net6.0/cv4pve-pepper.dll",
|
||||
"args": [
|
||||
"@TestParm.parm"
|
||||
],
|
||||
// Se i framework di destinazione sono stati modificati, assicurarsi di aggiornare il percorso del programma.
|
||||
"program": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper/bin/Debug/net8.0/cv4pve-pepper.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
// Per ulteriori informazioni sul campo 'console', vedere https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
13
.vscode/tasks.json
vendored
13
.vscode/tasks.json
vendored
|
@ -7,9 +7,9 @@
|
|||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper/Corsinvest.ProxmoxVE.Pepper.csproj",
|
||||
"${workspaceFolder}/Corsinvest.ProxmoxVE.Pepper.sln",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
|
@ -19,9 +19,9 @@
|
|||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper/Corsinvest.ProxmoxVE.Pepper.csproj",
|
||||
"${workspaceFolder}/Corsinvest.ProxmoxVE.Pepper.sln",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
|
@ -32,9 +32,8 @@
|
|||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper/Corsinvest.ProxmoxVE.Pepper.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
"--project",
|
||||
"${workspaceFolder}/Corsinvest.ProxmoxVE.Pepper.sln"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
|
|
24
README.md
24
README.md
|
@ -3,8 +3,6 @@
|
|||
[![License](https://img.shields.io/github/license/Corsinvest/cv4pve-pepper.svg)](LICENSE.md)
|
||||
|
||||
```text
|
||||
Description:
|
||||
|
||||
______ _ __
|
||||
/ ____/___ __________(_)___ _ _____ _____/ /_
|
||||
/ / / __ \/ ___/ ___/ / __ \ | / / _ \/ ___/ __/
|
||||
|
@ -12,33 +10,30 @@ Description:
|
|||
\____/\____/_/ /____/_/_/ /_/|___/\___/____/\__/
|
||||
|
||||
|
||||
Launching SPICE on Proxmox VE (Made in Italy)
|
||||
Launching SPICE remote-viewer for Proxmox VE (Made in Italy)
|
||||
|
||||
cv4pve-pepper is a part of suite cv4pve.
|
||||
For more information visit https://www.cv4pve-tools.com
|
||||
For more information visit https://www.corsinvest.it/cv4pve
|
||||
|
||||
Usage:
|
||||
cv4pve-pepper [command] [options]
|
||||
cv4pve-pepper [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.
|
||||
--validate-certificate Validate SSL Certificate Proxmox VE node.
|
||||
--host <host> (REQUIRED) The host name host[:port],host1[:port],host2[:port]
|
||||
--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.
|
||||
--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
|
||||
app-upgrade Upgrade application
|
||||
```
|
||||
|
||||
## Copyright and License
|
||||
|
@ -48,7 +43,7 @@ For licensing details please visit [LICENSE.md](LICENSE.md)
|
|||
|
||||
## Commercial Support
|
||||
|
||||
This software is part of a suite of tools called cv4pve-tools. If you want commercial support, visit the [site](https://www.cv4pve-tools.com)
|
||||
This software is part of a suite of tools called cv4pve-tools. If you want commercial support, visit the [site](https://www.corisnvest.it/cv4pve)
|
||||
|
||||
## Introduction
|
||||
|
||||
|
@ -76,6 +71,7 @@ this software aims to simplify run SPICE client from Proxmox VE using command li
|
|||
* Use Api token --api-token parameter
|
||||
* Send options directly to viewer
|
||||
* Execution with file parameter e.g. @FileParameter.parm
|
||||
* Validate certificate SSL, default not validate
|
||||
|
||||
## Api token
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<Version>1.6.1</Version>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Version>1.7.0</Version>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AssemblyName>cv4pve-pepper</AssemblyName>
|
||||
<Company>Corsinvest Srl</Company>
|
||||
<Authors>Daniele Corsini</Authors>
|
||||
|
@ -15,13 +15,8 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Fix RedHat, Centos,Fedora -->
|
||||
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />
|
||||
|
||||
<TrimmerRootAssembly Include="System.Net.WebClient" />
|
||||
|
||||
<!-- <ProjectReference Include="..\..\..\cv4pve-api-dotnet\src\Corsinvest.ProxmoxVE.Api.Shell\Corsinvest.ProxmoxVE.Api.Shell.csproj" /> -->
|
||||
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Shell" Version="7.3.7" />
|
||||
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Shell" Version="8.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="SpicNSpan" AfterTargets="Clean">
|
||||
|
|
|
@ -5,143 +5,137 @@
|
|||
|
||||
using System;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
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;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Corsinvest.ProxmoxVE.Pepper
|
||||
var app = ConsoleHelper.CreateApp("cv4pve-pepper", "Launching SPICE remote-viewer for Proxmox VE");
|
||||
var loggerFactory = ConsoleHelper.CreateLoggerFactory<Program>(app.GetLogLevelFromDebug());
|
||||
|
||||
var optVmId = app.VmIdOrNameOption();
|
||||
|
||||
var optProxy = app.AddOption<string>("--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.");
|
||||
|
||||
var optRemoteViewer = app.AddOption<string>("--viewer", "Executable SPICE client remote viewer.")
|
||||
.AddValidatorExistFile();
|
||||
optRemoteViewer.IsRequired = true;
|
||||
|
||||
var optViewerOptions = app.AddOption<string>("--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 (ctx) =>
|
||||
{
|
||||
class Program
|
||||
var client = await app.ClientTryLoginAsync(loggerFactory);
|
||||
var proxy = ctx.ParseResult.GetValueForOption(optProxy);
|
||||
if (string.IsNullOrWhiteSpace(proxy)) { proxy = client.Host; }
|
||||
|
||||
var vmId = ctx.ParseResult.GetValueForOption(optVmId);
|
||||
|
||||
var vm = await client.GetVmAsync(vmId);
|
||||
if (ctx.ParseResult.GetValueForOption(optStartOrResume) && (vm.IsStopped || vm.IsPaused))
|
||||
{
|
||||
static async Task<int> Main(string[] args)
|
||||
var status = vm.IsStopped
|
||||
? VmStatus.Start
|
||||
: VmStatus.Resume;
|
||||
|
||||
if (app.DebugIsActive())
|
||||
{
|
||||
var app = ConsoleHelper.CreateApp("cv4pve-pepper", "Launching SPICE on Proxmox VE");
|
||||
var optVmId = app.VmIdOrNameOption();
|
||||
await Console.Out.WriteLineAsync($"VM is {(vm.IsStopped ? "stopped" : "paused")}. {status} now!");
|
||||
}
|
||||
|
||||
var optProxy = app.AddOption("--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.");
|
||||
//start VM
|
||||
var result = await VmHelper.ChangeStatusVmAsync(client, vm.Node, vm.VmType, vm.VmId, status);
|
||||
await client.WaitForTaskToFinishAsync(result, timeout: ctx.ParseResult.GetValueForOption(optWaitForStartup) * 1000);
|
||||
|
||||
var optRemoteViewer = app.AddOption("--viewer", "Executable SPICE client remote viewer.").AddValidatorExistFile();
|
||||
optRemoteViewer.IsRequired = true;
|
||||
//check VM is running
|
||||
vm = await client.GetVmAsync(vmId);
|
||||
if (app.DebugIsActive()) { await Console.Out.WriteLineAsync($"VM is {vm.Status}."); }
|
||||
}
|
||||
|
||||
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 (success, reasonPhrase, content) = await client.Nodes[vm.Node].Qemu[vm.Id].Spiceproxy.GetSpiceFileVVAsync(proxy);
|
||||
if (success)
|
||||
{
|
||||
//proxy force
|
||||
if (new Regex(@"^(http|https|)://.*$").IsMatch(proxy))
|
||||
{
|
||||
var lines = content.Split("\n");
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
var loggerFactory = ConsoleHelper.CreateLoggerFactory<Program>(app.GetLogLevelFromDebug());
|
||||
var client = await app.ClientTryLogin(loggerFactory);
|
||||
|
||||
var proxy = optProxy.GetValue();
|
||||
if (string.IsNullOrWhiteSpace(proxy)) { proxy = client.Host; }
|
||||
|
||||
var vm = await client.GetVm(optVmId.GetValue());
|
||||
|
||||
if (optStartOrResume.GetValue() && (vm.IsStopped || vm.IsPaused))
|
||||
if (lines[i].StartsWith("proxy="))
|
||||
{
|
||||
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}."); }
|
||||
lines[i] = $"proxy={proxy}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
content = string.Join("\n", lines);
|
||||
|
||||
var (success, reasonPhrase, content) = await VmHelper.GetQemuSpiceFileVV(client, vm.Node, vm.VmId, proxy);
|
||||
if (success)
|
||||
{
|
||||
//proxy force
|
||||
if (new Regex(@"^(http|https|)://.*$").IsMatch(proxy))
|
||||
{
|
||||
var lines = content.Split("\n");
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (lines[i].StartsWith("proxy="))
|
||||
{
|
||||
lines[i] = $"proxy={proxy}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
content = string.Join("\n", lines);
|
||||
if (app.DebugIsActive())
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"Replace Proxy: {proxy}");
|
||||
await Console.Out.WriteLineAsync(content);
|
||||
}
|
||||
}
|
||||
|
||||
if (app.DebugIsActive())
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"Replace Proxy: {proxy}");
|
||||
await Console.Out.WriteLineAsync(content);
|
||||
}
|
||||
}
|
||||
var fileName = Path.GetTempFileName().Replace(".tmp", ".vv");
|
||||
File.WriteAllText(fileName, content);
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = false,
|
||||
};
|
||||
|
||||
var fileName = Path.GetTempFileName().Replace(".tmp", ".vv");
|
||||
File.WriteAllText(fileName, content);
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = false,
|
||||
};
|
||||
var viewerOptions = ctx.ParseResult.GetValueForOption(optViewerOptions);
|
||||
var remoteViewer = ctx.ParseResult.GetValueForOption(optRemoteViewer);
|
||||
|
||||
var viewerOpts = optViewerOptions.GetValue();
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
startInfo.FileName = "/bin/bash";
|
||||
startInfo.Arguments = $"-c \"{remoteViewer} {fileName} {viewerOptions}\"";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
startInfo.FileName = $"\"{remoteViewer}\"";
|
||||
startInfo.Arguments = $"\"{fileName}\" {viewerOptions}";
|
||||
}
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
startInfo.FileName = "/bin/bash";
|
||||
startInfo.Arguments = $"-c \"{optRemoteViewer.GetValue()} {fileName} {viewerOpts}\"";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
startInfo.FileName = $"\"{optRemoteViewer.GetValue()}\"";
|
||||
startInfo.Arguments = $"\"{fileName}\" {viewerOpts}";
|
||||
}
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = startInfo
|
||||
};
|
||||
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = startInfo
|
||||
};
|
||||
if (app.DebugIsActive())
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"Run FileName: {process.StartInfo.FileName}");
|
||||
await Console.Out.WriteLineAsync($"Run Arguments: {process.StartInfo.Arguments}");
|
||||
}
|
||||
|
||||
if (app.DebugIsActive())
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"Run FileName: {process.StartInfo.FileName}");
|
||||
await Console.Out.WriteLineAsync($"Run Arguments: {process.StartInfo.Arguments}");
|
||||
}
|
||||
|
||||
if (!app.DryRunIsActive())
|
||||
{
|
||||
process.Start();
|
||||
ctx.ExitCode = !process.HasExited || process.ExitCode == 0
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"Error: {reasonPhrase}");
|
||||
ctx.ExitCode = 1;
|
||||
}
|
||||
});
|
||||
|
||||
return await app.ExecuteApp(args);
|
||||
if (!app.DryRunIsActive())
|
||||
{
|
||||
process.Start();
|
||||
ctx.ExitCode = !process.HasExited || process.ExitCode == 0
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"Error: {reasonPhrase}");
|
||||
ctx.ExitCode = 1;
|
||||
}
|
||||
});
|
||||
|
||||
return await app.ExecuteAppAsync(args, loggerFactory.CreateLogger(typeof(Program)));
|
Loading…
Reference in a new issue