virtualizorjs 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/examples/eventhandling.js +9 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Since there is no SDK's for Node.js for the Virtualizor API, I decided to create
|
|
|
4
4
|
|
|
5
5
|
VirtualizorJS simplifies the management of Virtualizor servers with a streamlined and developer-friendly API for Node.js. Perform actions such as creating, starting, stopping, and restarting virtual servers effortlessly. Ideal for seamless integration into your Node.js applications, providing a powerful toolkit for Virtualizor server management.
|
|
6
6
|
|
|
7
|
-
[](https://badge.fury.io/js/virtualizorjs)
|
|
8
8
|
|
|
9
9
|
## Important
|
|
10
10
|
- This library is still in development and there is more to add but for now it's stable and ready to use, all the methods have been tested and work as expected.
|
|
@@ -51,20 +51,21 @@ ListVPS().then((data) => {
|
|
|
51
51
|
|
|
52
52
|
VirtualizorJS uses the [EventEmitter](https://nodejs.org/api/events.html) class to handle events. You can attach **`Event Listeners`** to different events provided by the VirtualizorClient.
|
|
53
53
|
|
|
54
|
-
- Note:
|
|
54
|
+
- Note: To use **`Event Listeners`** we need to define the **`VirtualizorClient`** as a `const` named preferably **`Client`** and then use **`Client.on()`** to attach **`Event Listeners`** to different events.
|
|
55
55
|
|
|
56
56
|
```javascript
|
|
57
57
|
const VirtualizorClient = require('virtualizorjs');
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
// The "eventOn" method is used to attach Event Listeners to different events provided by the VirtualizorClient.
|
|
61
|
-
const { on: eventOn } = new VirtualizorClient({
|
|
59
|
+
const Client = new VirtualizorClient({
|
|
62
60
|
host: '< IP or Hostname of Virtualizor Server >',
|
|
63
61
|
port: 4085,
|
|
64
62
|
adminapikey: "< Your API KEY >",
|
|
65
63
|
adminapipass: "< Your API PASS >",
|
|
66
64
|
});
|
|
67
65
|
|
|
66
|
+
//Get the methods you need
|
|
67
|
+
const { StartVPS } = Client;
|
|
68
|
+
|
|
68
69
|
// - Event Types - :
|
|
69
70
|
// 1. vpsCreated
|
|
70
71
|
// 2. vpsStarted
|
|
@@ -72,22 +73,22 @@ const { on: eventOn } = new VirtualizorClient({
|
|
|
72
73
|
// 4. vpsRestarted
|
|
73
74
|
|
|
74
75
|
// Event listener for when a virtual server is created
|
|
75
|
-
|
|
76
|
+
Client.on('vpsCreated', (response) => {
|
|
76
77
|
console.log(`Virtual Server Created! Details:`, response);
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
// Event listener for when a virtual server is started
|
|
80
|
-
|
|
81
|
+
Client.on('vpsStarted', (response) => {
|
|
81
82
|
console.log(`Virtual Server Started! Details:`, response);
|
|
82
83
|
});
|
|
83
84
|
|
|
84
85
|
// Event listener for when a virtual server is stopped
|
|
85
|
-
|
|
86
|
+
Client.on('vpsStopped', (response) => {
|
|
86
87
|
console.log(`Virtual Server Stopped! Details:`, response);
|
|
87
88
|
});
|
|
88
89
|
|
|
89
90
|
// Event listener for when a virtual server is restarted
|
|
90
|
-
|
|
91
|
+
Client.on('vpsRestarted', (response) => {
|
|
91
92
|
console.log(`Virtual Server Restarted! Details:`, response);
|
|
92
93
|
});
|
|
93
94
|
```
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
const VirtualizorClient = require('virtualizorjs');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Client = new VirtualizorClient({
|
|
4
4
|
host: '< IP or Hostname of Virtualizor Server >',
|
|
5
5
|
port: 4085,
|
|
6
6
|
adminapikey: "< Your API KEY >",
|
|
7
7
|
adminapipass: "< Your API PASS >",
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
+
const { StartVPS } = Client;
|
|
11
|
+
|
|
12
|
+
StartVPS(1);
|
|
13
|
+
|
|
10
14
|
// Event listener for when a virtual server is created
|
|
11
|
-
|
|
15
|
+
Client.on('vpsCreated', (response) => {
|
|
12
16
|
console.log(`Virtual Server Created! Details:`, response);
|
|
13
17
|
// Output: Virtual Server Created! Details: { ...virtualizorResponse }
|
|
14
18
|
});
|
|
15
19
|
|
|
16
20
|
// Event listener for when a virtual server is started
|
|
17
|
-
|
|
21
|
+
Client.on('vpsStarted', (response) => {
|
|
18
22
|
console.log(`Virtual Server Started! Details:`, response);
|
|
19
23
|
// Output: Virtual Server Started! Details: { ...virtualizorResponse }
|
|
20
24
|
});
|
|
21
25
|
|
|
22
26
|
// Event listener for when a virtual server is stopped
|
|
23
|
-
|
|
27
|
+
Client.on('vpsStopped', (response) => {
|
|
24
28
|
console.log(`Virtual Server Stopped! Details:`, response);
|
|
25
29
|
// Output: Virtual Server Stopped! Details: { ...virtualizorResponse }
|
|
26
30
|
});
|
|
27
31
|
|
|
28
32
|
// Event listener for when a virtual server is restarted
|
|
29
|
-
|
|
33
|
+
Client.on('vpsRestarted', (response) => {
|
|
30
34
|
console.log(`Virtual Server Restarted! Details:`, response);
|
|
31
35
|
// Output: Virtual Server Restarted! Details: { ...virtualizorResponse }
|
|
32
36
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "virtualizorjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "VirtualizorJS simplifies the management of Virtualizor servers with a streamlined and developer-friendly API for Node.js. Perform actions such as creating, starting, stopping, and restarting virtual servers effortlessly. Ideal for seamless integration into your Node.js applications, providing a powerful toolkit for Virtualizor server management.",
|
|
5
5
|
"main": "./src/VirtualizorClient.js",
|
|
6
6
|
"scripts": {},
|