项目作者: Corsinvest

项目描述 :
Proxmox VE Client API .Net C#
高级语言: C#
项目地址: git://github.com/Corsinvest/cv4pve-api-dotnet.git
创建时间: 2017-09-02T23:22:50Z
项目社区:https://github.com/Corsinvest/cv4pve-api-dotnet

开源协议:Other

下载


Corsinvest.ProxmoxVE.Api

Nuget Nuget Nuget Nuget Nuget

Proxmox VE Client API .Net

Proxmox VE Api

  1. ______ _ __
  2. / ____/___ __________(_)___ _ _____ _____/ /_
  3. / / / __ \/ ___/ ___/ / __ \ | / / _ \/ ___/ __/
  4. / /___/ /_/ / / (__ ) / / / / |/ / __(__ ) /_
  5. \____/\____/_/ /____/_/_/ /_/|___/\___/____/\__/
  6. Corsinvest for Proxmox VE Api Client (Made in Italy)

Copyright: Corsinvest Srl
For licensing details please visit LICENSE

Commercial Support

This software is part of a suite of tools called cv4pve-tools. If you want commercial support, visit the site

General

The client is generated from a JSON Api on Proxmox VE.

Main features

  • Easy to learn
  • Method named
  • Implementation respect the Api structure of Proxmox VE
  • Set ResponseType json, png
  • Full class and method generated from documentation (about client)
  • Comment any method and parameters
  • Parameters indexed eg [n] is structured in array index and value
  • Tree structure
    • client.Nodes[“pve1”].Qemu[100].Snapshot().snapshotList().Response.data
  • Return data Proxmox VE
  • Logger with MicrosMicrosoft.Extensions.Logging
  • Return result
    • Request
    • Response
    • Status
  • Last result action
  • Task utility
    • WaitForTaskToFinish
    • TaskIsRunning
    • GetExitStatusTask
  • Method direct access
    • Get
    • Create (Post)
    • Set (Put)
    • Delete
  • Login return bool if access
  • Return Result class more information
  • ClientBase lite function
  • Form Proxmox VE 6.2 support Api Token for user
  • Async / Await
  • Add model in Shared library for decode json
  • Add Extension method Get to decode in json from result in Extension library
  • Login with One-time password for Two-factor authentication
  • Set Timeout for the Connection.
  • Validate certificate SSL, default not validate

Api token

From version 6.2 of Proxmox VE is possible to use Api token.
This feature permit execute Api without using user and password.
If using Privilege Separation when create api token remember specify in permission.
Format USER@REALM!TOKENID=UUID

Result

The result is class Result and contain properties:

  • Response returned from Proxmox VE (data,errors,…) dynamic ExpandoObject.aspx)
  • ResponseToDictionary return response to dictionary IDictionary<String, object>
  • ResponseInError (bool) : Contains errors from Proxmox VE.
  • StatusCode (System.Net.HttpStatusCode): Status code of the HTTP response.
  • ReasonPhrase (string): The reason phrase which typically is sent by servers together with the status code.
  • IsSuccessStatusCode (bool) : Gets a value that indicates if the HTTP response was successful.
  • GetError() (string) : Get error.

Example result:

  1. {
  2. "data": {
  3. "smbios1": "uuid=9246585e-0c8b-4d02-8fe2-f48fd0da3975",
  4. "ide2": "none,media=cdrom",
  5. "onboot": 1,
  6. "boot": "cdn",
  7. "cores": 2,
  8. "agent": 1,
  9. "memory": 4096,
  10. "numa": 0,
  11. "bootdisk": "virtio0",
  12. "sockets": 1,
  13. "net0": "virtio=3A:39:38:30:36:31,bridge=vmbr0",
  14. "parent": "auto4hours170904080002",
  15. "digest": "acafde32daab50bce801fef2e029440c54ebe2f7",
  16. "vga": "qxl",
  17. "virtio0": "local-zfs:vm-100-disk-1,cache=writeback,size=50G",
  18. "ostype": "win8",
  19. "name": "phenometa"
  20. }
  21. }

Usage

  1. //if you want use lite version only get/set/create/delete use PveClientBase
  2. var client = new PveClient("10.92.90.91");
  3. if (await client.Login("root", "password"))
  4. {
  5. var vm = await client.Nodes["pve1"].Qemu[100];
  6. //config vm
  7. var config = await vm.Config.VmConfig();
  8. Console.WriteLine(JsonConvert.SerializeObject(config.Response,Formatting.Indented));
  9. //create snapshot
  10. var response = await vm.Snapshot.Snapshot("pippo2311");
  11. //update snapshot description
  12. await vm.Snapshot["pippo2311"].Config.UpdateSnapshotConfig("description");
  13. //delete snapshot
  14. await vm.Snapshot["pippo2311"].Delsnapshot();
  15. //list of snapshot
  16. foreach (var snapshot in (await vm.Snapshot.SnapshotList()).Response.data)
  17. {
  18. Console.WriteLine(JsonConvert.SerializeObject(snapshot,Formatting.Indented));
  19. Console.WriteLine(snapshot.name);
  20. }
  21. //change response type from json to png
  22. client.ResponseType = "png";
  23. var dataImg = client.Nodes["pve1"].Rrd.Rrd("cpu", "day").Response;
  24. Console.WriteLine("<img src=\"{dataImg}\" \>");
  25. }
  26. //using Api Token
  27. var client = new PveClient("10.92.100.33");
  28. client.ApiToken = "root@pam!qqqqqq=8a8c1cd4-d373-43f1-b366-05ce4cb8061f";
  29. var version = await client.Version.Version();
  30. Console.WriteLine(JsonConvert.SerializeObject(version.Response.data, Formatting.Indented));

Corsinvest.ProxmoxVE.Extension

Extension add functionality on Api.

  • ApiExplorer
  • Retrive VM/CT data from name or id
  • Simplify management of VM/CT e.g snapshot
  • Extension method Get to decode json from result
    e.g Client.Cluster.Status.Get() return IEnumerable

Corsinvest.ProxmoxVE.Shared

Contain model for Json conversion and utility.

Corsinvest.ProxmoxVE.Metadata

Read documentation ProxmoxVE API and extract structure.

Corsinvest.ProxmoxVE.Shell

Utility for console application.