https://github.com/alandoherty/node-lxd
A client for linux containers (lxd)
https://github.com/alandoherty/node-lxd
api linux-containers lxd nodejs
Last synced: about 2 months ago
JSON representation
A client for linux containers (lxd)
- Host: GitHub
- URL: https://github.com/alandoherty/node-lxd
- Owner: alandoherty
- License: mit
- Created: 2016-02-09T11:28:53.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-01T11:53:16.000Z (about 6 years ago)
- Last Synced: 2025-02-19T19:39:48.262Z (2 months ago)
- Topics: api, linux-containers, lxd, nodejs
- Language: JavaScript
- Size: 79.1 KB
- Stars: 43
- Watchers: 5
- Forks: 20
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://badge.fury.io/js/node-lxd)
A client for communicating with a local or remote instance of linux containers. The interface is object-oriented, simple and uniform. Unrestrictive with an open MIT license.
# Installing
```bash
$ npm install --save node-lxd
```## Getting Started ##
The following example connects to the local LXC instance and launches a new container.
```js
var lxd = require("node-lxd");var client = lxd();
client.create("myContainer", "ubuntu", function(err, container) {
container.start(function(err) {
if (!err)
console.log("Started " + container.name());
});
});
```## Example ##
The following example uses an express application to allow users to create containers and execute commands.
```js
// requires
var express = require("express");
var lxd = require("node-lxd");
var client = lxd();
var app = express();var containers = {};
app.post("/create", function(req, res) {
client.launch(req.query.name, function(err, container) {
if (err) res.json({success: false, message: err.getMessage()});
else {
containers[req.query.name] = container;
res.json({success: true, message: "Container launched"});
}
});
});app.post("/run", function(req, res) {
if (!containers.hasOwnProperty(req.query.name)) {
res.json({success: false, message: "Container does not exist"});
return;
}containers[req.query.name].run(req.query.cmd.split(" "), function(err, stdOut, stdErr) {
if (err) res.json({success: false, message: err.getMessage()});
else if (stdErr.length > 0) res.json({success: false, message: stdErr});
else {
res.json({success: true, message: stdOut});
}
});
});app.listen(3000, function(err) {
if (!err)
console.log("listening on port 3000");
});
```## Documentation ##
The client class is documented [here](https://github.com/alandoherty/node-lxd/blob/master/docs/client.md).
The container class is documented [here](https://github.com/alandoherty/node-lxd/blob/master/docs/container.md).
The process class is documented [here](https://github.com/alandoherty/node-lxd/blob/master/docs/process.md).