virtualizorjs 1.0.0-beta
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/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/SECURITY.md +25 -0
- package/examples/createvps.js +33 -0
- package/examples/eventhandling.js +32 -0
- package/examples/listvps.js +117 -0
- package/package.json +38 -0
- package/src/Actions.js +73 -0
- package/src/VirtualizorClient.js +536 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the
|
|
26
|
+
overall community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or
|
|
31
|
+
advances of any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email
|
|
35
|
+
address, without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
|
86
|
+
of actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
|
93
|
+
permanent ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
|
113
|
+
the community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.0, available at
|
|
119
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
122
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
|
123
|
+
|
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
|
125
|
+
|
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
127
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
128
|
+
https://www.contributor-covenant.org/translations.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
|
|
2
|
+
# Contributing to VirtualizorJS
|
|
3
|
+
|
|
4
|
+
Welcome to VirtualizorJS! We appreciate your interest in contributing to our project. By contributing, you help make VirtualizorJS better for everyone. Please take a moment to review this document before getting started.
|
|
5
|
+
|
|
6
|
+
## Table of Contents
|
|
7
|
+
|
|
8
|
+
1. [Code of Conduct](#code-of-conduct)
|
|
9
|
+
2. [How Can I Contribute?](#how-can-i-contribute)
|
|
10
|
+
3. [Getting Started](#getting-started)
|
|
11
|
+
- [Fork the Repository](#fork-the-repository)
|
|
12
|
+
- [Clone the Repository](#clone-the-repository)
|
|
13
|
+
- [Install Dependencies](#install-dependencies)
|
|
14
|
+
- [Make Changes](#make-changes)
|
|
15
|
+
- [Test Your Changes](#test-your-changes)
|
|
16
|
+
4. [Submitting a Pull Request](#submitting-a-pull-request)
|
|
17
|
+
5. [Code of Conduct](#code-of-conduct)
|
|
18
|
+
6. [License](#license)
|
|
19
|
+
|
|
20
|
+
## Code of Conduct
|
|
21
|
+
|
|
22
|
+
Please review our [Code of Conduct](CODE_OF_CONDUCT.md) to understand the standards and expectations for all contributors.
|
|
23
|
+
|
|
24
|
+
## How Can I Contribute?
|
|
25
|
+
|
|
26
|
+
### Reporting Bugs
|
|
27
|
+
|
|
28
|
+
If you encounter a bug, please [open an issue](../../issues) and provide as much detail as possible.
|
|
29
|
+
|
|
30
|
+
### Suggesting Enhancements
|
|
31
|
+
|
|
32
|
+
Have an idea to enhance VirtualizorJS? Feel free to [open an issue](../../issues) with your suggestion, or even better, submit a pull request.
|
|
33
|
+
|
|
34
|
+
### Pull Requests
|
|
35
|
+
|
|
36
|
+
We welcome contributions! Before submitting a pull request, please ensure:
|
|
37
|
+
|
|
38
|
+
- Your code adheres to the existing coding style.
|
|
39
|
+
- You have documented any new features or changes.
|
|
40
|
+
|
|
41
|
+
## Getting Started
|
|
42
|
+
|
|
43
|
+
### Fork the Repository
|
|
44
|
+
|
|
45
|
+
Click on the "Fork" button at the top right of the repository page to create your copy.
|
|
46
|
+
|
|
47
|
+
### Clone the Repository
|
|
48
|
+
|
|
49
|
+
Clone your forked repository to your local machine:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
git clone https://github.com/kkMihai/virtualizorjs.git
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Install Dependencies
|
|
56
|
+
|
|
57
|
+
Navigate to the project directory and install dependencies:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
cd virtualizorjs
|
|
61
|
+
npm install
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Make Changes
|
|
65
|
+
|
|
66
|
+
Make your changes and add new features or fix bugs.
|
|
67
|
+
|
|
68
|
+
### Test Your Changes
|
|
69
|
+
|
|
70
|
+
Ensure that your changes don't introduce new issues. Run tests and fix any failures:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm test
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Submitting a Pull Request
|
|
77
|
+
|
|
78
|
+
When you're ready to submit your changes:
|
|
79
|
+
|
|
80
|
+
1. Commit your changes: `git commit -m "Your commit message"`
|
|
81
|
+
2. Push to your fork: `git push origin your-branch`
|
|
82
|
+
3. Open a pull request from your fork to the `main` branch of the original repository.
|
|
83
|
+
|
|
84
|
+
Our team will review your pull request and provide feedback. Thank you for contributing to VirtualizorJS!
|
|
85
|
+
|
|
86
|
+
## Code of Conduct
|
|
87
|
+
|
|
88
|
+
Please follow our [Code of Conduct](CODE_OF_CONDUCT.md) in all interactions.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
By contributing to VirtualizorJS, you agree that your contributions will be licensed under the [MIT License](LICENSE).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 kkMihai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# VirtualizorJS
|
|
2
|
+
|
|
3
|
+
Since there is no SDK's for Node.js for the Virtualizor API, I decided to create one, and one that is actually easy to use and useful with **0 Dependencies** keeping it `Lightweight` and `Fast`.
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
[](https://badge.fury.io/js/virtualizorjs)
|
|
8
|
+
|
|
9
|
+
## Important
|
|
10
|
+
- As of `19 January 2024` Not all Virtualizor API functions are tested fully. ( i m busy (just lazy lmao))
|
|
11
|
+
|
|
12
|
+
## Table of Contents
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Usage](#usage)
|
|
15
|
+
- [Examples](#examples)
|
|
16
|
+
- [API Documentation](#api-documentation)
|
|
17
|
+
- [Contributing](#contributing)
|
|
18
|
+
- [License](#license)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm i virtualizorjs@latest
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
|
|
30
|
+
const VirtualizorClient = require('virtualizorjs');
|
|
31
|
+
|
|
32
|
+
// Initialize VirtualizorClient
|
|
33
|
+
const { ListVPS } = new VirtualizorClient({
|
|
34
|
+
host: '< IP or Hostname of Virtualizor Server >',
|
|
35
|
+
port: 4083,
|
|
36
|
+
key: "< Your API KEY >",
|
|
37
|
+
pass: "< Your API PASS >",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Using const client = new VirtualizorClient({ ... }) is also valid, but you will have to use client.ListVPS() instead of ListVPS() which just looks ugly.
|
|
41
|
+
// Example: Get a list of all VPSs
|
|
42
|
+
ListVPS().then((data) => {
|
|
43
|
+
console.log(data);
|
|
44
|
+
}).catch((err) => {
|
|
45
|
+
console.log(err);
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
# Event Handling Usage
|
|
50
|
+
|
|
51
|
+
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.
|
|
52
|
+
|
|
53
|
+
- Note: We define the "on" method as "eventOn" to avoid confusion with the EventEmitter's "on" method, However you can do it however you want this is just an example.
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
const VirtualizorClient = require('virtualizorjs');
|
|
57
|
+
|
|
58
|
+
// We define the "on" method as "eventOn" to avoid confusion with the EventEmitter's "on" method, However you can do it however you want this is just an example.
|
|
59
|
+
// The "eventOn" method is used to attach Event Listeners to different events provided by the VirtualizorClient.
|
|
60
|
+
const { on: eventOn } = new VirtualizorClient({
|
|
61
|
+
host: '< IP or Hostname of Virtualizor Server >',
|
|
62
|
+
port: 4083,
|
|
63
|
+
key: "< Your API KEY >",
|
|
64
|
+
pass: "< Your API PASS >",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// - Event Types - :
|
|
68
|
+
// 1. vpsCreated
|
|
69
|
+
// 2. vpsStarted
|
|
70
|
+
// 3. vpsStopped
|
|
71
|
+
// 4. vpsRestarted
|
|
72
|
+
|
|
73
|
+
// Event listener for when a virtual server is created
|
|
74
|
+
eventOn('vpsCreated', (response) => {
|
|
75
|
+
console.log(`Virtual Server Created! Details:`, response);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Event listener for when a virtual server is started
|
|
79
|
+
eventOn('vpsStarted', (response) => {
|
|
80
|
+
console.log(`Virtual Server Started! Details:`, response);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Event listener for when a virtual server is stopped
|
|
84
|
+
eventOn('vpsStopped', (response) => {
|
|
85
|
+
console.log(`Virtual Server Stopped! Details:`, response);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Event listener for when a virtual server is restarted
|
|
89
|
+
eventOn('vpsRestarted', (response) => {
|
|
90
|
+
console.log(`Virtual Server Restarted! Details:`, response);
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## ❓ What's the point of using **`Event Listeners`**?
|
|
95
|
+
- **`Event Listeners`** are useful when you want to perform an action when a certain event occurs without modifying the source code of the **`VirtualizorJS`** library to avoid breaking changes.
|
|
96
|
+
- For example, you can use **`Event Listeners`** to send a notification to your `users` when a event is triggered.
|
|
97
|
+
- You can also use **`Event Listeners`** to perform an action when a event is triggered.
|
|
98
|
+
|
|
99
|
+
## Examples
|
|
100
|
+
|
|
101
|
+
- [Get VPS's List](/examples/listvps.js)
|
|
102
|
+
- [Create VPS](/examples/createvps.js)
|
|
103
|
+
- [Using Event Handling](/examples/eventhandling.js)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Documentation
|
|
107
|
+
|
|
108
|
+
- Check the [Wiki](https://github.com/kkMihai/virtualizorjs/wiki) for detailed documentation.
|
|
109
|
+
|
|
110
|
+
## Roadmap
|
|
111
|
+
- [ ] Add Proxmox KVM Support
|
|
112
|
+
- [ ] Add Virtualization Types enums
|
|
113
|
+
|
|
114
|
+
## Contributing
|
|
115
|
+
|
|
116
|
+
- Feel free to contribute by opening issues or submitting pull requests. See [CONTRIBUTING](/CONTRIBUTING.md) for details.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
- This project is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Supported |
|
|
6
|
+
| ------- | ------------------ |
|
|
7
|
+
| 1.0.0 | :white_check_mark: |
|
|
8
|
+
|
|
9
|
+
## Reporting a Vulnerability
|
|
10
|
+
|
|
11
|
+
If you discover any security issues within the project, please report them by following these guidelines:
|
|
12
|
+
|
|
13
|
+
1. **Go to the Issues section:** Visit [GitHub Issues](https://github.com/kkMihai/virtualizorjs/issues) to check if the vulnerability has already been reported or discussed.
|
|
14
|
+
|
|
15
|
+
2. **Open a New Issue:** If the vulnerability is not reported, please open a new issue.
|
|
16
|
+
|
|
17
|
+
3. **Provide Details:** Clearly describe the nature of the vulnerability, including steps to reproduce if possible. The more information you provide, the easier it is for us to understand and address the issue.
|
|
18
|
+
|
|
19
|
+
4. **Expectations:** We will acknowledge your report within a reasonable timeframe and strive to keep you informed of the progress.
|
|
20
|
+
|
|
21
|
+
5. **Resolution:** Once the vulnerability is validated, we will work on resolving it. The timeline for resolution may vary based on the severity of the issue.
|
|
22
|
+
|
|
23
|
+
Please note that this security policy applies to supported versions. Ensure you are using a supported version before reporting any vulnerabilities.
|
|
24
|
+
|
|
25
|
+
Thank you for helping us keep VirtualizorJS secure!
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const VirtualizorClient = require("virtualizorjs");
|
|
2
|
+
|
|
3
|
+
const { CreateVPS } = new VirtualizorClient({
|
|
4
|
+
host: "< IP or Hostname of Virtualizor Server >",
|
|
5
|
+
port: 4083, // Default port for Virtualizor API
|
|
6
|
+
key: "< Your API KEY >",
|
|
7
|
+
pass: "< Your API PASS >",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
async function exampleUsage() {
|
|
11
|
+
try {
|
|
12
|
+
const vps = await CreateVPS({
|
|
13
|
+
virtualizationType: "kvm",
|
|
14
|
+
nodeSelection: "node1",
|
|
15
|
+
userEmail: "user@example.com",
|
|
16
|
+
userPassword: "password",
|
|
17
|
+
serverHostname: "serverhostname",
|
|
18
|
+
rootPassword: "password",
|
|
19
|
+
osId: "222",
|
|
20
|
+
ipAddress: "188.0.0.0",
|
|
21
|
+
storageSpace: "10", // GB
|
|
22
|
+
serverRam: "1024", // MB
|
|
23
|
+
bandwidthLimit: "1000", // GB | 0 for unlimited
|
|
24
|
+
cpuCores: "1",
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log(vps); // Output: { time_taken: 0.022, ... }
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error("Error:", error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exampleUsage();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const VirtualizorClient = require('virtualizorjs');
|
|
2
|
+
|
|
3
|
+
const { on: eventOn } = new VirtualizorClient({
|
|
4
|
+
host: '< IP or Hostname of Virtualizor Server >',
|
|
5
|
+
port: 4083,
|
|
6
|
+
key: "< Your API KEY >",
|
|
7
|
+
pass: "< Your API PASS >",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// Event listener for when a virtual server is created
|
|
11
|
+
eventOn('vpsCreated', (response) => {
|
|
12
|
+
console.log(`Virtual Server Created! Details:`, response);
|
|
13
|
+
// Output: Virtual Server Created! Details: { ...virtualizorResponse }
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// Event listener for when a virtual server is started
|
|
17
|
+
eventOn('vpsStarted', (response) => {
|
|
18
|
+
console.log(`Virtual Server Started! Details:`, response);
|
|
19
|
+
// Output: Virtual Server Started! Details: { ...virtualizorResponse }
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Event listener for when a virtual server is stopped
|
|
23
|
+
eventOn('vpsStopped', (response) => {
|
|
24
|
+
console.log(`Virtual Server Stopped! Details:`, response);
|
|
25
|
+
// Output: Virtual Server Stopped! Details: { ...virtualizorResponse }
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Event listener for when a virtual server is restarted
|
|
29
|
+
eventOn('vpsRestarted', (response) => {
|
|
30
|
+
console.log(`Virtual Server Restarted! Details:`, response);
|
|
31
|
+
// Output: Virtual Server Restarted! Details: { ...virtualizorResponse }
|
|
32
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const VirtualizorClient = require("virtualizorjs");
|
|
2
|
+
|
|
3
|
+
const { ListVPS } = new VirtualizorClient({
|
|
4
|
+
host: "< IP or Hostname of Virtualizor Server >",
|
|
5
|
+
port: 4083, // Default port for Virtualizor API
|
|
6
|
+
key: "< Your API KEY >",
|
|
7
|
+
pass: "< Your API PASS >",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
async function exampleUsage() {
|
|
11
|
+
try {
|
|
12
|
+
const vpsList = await ListVPS();
|
|
13
|
+
console.log(vpsList);
|
|
14
|
+
//Output:
|
|
15
|
+
// {
|
|
16
|
+
// "37": {
|
|
17
|
+
// "vpsid": "37",
|
|
18
|
+
// "vps_name": "v1001",
|
|
19
|
+
// "uuid": "mark7ygoeqtfdf72",
|
|
20
|
+
// "serid": 0,
|
|
21
|
+
// "time": "1534260671",
|
|
22
|
+
// "edittime": "1534499180",
|
|
23
|
+
// "virt": "kvm",
|
|
24
|
+
// "uid": "55",
|
|
25
|
+
// "plid": "1",
|
|
26
|
+
// "hostname": "www.mydomainff.com",
|
|
27
|
+
// "osid": "270",
|
|
28
|
+
// "os_name": "centos-6.5-x86",
|
|
29
|
+
// "iso": "",
|
|
30
|
+
// "sec_iso": "",
|
|
31
|
+
// "boot": "cda",
|
|
32
|
+
// "space": "2",
|
|
33
|
+
// "inodes": "0",
|
|
34
|
+
// "ram": "128",
|
|
35
|
+
// "burst": "0",
|
|
36
|
+
// "swap": "128",
|
|
37
|
+
// "cpu": "1000",
|
|
38
|
+
// "cores": "1",
|
|
39
|
+
// "cpupin": "-1",
|
|
40
|
+
// "cpu_percent": "0.00",
|
|
41
|
+
// "bandwidth": "1",
|
|
42
|
+
// "network_speed": "0",
|
|
43
|
+
// "upload_speed": "-1",
|
|
44
|
+
// "io": "0",
|
|
45
|
+
// "ubc": "a:0:{}",
|
|
46
|
+
// "acpi": "1",
|
|
47
|
+
// "apic": "1",
|
|
48
|
+
// "pae": "1",
|
|
49
|
+
// "shadow": "0",
|
|
50
|
+
// "vnc": "1",
|
|
51
|
+
// "vncport": "5901",
|
|
52
|
+
// "vnc_passwd": "",
|
|
53
|
+
// "hvm": "0",
|
|
54
|
+
// "suspended": "0",
|
|
55
|
+
// "suspend_reason": null,
|
|
56
|
+
// "nw_suspended": null,
|
|
57
|
+
// "rescue": "0",
|
|
58
|
+
// "band_suspend": "0",
|
|
59
|
+
// "tuntap": "0",
|
|
60
|
+
// "ppp": "0",
|
|
61
|
+
// "ploop": "0",
|
|
62
|
+
// "dns_nameserver": "a:0:{}",
|
|
63
|
+
// "osreinstall_limit": "0",
|
|
64
|
+
// "preferences": null,
|
|
65
|
+
// "nic_type": "virtio",
|
|
66
|
+
// "vif_type": "",
|
|
67
|
+
// "virtio": "0",
|
|
68
|
+
// "pv_on_hvm": "0",
|
|
69
|
+
// "disks": null,
|
|
70
|
+
// "kvm_cache": "0",
|
|
71
|
+
// "io_mode": "0",
|
|
72
|
+
// "cpu_mode": "default",
|
|
73
|
+
// "total_iops_sec": "0",
|
|
74
|
+
// "read_bytes_sec": "0",
|
|
75
|
+
// "write_bytes_sec": "0",
|
|
76
|
+
// "kvm_vga": "0",
|
|
77
|
+
// "acceleration": "0",
|
|
78
|
+
// "vnc_keymap": "en-us",
|
|
79
|
+
// "routing": "0",
|
|
80
|
+
// "mg": "",
|
|
81
|
+
// "used_bandwidth": "0.01",
|
|
82
|
+
// "cached_disk": "a:2:{s:4:\"disk\";a:3:{s:4:\"Used\";i:776044;s:9:\"Available\";i:1190036;s:4:\"Use%\";d:39.469999999999998863131622783839702606201171875;}s:5:\"inode\";a:4:{s:6:\"Inodes\";i:122880;s:5:\"IUsed\";i:21323;s:5:\"IFree\";i:101557;s:4:\"Use%\";d:17.35000000000000142108547152020037174224853515625;}}",
|
|
83
|
+
// "webuzo": "0",
|
|
84
|
+
// "disable_ebtables": "0",
|
|
85
|
+
// "install_xentools": "0",
|
|
86
|
+
// "admin_managed": "0",
|
|
87
|
+
// "rdp": "0",
|
|
88
|
+
// "topology_sockets": "0",
|
|
89
|
+
// "topology_cores": "0",
|
|
90
|
+
// "topology_threads": "0",
|
|
91
|
+
// "mac": "00:16:3e:5f:cd:48",
|
|
92
|
+
// "notes": null,
|
|
93
|
+
// "disable_nw_config": "0",
|
|
94
|
+
// "locked": "",
|
|
95
|
+
// "openvz_features": "",
|
|
96
|
+
// "speed_cap": "",
|
|
97
|
+
// "numa": "0",
|
|
98
|
+
// "bpid": "0",
|
|
99
|
+
// "bserid": "0",
|
|
100
|
+
// "timezone": null,
|
|
101
|
+
// "usbdevice": "",
|
|
102
|
+
// "server_name": "localhost",
|
|
103
|
+
// "email": "tt@rrr.com",
|
|
104
|
+
// "pid": "0",
|
|
105
|
+
// "type": "0",
|
|
106
|
+
// "os_distro": "centos",
|
|
107
|
+
// "ips": {
|
|
108
|
+
// "2": "8.8.8.1"
|
|
109
|
+
// }
|
|
110
|
+
// }
|
|
111
|
+
// }
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error("Error:", error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
exampleUsage();
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "virtualizorjs",
|
|
3
|
+
"version": "1.0.0-beta",
|
|
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
|
+
"main": "/src/VirtualizorClient.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"virtualizor",
|
|
8
|
+
"api",
|
|
9
|
+
"nodejs",
|
|
10
|
+
"js",
|
|
11
|
+
"sdk",
|
|
12
|
+
"wrapper",
|
|
13
|
+
"virtualizorjs",
|
|
14
|
+
"virtualizor-js",
|
|
15
|
+
"virtualizorjs-api",
|
|
16
|
+
"virtualizorjs-wrapper",
|
|
17
|
+
"virtualizorjs-sdk",
|
|
18
|
+
"lightweight",
|
|
19
|
+
"easy",
|
|
20
|
+
"simple",
|
|
21
|
+
"powerful",
|
|
22
|
+
"fast"
|
|
23
|
+
],
|
|
24
|
+
"author": "kkMihai",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"github": "https://github.com/kkMihai/virtualizorjs",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/kkMihai/virtualizorjs.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/kkMihai/virtualizorjs/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/kkMihai/virtualizorjs#readme",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=12.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/Actions.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Actions that can be performed on the server. Made available as an enum incase the API changes.
|
|
3
|
+
* @enum {string}
|
|
4
|
+
* @readonly
|
|
5
|
+
*/
|
|
6
|
+
module.exports = {
|
|
7
|
+
/**
|
|
8
|
+
* Action to add a new virtual private server (VPS).
|
|
9
|
+
* @type {string}
|
|
10
|
+
*/
|
|
11
|
+
AddVPS: "addvs",
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Action to manage a VPS.
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
VPSManage: "vpsmanage",
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Action to list all VPS.
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
ListVPS: "vs",
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Action to start a VPS.
|
|
27
|
+
* @type {string}
|
|
28
|
+
*/
|
|
29
|
+
StartVPS: "start",
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Action to stop a VPS.
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
StopVPS: "stop",
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Action to restart a VPS.
|
|
39
|
+
* @type {string}
|
|
40
|
+
*/
|
|
41
|
+
RestartVPS: "restart",
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Action to get VPS RAM information.
|
|
45
|
+
* @type {string}
|
|
46
|
+
*/
|
|
47
|
+
GetVPSRam: "ram",
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Action to get VPS CPU information.
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
53
|
+
GetVPSCPU: "cpu",
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Action to get VPS disk information.
|
|
57
|
+
* @type {string}
|
|
58
|
+
*/
|
|
59
|
+
GetVPSDisk: "disk",
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Action to get Server Bandwidth information.
|
|
63
|
+
* @type {string}
|
|
64
|
+
*/
|
|
65
|
+
GetServerBandwidth: "bandwidth",
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Action to get VPS Bandwidth information.
|
|
69
|
+
* @type {string}
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
GetPlans: "plans",
|
|
73
|
+
};
|
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
const https = require("https");
|
|
2
|
+
const { URLSearchParams } = require("url");
|
|
3
|
+
const EventEmitter = require("events");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description - This class contains some the actions supported by Virtualizor API
|
|
7
|
+
* @class Actions
|
|
8
|
+
* @static
|
|
9
|
+
* @readonly
|
|
10
|
+
* @memberof VirtualizorClient
|
|
11
|
+
* @enum {string}
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const Actions = require("./actions");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @class VirtualizorClient
|
|
18
|
+
* @description - This class is used to make http requests to Virtualizor API
|
|
19
|
+
* @version 1.0.0
|
|
20
|
+
* @author kkMihai <kkmihai@duck.com>
|
|
21
|
+
* @param {Object} optionsv - Options for VirtualizorClient
|
|
22
|
+
* @param {String} options.host - Hostname of the Virtualizor server (IP or domain)
|
|
23
|
+
* @param {String} options.port - Port of the Virtualizor server (default: 4083)
|
|
24
|
+
* @param {String} options.key - API key
|
|
25
|
+
* @param {String} options.pass - API password
|
|
26
|
+
* @param {Boolean} options.isRawResponse - If true, the response will be the raw response from the API, Recommended to set this to false
|
|
27
|
+
* @returns {VirtualizorClient} VirtualizorClient
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
class VirtualizorClient extends EventEmitter {
|
|
31
|
+
constructor({ host, port, key, pass, isRawResponse = false }) {
|
|
32
|
+
super();
|
|
33
|
+
this.host = host;
|
|
34
|
+
this.port = port;
|
|
35
|
+
this.key = key;
|
|
36
|
+
this.pass = pass;
|
|
37
|
+
this.isRawResponse = isRawResponse
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @description - Bind Methods
|
|
41
|
+
* @memberof VirtualizorClient
|
|
42
|
+
*/
|
|
43
|
+
this.CreateVPS = this.CreateVPS.bind(this);
|
|
44
|
+
this.GetVPS = this.GetVPS.bind(this);
|
|
45
|
+
this.ListVPS = this.ListVPS.bind(this);
|
|
46
|
+
this.StartVPS = this.StartVPS.bind(this);
|
|
47
|
+
this.StopVPS = this.StopVPS.bind(this);
|
|
48
|
+
this.RestartVPS = this.RestartVPS.bind(this);
|
|
49
|
+
this.GetVPSRam = this.GetVPSRam.bind(this);
|
|
50
|
+
this.GetVPSCPU = this.GetVPSCPU.bind(this);
|
|
51
|
+
this.GetVPSDisk = this.GetVPSDisk.bind(this);
|
|
52
|
+
this.GetServerBandwidth = this.GetServerBandwidth.bind(this);
|
|
53
|
+
this.GetPlans = this.GetPlans.bind(this);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @description - This method is used to build query string and should not be used externally
|
|
58
|
+
* @param {Object} params
|
|
59
|
+
* @returns {String} query string
|
|
60
|
+
* @memberof VirtualizorClient
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
buildQueryString(params) {
|
|
64
|
+
params.api = "json";
|
|
65
|
+
const queryParams = new URLSearchParams(params);
|
|
66
|
+
return `?${queryParams.toString()}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @description - This method is used to make http/s request and should not be used externally
|
|
71
|
+
* @param {String} path
|
|
72
|
+
* @param {String} method
|
|
73
|
+
* @param {String} postData
|
|
74
|
+
* @returns {Promise} Promise
|
|
75
|
+
* @memberof VirtualizorClient
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
makeHttpRequest(path, method = "GET", postData) {
|
|
79
|
+
const options = {
|
|
80
|
+
host: this.host,
|
|
81
|
+
port: this.port,
|
|
82
|
+
path: path,
|
|
83
|
+
method: method,
|
|
84
|
+
headers: {
|
|
85
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
86
|
+
},
|
|
87
|
+
agent: new https.Agent({ rejectUnauthorized: false }),
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
const req = https.request(options, (res) => {
|
|
92
|
+
let data = "";
|
|
93
|
+
|
|
94
|
+
res.on("data", (chunk) => {
|
|
95
|
+
data += chunk;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
res.on("end", () => {
|
|
99
|
+
try {
|
|
100
|
+
const parsedData = JSON.parse(data);
|
|
101
|
+
resolve(parsedData);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
reject(error);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
req.on("error", (error) => {
|
|
109
|
+
reject(error);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (postData) {
|
|
113
|
+
req.write(postData);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
req.end();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @description - This method is used to create a new virtual server
|
|
122
|
+
* @param {Object} params - Parameters for creating a new virtual server
|
|
123
|
+
* @param {Object | String} params.storageSpace - Format { Size: Number, st_uuid: String }
|
|
124
|
+
* @returns {Promise} Promise
|
|
125
|
+
* @memberof VirtualizorClient
|
|
126
|
+
*/
|
|
127
|
+
async CreateVPS({
|
|
128
|
+
virtualizationType,
|
|
129
|
+
nodeSelection,
|
|
130
|
+
userEmail,
|
|
131
|
+
userPassword,
|
|
132
|
+
serverHostname,
|
|
133
|
+
rootPassword,
|
|
134
|
+
osId,
|
|
135
|
+
ipAddress,
|
|
136
|
+
storageSpace,
|
|
137
|
+
serverRam,
|
|
138
|
+
bandwidthLimit,
|
|
139
|
+
cpuCores,
|
|
140
|
+
}) {
|
|
141
|
+
/**
|
|
142
|
+
* @description - This method is used to handle storage space parameter, This in GB
|
|
143
|
+
* @param {Array|Number} space
|
|
144
|
+
* @returns {Number | Promise} Promise
|
|
145
|
+
* @memberof VirtualizorClient
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
function handleDiskSpace(space) {
|
|
150
|
+
if (Array.isArray(space)) {
|
|
151
|
+
return space.reduce((acc, curr) => acc + curr, 0);
|
|
152
|
+
}
|
|
153
|
+
return space;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const queryParams = {
|
|
157
|
+
action: Actions.AddVPS,
|
|
158
|
+
virt: virtualizationType,
|
|
159
|
+
node_select: nodeSelection,
|
|
160
|
+
user_email: userEmail,
|
|
161
|
+
user_pass: userPassword,
|
|
162
|
+
hostname: serverHostname,
|
|
163
|
+
root_pass: rootPassword,
|
|
164
|
+
os_id: osId,
|
|
165
|
+
ips: ipAddress,
|
|
166
|
+
space: handleDiskSpace(storageSpace),
|
|
167
|
+
ram: serverRam,
|
|
168
|
+
bandwidth: bandwidthLimit,
|
|
169
|
+
cores: cpuCores,
|
|
170
|
+
key: this.key,
|
|
171
|
+
pass: this.pass,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const path = `/index.php${this.buildQueryString(queryParams)}`;
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
const response = await this.makeHttpRequest(path, "POST");
|
|
178
|
+
this.emit("vpsCreated", response);
|
|
179
|
+
return Promise.resolve({
|
|
180
|
+
message: response.done && response.done.msg,
|
|
181
|
+
data: response,
|
|
182
|
+
});
|
|
183
|
+
} catch (error) {
|
|
184
|
+
return Promise.reject(error);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @description - This method is used to get information about a virtual server
|
|
190
|
+
* @param {String} id - ID of the virtual server
|
|
191
|
+
* @returns {Promise} Promise
|
|
192
|
+
* @memberof VirtualizorClient
|
|
193
|
+
*/
|
|
194
|
+
async GetVPS(id) {
|
|
195
|
+
const queryParams = {
|
|
196
|
+
act: Actions.VPSManage,
|
|
197
|
+
changeserid: id,
|
|
198
|
+
key: this.key,
|
|
199
|
+
pass: this.pass,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const path = `/index.php${this.buildQueryString(queryParams)}`;
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
const res = await this.makeHttpRequest(path);
|
|
206
|
+
let resData = res;
|
|
207
|
+
|
|
208
|
+
if (!this.isRawResponse) {
|
|
209
|
+
resData = {
|
|
210
|
+
ip: res.info.ip,
|
|
211
|
+
hostname: res.info.hostname,
|
|
212
|
+
status: res.info.status,
|
|
213
|
+
os: res.info.vps.os_name,
|
|
214
|
+
cores: res.info.vps.cores,
|
|
215
|
+
ram: res.info.vps.ram,
|
|
216
|
+
space: res.info.vps.space,
|
|
217
|
+
bandwidth: {
|
|
218
|
+
limit: res.info.bandwidth.limit,
|
|
219
|
+
used: res.info.bandwidth.used,
|
|
220
|
+
free: res.info.bandwidth.free,
|
|
221
|
+
},
|
|
222
|
+
datacenter: res.info.server_name,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return Promise.resolve(resData);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
return Promise.reject(err);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @description - This method is used to list all virtual servers
|
|
234
|
+
* @returns {Promise} Promise
|
|
235
|
+
* @param {Number} [vpsid] - Search using id
|
|
236
|
+
* @param {String} [vpsname] - Search using vid
|
|
237
|
+
* @param {String} [vpsip] - Results will be returned on the basis of the ip
|
|
238
|
+
* @param {String} [vpshostname] - VPS is searched on the basis of the hostname passed
|
|
239
|
+
* @param {String} [vpsstatus] - VPS is searched on the basis of the status of the vps
|
|
240
|
+
* (type 's' for suspended, type 'u' for unsuspended)
|
|
241
|
+
* @param {String} [vstype] - VPS is searched on the basis of the type of virtualization,
|
|
242
|
+
* refer below table for valid values
|
|
243
|
+
* @param {String} [speedcap] - VPS is searched on the basis of the type of speed cap
|
|
244
|
+
* (type 1 for enabled, 2 for disabled)
|
|
245
|
+
* @param {String} [user] - Search for the vps according to the user
|
|
246
|
+
* @param {String} [vsgid] - Search for the vps according to the server group
|
|
247
|
+
* @param {String} [vserid] - VPS is searched on the basis of the server
|
|
248
|
+
* @param {String} [plid] - VPS is searched on the basis of plan that it has been assigned
|
|
249
|
+
* @param {String} [bpid] - VPS is searched on the basis of backup plan that it has been assigned
|
|
250
|
+
* @param {Number} [reslen] - Number of records to be returned, default is 50
|
|
251
|
+
* @param {Number} [page] - Page number, each page show 50 records
|
|
252
|
+
* @memberof VirtualizorClient
|
|
253
|
+
*/
|
|
254
|
+
async ListVPS(
|
|
255
|
+
vpsid,
|
|
256
|
+
vpsname,
|
|
257
|
+
vpsip,
|
|
258
|
+
vpshostname,
|
|
259
|
+
vpsstatus,
|
|
260
|
+
vstype,
|
|
261
|
+
speedcap,
|
|
262
|
+
user,
|
|
263
|
+
vsgid,
|
|
264
|
+
vserid,
|
|
265
|
+
plid,
|
|
266
|
+
bpid,
|
|
267
|
+
reslen,
|
|
268
|
+
page
|
|
269
|
+
) {
|
|
270
|
+
const queryParams = {
|
|
271
|
+
act: Actions.ListVPS,
|
|
272
|
+
key: this.key,
|
|
273
|
+
pass: this.pass,
|
|
274
|
+
vpsid,
|
|
275
|
+
vpsname,
|
|
276
|
+
vpsip,
|
|
277
|
+
vpshostname,
|
|
278
|
+
vpsstatus,
|
|
279
|
+
vstype,
|
|
280
|
+
speedcap,
|
|
281
|
+
user,
|
|
282
|
+
vsgid,
|
|
283
|
+
vserid,
|
|
284
|
+
plid,
|
|
285
|
+
bpid,
|
|
286
|
+
reslen,
|
|
287
|
+
page,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const path = `/index.php${this.buildQueryString(queryParams)}`;
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
const res = await this.makeHttpRequest(path, "POST");
|
|
294
|
+
let resData = res;
|
|
295
|
+
|
|
296
|
+
if (!this.isRawResponse && res.data.vs) {
|
|
297
|
+
resData = Object.keys(res.data.vs).reduce((acc, key) => {
|
|
298
|
+
const vps = res.data.vs[key];
|
|
299
|
+
|
|
300
|
+
if (vps && vps.vpsid && vps.hostname && vps.os_name) {
|
|
301
|
+
acc.push({
|
|
302
|
+
id: vps.vpsid,
|
|
303
|
+
name: vps.vps_name,
|
|
304
|
+
hostname: vps.hostname,
|
|
305
|
+
os: vps.os_name,
|
|
306
|
+
cores: vps.cores,
|
|
307
|
+
ram: vps.ram,
|
|
308
|
+
space: vps.space,
|
|
309
|
+
bandwidth: vps.bandwidth,
|
|
310
|
+
serverName: vps.server_name,
|
|
311
|
+
status: vps.status,
|
|
312
|
+
ip: vps.ips,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return acc;
|
|
317
|
+
}, []);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return Promise.resolve(resData);
|
|
321
|
+
} catch (err) {
|
|
322
|
+
return Promise.reject(err);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @description - This method is used to start a virtual server
|
|
329
|
+
* @param {String} vpsId - ID of the virtual server
|
|
330
|
+
* @returns {Promise} Promise
|
|
331
|
+
* @memberof VirtualizorClient
|
|
332
|
+
*/
|
|
333
|
+
async StartVPS(vpsId) {
|
|
334
|
+
const queryParams = {
|
|
335
|
+
act: Actions.StartVPS,
|
|
336
|
+
vpsid: vpsId,
|
|
337
|
+
key: this.key,
|
|
338
|
+
pass: this.pass,
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const path = `/index.php${this.buildQueryString(queryParams)}&action=vs`;
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
const res = await this.makeHttpRequest(path);
|
|
345
|
+
this.emit("vpsStarted", res);
|
|
346
|
+
return Promise.resolve({
|
|
347
|
+
message: res.done && res.done.msg,
|
|
348
|
+
time_taken: res.time_taken,
|
|
349
|
+
});
|
|
350
|
+
} catch (err) {
|
|
351
|
+
return Promise.reject(err);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @description - This method is used to stop a virtual server
|
|
357
|
+
* @param {String} vpsId - ID of the virtual server
|
|
358
|
+
* @returns {Promise} Promise
|
|
359
|
+
* @memberof VirtualizorClient
|
|
360
|
+
*/
|
|
361
|
+
async StopVPS(vpsId) {
|
|
362
|
+
const queryParams = {
|
|
363
|
+
act: Actions.StopVPS,
|
|
364
|
+
vpsid: vpsId,
|
|
365
|
+
key: this.key,
|
|
366
|
+
pass: this.pass,
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const path = `/index.php${this.buildQueryString(queryParams)}&action=vs`;
|
|
370
|
+
|
|
371
|
+
try {
|
|
372
|
+
const res = await this.makeHttpRequest(path);
|
|
373
|
+
this.emit("vpsStopped", res);
|
|
374
|
+
return Promise.resolve({
|
|
375
|
+
message: res.done && res.done.msg,
|
|
376
|
+
time_taken: res.time_taken,
|
|
377
|
+
});
|
|
378
|
+
} catch (err) {
|
|
379
|
+
return Promise.reject(err);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* @description - This method is used to restart a virtual server
|
|
385
|
+
* @param {String} vpsId - ID of the virtual server
|
|
386
|
+
* @returns {Promise} Promise
|
|
387
|
+
* @memberof VirtualizorClient
|
|
388
|
+
*/
|
|
389
|
+
async RestartVPS(vpsId) {
|
|
390
|
+
const queryParams = {
|
|
391
|
+
act: Actions.RestartVPS,
|
|
392
|
+
vpsid: vpsId,
|
|
393
|
+
key: this.key,
|
|
394
|
+
pass: this.pass,
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const path = `/index.php${this.buildQueryString(queryParams)}&action=vs`;
|
|
398
|
+
|
|
399
|
+
try {
|
|
400
|
+
const res = await this.makeHttpRequest(path);
|
|
401
|
+
this.emit("vpsRestarted", res);
|
|
402
|
+
return Promise.resolve({
|
|
403
|
+
message: res.done && res.done.msg,
|
|
404
|
+
time_taken: res.time_taken,
|
|
405
|
+
});
|
|
406
|
+
} catch (err) {
|
|
407
|
+
return Promise.reject(err);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* @description - This method is used to get RAM information of a virtual server
|
|
413
|
+
* @param {String} vpsId - ID of the virtual server
|
|
414
|
+
* @returns {Promise} Promise
|
|
415
|
+
* @memberof VirtualizorClient
|
|
416
|
+
*/
|
|
417
|
+
async GetVPSRam(vpsId) {
|
|
418
|
+
const queryParams = {
|
|
419
|
+
act: Actions.GetVPSRam,
|
|
420
|
+
changeserid: vpsId,
|
|
421
|
+
key: this.key,
|
|
422
|
+
pass: this.pass,
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const path = `/index.php${this.buildQueryString(queryParams)}`;
|
|
426
|
+
|
|
427
|
+
try {
|
|
428
|
+
const res = await this.makeHttpRequest(path);
|
|
429
|
+
return Promise.resolve({
|
|
430
|
+
ram: res.ram,
|
|
431
|
+
time_taken: res.time_taken,
|
|
432
|
+
});
|
|
433
|
+
} catch (err) {
|
|
434
|
+
return Promise.reject(err);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* @description - This method is used to get CPU information of a virtual server
|
|
440
|
+
* @param {String} vpsId - ID of the virtual server
|
|
441
|
+
* @returns {Promise} Promise
|
|
442
|
+
* @memberof VirtualizorClient
|
|
443
|
+
*/
|
|
444
|
+
async GetVPSCPU(vpsId) {
|
|
445
|
+
const queryParams = {
|
|
446
|
+
act: Actions.GetVPSCPU,
|
|
447
|
+
changeserid: vpsId,
|
|
448
|
+
key: this.key,
|
|
449
|
+
pass: this.pass,
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const path = `/index.php${this.buildQueryString(queryParams)}`;
|
|
453
|
+
|
|
454
|
+
try {
|
|
455
|
+
const res = await this.makeHttpRequest(path);
|
|
456
|
+
return Promise.resolve({
|
|
457
|
+
cpu: res.cpu,
|
|
458
|
+
time_taken: res.time_taken,
|
|
459
|
+
});
|
|
460
|
+
} catch (err) {
|
|
461
|
+
return Promise.reject(err);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* @description - This method is used to get disk information of a virtual server
|
|
467
|
+
* @param {String} vpsId - ID of the virtual server
|
|
468
|
+
* @returns {Promise} Promise
|
|
469
|
+
* @memberof VirtualizorClient
|
|
470
|
+
*/
|
|
471
|
+
async GetVPSDisk(vpsId) {
|
|
472
|
+
const queryParams = {
|
|
473
|
+
act: Actions.GetVPSDisk,
|
|
474
|
+
changeserid: vpsId,
|
|
475
|
+
key: this.key,
|
|
476
|
+
pass: this.pass,
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const path = `/index.php${this.buildQueryString(queryParams)}`;
|
|
480
|
+
|
|
481
|
+
try {
|
|
482
|
+
const res = await this.makeHttpRequest(path);
|
|
483
|
+
return Promise.resolve({
|
|
484
|
+
disk: res.disk,
|
|
485
|
+
time_taken: res.time_taken,
|
|
486
|
+
});
|
|
487
|
+
} catch (err) {
|
|
488
|
+
return Promise.reject(err);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* @description - This method is used to get bandwidth information of a virtual server
|
|
494
|
+
* @param {String} month - Month for which bandwidth information is required (YYYY-MM)
|
|
495
|
+
* @returns {Promise} Promise
|
|
496
|
+
* @memberof VirtualizorClient
|
|
497
|
+
*/
|
|
498
|
+
async GetServerBandwidth(month) {
|
|
499
|
+
const queryParams = {
|
|
500
|
+
act: Actions.GetServerBandwidth,
|
|
501
|
+
key: this.key,
|
|
502
|
+
pass: this.pass,
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
const path = `/index.php${this.buildQueryString(queryParams)}`;
|
|
506
|
+
|
|
507
|
+
try {
|
|
508
|
+
const res = await this.makeHttpRequest(path, "GET", `show=${month}`);
|
|
509
|
+
return Promise.resolve({
|
|
510
|
+
bandwidth: res.bandwidth,
|
|
511
|
+
time_taken: res.time_taken,
|
|
512
|
+
});
|
|
513
|
+
} catch (err) {
|
|
514
|
+
return Promise.reject(err);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
async GetPlans() {
|
|
519
|
+
const queryParams = {
|
|
520
|
+
act: Actions.GetPlans,
|
|
521
|
+
key: this.key,
|
|
522
|
+
pass: this.pass,
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
const path = `/index.php${this.buildQueryString(queryParams)}`;
|
|
526
|
+
|
|
527
|
+
try {
|
|
528
|
+
const res = await this.makeHttpRequest(path);
|
|
529
|
+
return Promise.resolve(res);
|
|
530
|
+
} catch (err) {
|
|
531
|
+
return Promise.reject(err);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
module.exports = VirtualizorClient;
|