Skip to content

Commit

Permalink
Reimplemented result with dedicated class
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Oct 4, 2017
1 parent 4fc9240 commit 9737536
Show file tree
Hide file tree
Showing 3 changed files with 2,649 additions and 1,320 deletions.
87 changes: 58 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
#eve2pve-api-java
# eve2pve-api-java
ProxmoVE Client API JAVA

[ProxmoxVE Api](https://pve.proxmox.com/pve-docs/api-viewer/)

```
______ __ _ _ ________
/ ____/___ / /____ _________ _____(_)_______ | | / / ____/
/ __/ / __ \/ __/ _ \/ ___/ __ \/ ___/ / ___/ _ \ | | / / __/
/ /___/ / / / /_/ __/ / / /_/ / / / (__ ) __/ | |/ / /___
/_____/_/ /_/\__/\___/_/ / .___/_/ /_/____/\___/ |___/_____/
/_/
(Made in Italy)
```

# General

The client is generated from a JSON Api on ProxmoxVE.
The result is a complete response from server and converted in JSONObject.

# Result

The result is class **Result** and contain methods:
* **getResponse()** returned from ProxmoxVE (data,errors,...) JSONObject
* **responseInError** (bool) : Contains errors from ProxmoxVE.
* **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
Expand All @@ -15,17 +35,21 @@ The result is a complete response from server and converted in JSONObject.
* Comment any method and parameters
* Parameters indexed eg [n] is structured in array index and value
* Tree structure
* client.getNodes().get("pve1").getQemu().vmlist().getJSONArray("data")
* Return data proxmox
* client.getNodes().get("pve1").getQemu().vmlist().getResponse().getJSONArray("data")
* Return data Proxmox VE
* Return result status
* getStatusCode
* getReasonPhrase
* isSuccessStatusCode
* Wait task finish task
* waitForTaskToFinish
* Method directry access
* get
* post
* put
* delete
* login return bool if access
* Login return bool if access
* Return Result class more information

# Usage

Expand All @@ -38,36 +62,41 @@ System.out.println(client->get('/version'));
// same for put/post/delete

//loop nodes for
JSONArray nodes = client.getNodes().index().getJSONArray("data");
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
for (JSONObject node : Client.<JSONObject>JSONArrayToList(client.getNodes().index().getJSONArray("data"))) {
for (JSONObject node : Client.<JSONObject>JSONArrayToList(client.getNodes().index().getResponse().getJSONArray("data"))) {
System.out.println(node);
}

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

//loop snashot
JSONArray snapshots = client.getNodes().get("pve1")
.getQemu().get(100).getSnapshot().snapshotList().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");
System.out.println(retCreateSnap.get("data"));

//delete snapshot
JSONObject retDeleSnap = client.getNodes().get("pve1")
.getQemu().get(100).getSnapshot().get("pippo").delsnapshot();
System.out.println(retDeleSnap.get("data"));
```
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 snashots
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
Client.Result retDeleSnap = client.getNodes().get("pve1")
.getQemu().get(100).getSnapshot().get("pippo").delsnapshot();
System.out.println(retDeleSnap.getResponse().get("data"));
```
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.enterpriseve.proxmoxve.api</groupId>
<artifactId>eve2pve-api-java</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand All @@ -30,4 +30,6 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>eve2pve-api-java</name>
<description>ProxmoVE Client API JAVA </description>
</project>
Loading

0 comments on commit 9737536

Please sign in to comment.