corsinvest / cv4pve-api-dotnet Goto Github PK
View Code? Open in Web Editor NEWProxmox VE Client API .Net C#
Home Page: https://www.corsinvest.it/cv4pve
License: GNU General Public License v3.0
Proxmox VE Client API .Net C#
Home Page: https://www.corsinvest.it/cv4pve
License: GNU General Public License v3.0
While analyzing the source code, I came across the following line:
However, according to Microsoft documentation, it's strongly recommended to reuse the same copy of HttpClient:
HttpClient is intended to be instantiated once per application, rather than per-use
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0
If I understand correctly, the using statement ensures that the HttpClient instance is disposed, preventing resource leaks. However, creating a new instance of HttpClient every time can lead to performance issues and even resource exhaustion.
Could you please explain why it's done that way, using "using"?
Hello,
I just updated the Nuget package, but unfortunately it seems that the version that is installed with Nuget is not the one that is provided on Github.
Can you please check this and possibly update it?
Thank you
Philipp
Here is an example:
Github code:
public async Task<Result> Vzdump(bool? all = null, int? bwlimit = null, string compress = null, string dumpdir = null, string exclude = null, string exclude_path = null, int? ionice = null, int? lockwait = null, string mailnotification = null, string mailto = null, int? maxfiles = null, string mode = null, string notes_template = null, string notification_policy = null, string notification_target = null, string performance = null, int? pigz = null, string pool = null, bool? protected_ = null, string prune_backups = null, bool? quiet = null, bool? remove = null, string script = null, bool? stdexcludes = null, bool? stdout = null, bool? stop = null, int? stopwait = null, string storage = null, string tmpdir = null, string vmid = null, int? zstd = null)
{
var parameters = new Dictionary<string, object>();
parameters.Add("all", all);
parameters.Add("bwlimit", bwlimit);
parameters.Add("compress", compress);
parameters.Add("dumpdir", dumpdir);
parameters.Add("exclude", exclude);
parameters.Add("exclude-path", exclude_path);
parameters.Add("ionice", ionice);
parameters.Add("lockwait", lockwait);
parameters.Add("mailnotification", mailnotification);
parameters.Add("mailto", mailto);
parameters.Add("maxfiles", maxfiles);
parameters.Add("mode", mode);
parameters.Add("notes-template", notes_template);
parameters.Add("notification-policy", notification_policy);
parameters.Add("notification-target", notification_target);
parameters.Add("performance", performance);
parameters.Add("pigz", pigz);
parameters.Add("pool", pool);
parameters.Add("protected", protected_);
parameters.Add("prune-backups", prune_backups);
parameters.Add("quiet", quiet);
parameters.Add("remove", remove);
parameters.Add("script", script);
parameters.Add("stdexcludes", stdexcludes);
parameters.Add("stdout", stdout);
parameters.Add("stop", stop);
parameters.Add("stopwait", stopwait);
parameters.Add("storage", storage);
parameters.Add("tmpdir", tmpdir);
parameters.Add("vmid", vmid);
parameters.Add("zstd", zstd);
return await _client.Create($"/nodes/{_node}/vzdump", parameters);
}
Code of Nuget Package:
public async Task<Result> Vzdump(bool? all = null, int? bwlimit = null, string compress = null, string dumpdir = null, string exclude = null, string exclude_path = null, int? ionice = null, int? lockwait = null, string mailnotification = null, string mailto = null, int? maxfiles = null, string mode = null, string notes_template = null, string performance = null, int? pigz = null, string pool = null, bool? protected_ = null, string prune_backups = null, bool? quiet = null, bool? remove = null, string script = null, bool? stdexcludes = null, bool? stdout = null, bool? stop = null, int? stopwait = null, string storage = null, string tmpdir = null, string vmid = null, int? zstd = null)
{
var parameters = new Dictionary<string, object>();
parameters.Add("all", all);
parameters.Add("bwlimit", bwlimit);
parameters.Add("compress", compress);
parameters.Add("dumpdir", dumpdir);
parameters.Add("exclude", exclude);
parameters.Add("exclude-path", exclude_path);
parameters.Add("ionice", ionice);
parameters.Add("lockwait", lockwait);
parameters.Add("mailnotification", mailnotification);
parameters.Add("mailto", mailto);
parameters.Add("maxfiles", maxfiles);
parameters.Add("mode", mode);
parameters.Add("notes-template", notes_template);
parameters.Add("performance", performance);
parameters.Add("pigz", pigz);
parameters.Add("pool", pool);
parameters.Add("protected", protected_);
parameters.Add("prune-backups", prune_backups);
parameters.Add("quiet", quiet);
parameters.Add("remove", remove);
parameters.Add("script", script);
parameters.Add("stdexcludes", stdexcludes);
parameters.Add("stdout", stdout);
parameters.Add("stop", stop);
parameters.Add("stopwait", stopwait);
parameters.Add("storage", storage);
parameters.Add("tmpdir", tmpdir);
parameters.Add("vmid", vmid);
parameters.Add("zstd", zstd);
return await _client.Create($"/nodes/{_node}/vzdump", parameters);
}
No response
.Net 8.0
8.1.0
8.1.0
No response
Windows
how do list all nodes and list all virtual machines and containers?
Corsinvest.ProxmoxVE.Api (2.4.0.0)
client.UseApiToken("");
Error CS1061 'PveClient' does not contain a definition for 'UseApiToken' and no accessible extension method 'UseApiToken' accepting a first argument of type 'PveClient' could be found (are you missing a using directive or an assembly reference?)
We got very far with our wrapping of this awesome package, but failed at the uploading of ISOs.
Our Code:
internal bool UploadISO(string hostname, string isoFile, string sha256, string? overrideFileName)
{
var task = _client.Nodes[hostname].Storage["local"].Upload.Upload("iso", overrideFileName ?? Path.GetFileName(isoFile), checksum: sha256, checksum_algorithm: "sha256")
task.Wait();
var result = task.Result;
return result.IsSuccessStatusCode;
}
Where isoFile is for example "C:/someISO.iso", overrideFileName would be "windowsXYZ.iso" or null and the sha matching.
We fail on the task.Wait() with the exception of:
One or more errors occurred. (An error occurred while sending the request.)
We would expect our file to be uploaded just as with the ui, but it's also unclear to us, how the file content is being uploaded. Maybe hence we get an error?
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at osisa.SystemManagement.Proxmox.Proxmox.UploadISO(MachineName hostname, String isoFile, String sha256, String overrideFileName) in C:\git\main\netbase\src\osisa.SystemManagement.Proxmox\Proxmox.cs:line 291
at osisa.SystemManagement.Proxmox.Host.UploadISO(String isoFile, String sha256, String overrideFileName) in C:\git\main\netbase\src\osisa.SystemManagement.Proxmox\Host.cs:line 195
at osisa.SystemManagement.Proxmox.Tests.SpikeTests.UploadISO(String isoFile, String sha256) in C:\git\main\netbase\src\osisa.SystemManagement.Proxmox.Tests\SpikeTests.cs:line 188
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
at System.Net.Http.HttpConnection.<SendAsyncCore>d__61.MoveNext()
at System.Net.Http.HttpConnectionPool.<SendWithVersionDetectionAndRetryAsync>d__86.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.RedirectHandler.<SendAsync>d__4.MoveNext()
at System.Net.Http.HttpClient.<<SendAsync>g__Core|83_0>d.MoveNext()
at Corsinvest.ProxmoxVE.Api.PveClientBase.<ExecuteAction>d__36.MoveNext()
at Corsinvest.ProxmoxVE.Api.PveClientBase.<Create>d__32.MoveNext()
at Corsinvest.ProxmoxVE.Api.PveClient.PveNodes.PveNodeItem.PveStorage.PveStorageItem.PveUpload.<Upload>d__4.MoveNext()
The response ended prematurely.
at System.Net.Http.HttpConnection.<SendAsyncCore>d__61.MoveNext()
netstandard2.0
7.3-1
8.0.0
No response
Windows
.Nodes[node].Lxc.CreateVm() takes in a parameter cpulimit of type int?
In the API, this value is specified as a "number" and not "integer", meaning it can be floating point, and is allowed to be non-integer trough the Proxmox API and GUI.
This doesn't seem possible with this library as it requires integers, making fractional limits that aren't a taking a full core impossible (1.5, 0.5, etc.)
Hello,
thank you for this package, however I lack of understanding how it works.
For example, I'm trying to get all users and log the response in a richTextBox:
var client = new PveClient(File.ReadLines(ipList).First());
if(client.Login("root", File.ReadLines(passwordList).First()))
{
Log("Connected to " + client.Hostname, 1);
var users = client.Get("/access/users");
Log(users.Response, 2);
}
however it does not work as supposed to. What am I doing wrong?
Is there a reason why in Corsinvest.ProxmoxVE.Api.Extension.VM.VMInfo.SetStatus resume is not an available case considering Suspend is implemented?
Just curious if there's a reason for that or if just hasn't been implemented yet, either way I figure I could always handle that in my own code.
Hi guys,
Im searching for a way to create a virtual machine using the proxmox api,
This is working well but i cant find anywhere how i can create a vm.
string ip = Settings.Default["ip"].ToString();
string token = Settings.Default["token"].ToString();
var client = new PveClient(ip);
client.ApiToken = token;
Maybe someone can help me with a example orsomething
Thnx,
I've tried deleting a container, with the result of Unexpected content for method 'DELETE'
and StatusCode of NotImplemented.
.Net Version: 5.0
cv4pve-api-dotnet Version: 7.0.1
Proxmox Version: 7.0-13
Steps to reproduce are quite simple:
Make a container
Try to delete it through code, with .DestroyVm(true, true, true)
Trying to use PveClientBase.WaitForTaskToFinish() causes 100% CPU usage on one core for prolonged periods of time until the task is finished.
This is due to how its coded, a while loop that constantly checks a condition.
PveClientBase.WaitForTaskToFinish(), since it already blocks a thread waiting for something, it shouldn't constantly try to check for time when its supplied a "wait" parameter - Instead, a Thread.Sleep() would be much better - Both block the thread, but Thread.Sleep() doesn't also utilize 100% of a CPU core.
Suggested Fix
Change these lines (
cv4pve-api-dotnet/src/Corsinvest.ProxmoxVE.Api/PveClientBase.cs
Lines 325 to 332 in 556cee5
while (isRunning && (DateTime.Now - timeStart).Milliseconds < timeOut)
{
// Maybe even make the "wait" a int, instead of long by default
Thread.Sleep((int)wait);
isRunning = TaskIsRunning(node, task);
}
No response
.Net 5.0
7.0-13
7.0.1
No response
Linux
Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.