Skip to content

Commit

Permalink
Force proxy to replace default value in .vv file
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Nov 19, 2020
1 parent a08c9d7 commit 01fc6b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -24,6 +24,7 @@ Options:
--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 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
Commands:
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.3.8</Version>
<Version>1.3.9</Version>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>cv4pve-pepper</AssemblyName>
<Company>Corsinvest Srl</Company>
Expand Down
30 changes: 27 additions & 3 deletions src/Corsinvest.ProxmoxVE.Pepper/Program.cs
Expand Up @@ -31,7 +31,8 @@ static int Main(string[] args)
var optProxy = app.Option("--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 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);

var optRemoteViewer = app.Option("--viewer",
Expand All @@ -43,13 +44,36 @@ static int Main(string[] args)
app.OnExecute(() =>
{
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;
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");
File.WriteAllText(fileName, content);
var startInfo = new ProcessStartInfo
Expand Down

0 comments on commit 01fc6b3

Please sign in to comment.