Giter Club home page Giter Club logo

cv4pve-api-java's Introduction

cv4pve-api-java

Proxmox VE Client API Java

GitHub release

Proxmox VE Api

   ______                _                      __
  / ____/___  __________(_)___ _   _____  _____/ /_
 / /   / __ \/ ___/ ___/ / __ \ | / / _ \/ ___/ __/
/ /___/ /_/ / /  (__  ) / / / / |/ /  __(__  ) /_
\____/\____/_/  /____/_/_/ /_/|___/\___/____/\__/

Corsinvest for Proxmox VE Api Client  (Made in Italy)

Copyright and License

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.

Result

The result is class Result and contain methods:

  • getResponse() returned from Proxmox VE (data,errors,...) JSONObject .
  • responseInError (bool) : Contains errors from Proxmox VE.
  • getStatusCode() (int) : Status code of the HTTP response.
  • getReasonPhrase() (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.

Main features

  • Easy to learn
  • Method named
  • Implementation respect the Api structure of Proxmox VE
  • Full method generated from documentation
  • Comment any method and parameters
  • Parameters indexed eg [n] is structured in array index and value
  • Tree structure
    • client.getNodes().get("pve1").getQemu().vmlist().getResponse().getJSONArray("data")
  • Return data Proxmox VE
  • Debug Level show to console information
  • Return result
    • Request
    • Response
    • Status
  • Last result action
  • Wait task finish task
    • waitForTaskToFinish
    • taskIsRunning
    • getExitStatusTask
  • Method directly access
    • get
    • set
    • create
    • delete
  • Login return bool if access
  • Return Result class more information
  • Minimal dependency library
  • ClientBase lite function
  • Form Proxmox VE 6.2 support Api Token for user
  • Login with One-time password for Two-factor authentication
  • Support for Proxy

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

Usage

//if you want use lite version only get/set/create/delete use PveClientBase

PveClient client = new PveClient("10.92.90.91", 8006);
if (client.login("root", "password", "pam")) {
        //version
        System.out.println(client.getVersion().version().getResponse().get("data"));

        // same for put/post/delete
        //loop nodes for
        JSONArray nodes = client.getNodes().index().getResponse().getJSONArray("data");
        for (int i = 0; i < nodes.length(); i++) {
                System.out.println(nodes.get(i));
        }

        //loop nodes for each
        PveClient.<JSONObject>JSONArrayToList(client.getNodes().index().getResponse().getJSONArray("data")).forEach((node) -> {
                System.out.println(node);
        });

        //loops vms qemu
        JSONArray vms = client.getNodes().get("pve1").getQemu().vmlist().getResponse().getJSONArray("data");
        for (int i = 0; i < vms.length(); i++) {
                System.out.println(vms.get(i));
        }

        //loop snapshots
        JSONArray snapshots = client.getNodes().get("pve1")
                .getQemu().get(100).getSnapshot().snapshotList().getResponse().getJSONArray("data");
        for (int i = 0; i < snapshots.length(); i++) {
                System.out.println(snapshots.get(i));
        }

        //create snapshot
        JSONObject retCreateSnap = client.getNodes().get("pve1").getQemu().get(100).getSnapshot().snapshot("pippo").getResponse();

        //print UPID
        System.out.println(retCreateSnap.get("data"));

        //wait creation
        client.waitForTaskToFinish("pve1", retCreateSnap.getString("data"), 500, 10000);

        //delete snapshot
        Result retDeleSnap = client.getNodes().get("pve1").getQemu().get(100).getSnapshot().get("pippo").delsnapshot();
        System.out.println(retDeleSnap.getResponse().get("data"));
}

Escape string

For escape string use URLEncoder.encode

Map<Integer, String> netN = new HashMap<>();
netN.put(1, URLEncoder.encode("name=eth0,rate=15,bridge=vmbr0,firewall=1,gw=xx.xx.xx.xx,ip=xx.xx.xx.xx/24,hwaddr=02:00:be:0f:f2:63",StandardCharsets.UTF_8));

cv4pve-api-java's People

Contributors

franklupo avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.