0.2.9 • Published 7 years ago

node-lxd v0.2.9

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

npm version

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

$ npm install --save node-lxd

Getting Started

The following example connects to the local LXC instance and launches a new container.

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.

// 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.

The container class is documented here.

The process class is documented here.

0.2.9

7 years ago

0.2.8

9 years ago

0.2.7

9 years ago

0.2.6

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago