1
0
Fork 0
mirror of https://github.com/Corsinvest/cv4pve-pepper.git synced 2025-02-12 10:01:53 +00:00

Force proxy to replace default value in .vv file

This commit is contained in:
Daniele Corsini 2020-11-19 09:07:36 +01:00
parent a08c9d7852
commit 01fc6b38da
3 changed files with 29 additions and 4 deletions

View file

@ -24,6 +24,7 @@ Options:
--proxy SPICE proxy server. This can be used by the client to specify the proxy server. --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. All nodes in a cluster runs 'spiceproxy', so it is up to the client to choose one.
By default, we return the node where the VM is currently running. By default, we return the node where the VM is currently running.
If specify http://[host]:[port] then replace proxy option in file .vv. E.g. for reverse proxy.
--viewer Executable SPICE client remote viewer --viewer Executable SPICE client remote viewer
Commands: Commands:

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<Version>1.3.8</Version> <Version>1.3.9</Version>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>cv4pve-pepper</AssemblyName> <AssemblyName>cv4pve-pepper</AssemblyName>
<Company>Corsinvest Srl</Company> <Company>Corsinvest Srl</Company>

View file

@ -31,7 +31,8 @@ namespace Corsinvest.ProxmoxVE.Pepper
var optProxy = app.Option("--proxy", var optProxy = app.Option("--proxy",
@"SPICE proxy server. This can be used by the client to specify the proxy server." + @"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." + " All nodes in a cluster runs 'spiceproxy', so it is up to the client to choose one." +
" By default, we return the node where the VM is currently running.", " By default, we return the node where the VM is currently running." +
" If specify http://[host]:[port] then replace proxy option in file .vv. E.g. for reverse proxy.",
CommandOptionType.SingleValue); CommandOptionType.SingleValue);
var optRemoteViewer = app.Option("--viewer", var optRemoteViewer = app.Option("--viewer",
@ -43,13 +44,36 @@ namespace Corsinvest.ProxmoxVE.Pepper
app.OnExecute(() => app.OnExecute(() =>
{ {
var client = app.ClientTryLogin(); var client = app.ClientTryLogin();
var content = client.GetVM(optVmId.Value())
.GetSpiceFileVV(optProxy.HasValue() ? optProxy.Value() : null);
var proxy = optProxy.HasValue() ? optProxy.Value() : null;
var proxyForce = (proxy + "").ToLower().StartsWith("http://");
var content = client.GetVM(optVmId.Value()).GetSpiceFileVV(proxyForce ? null : proxy);
var ret = client.LastResult.IsSuccessStatusCode; var ret = client.LastResult.IsSuccessStatusCode;
if (ret) if (ret)
{ {
//proxy force
if (proxyForce)
{
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())
{
app.Out.WriteLine($"Replace Proxy: {proxy}");
app.Out.WriteLine(content);
}
}
var fileName = Path.GetTempFileName().Replace(".tmp", ".vv"); var fileName = Path.GetTempFileName().Replace(".tmp", ".vv");
File.WriteAllText(fileName, content); File.WriteAllText(fileName, content);
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo